Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
60fdf4d
feat(models): OMN-1050 - Create typed payload models for core models
jonahgabriel Dec 27, 2025
ba9fe45
fix(models): OMN-1050 - Fix mypy errors and docstring inconsistencies
jonahgabriel Dec 27, 2025
25aedd2
Merge branch 'main' into jonah/omn-1050-migrate-payloads-to-tcontext
jonahgabriel Dec 27, 2025
cfd10f2
fix(models): OMN-1050 - Fix PR review issues and CI lint error
jonahgabriel Dec 27, 2025
f8fafc8
refactor(models): OMN-1050 - Address PR review nitpicks
jonahgabriel Dec 27, 2025
d01a0b9
test(models): OMN-1050 - Add comprehensive tests and PR review fixes
jonahgabriel Dec 27, 2025
b94fdd4
fix(models): OMN-1050 - Address final PR review issues
jonahgabriel Dec 27, 2025
8fb430e
Merge remote-tracking branch 'origin/main' into jonah/omn-1050-migrat…
jonahgabriel Dec 27, 2025
f4aebd7
fix(models): OMN-1050 - Address PR #251 release-ready review feedback
Dec 27, 2025
dfd308f
fix(models): OMN-1050 - Fix all pre-commit hook violations from merge
jonahgabriel Dec 27, 2025
8672400
Merge branch 'jonah/omn-1050-migrate-payloads-to-tcontext' of https:/…
jonahgabriel Dec 27, 2025
73b606a
fix(models): OMN-1050 - Fix CI failure and address remaining PR #251 …
jonahgabriel Dec 27, 2025
4b582b7
fix(models): OMN-1050 - Address all PR #251 release-ready review issues
jonahgabriel Dec 27, 2025
9169709
fix(models): OMN-1050 - Add UUID validators and integration tests for…
jonahgabriel Dec 28, 2025
dd58df4
fix(models): OMN-1050 - Address final PR #251 review feedback
jonahgabriel Dec 28, 2025
dc04bf9
Merge branch 'main' into jonah/omn-1050-migrate-payloads-to-tcontext
jonahgabriel Dec 28, 2025
0b1a9c4
Merge branch 'main' into jonah/omn-1050-migrate-payloads-to-tcontext
jonahgabriel Dec 28, 2025
8937332
fix(models): centralize ERROR_CODE_PATTERN and apply stashed fixes
jonahgabriel Dec 28, 2025
160532f
fix(tests): use canonical import path for EnumEffectType
jonahgabriel Dec 28, 2025
0f62dc4
fix(ci): address PR #251 review feedback and fix CI failures
jonahgabriel Dec 28, 2025
f99f198
Merge branch 'main' into jonah/omn-1050-migrate-payloads-to-tcontext
jonahgabriel Dec 28, 2025
168cfa2
fix(models): address PR #251 review feedback and fix CI failures
jonahgabriel Dec 28, 2025
4a00aaf
Merge branch 'main' into jonah/omn-1050-migrate-payloads-to-tcontext
jonahgabriel Dec 28, 2025
a112ad9
fix(models): address remaining PR #251 review feedback
jonahgabriel Dec 28, 2025
6a6a7be
Merge branch 'main' into jonah/omn-1050-migrate-payloads-to-tcontext
jonahgabriel Dec 28, 2025
d6dad79
refactor(models): separate contract vs template context for payload t…
jonahgabriel Dec 28, 2025
83f209a
fix(models): address PR #251 code style and test improvements
jonahgabriel Dec 28, 2025
13bdfe2
fix(models): address PR #251 review feedback and CI failure
jonahgabriel Dec 29, 2025
b376f4f
feat(models): add security validation, caching, and docs improvements
jonahgabriel Dec 29, 2025
af9c14b
merge: resolve conflicts with main branch
jonahgabriel Dec 29, 2025
11e19be
fix(models): address PR #251 review feedback - thread safety and Pyda…
jonahgabriel Dec 29, 2025
08c79cc
fix(models): address remaining PR #251 feedback - thread safety and i…
jonahgabriel Dec 29, 2025
e8f3a24
Merge remote-tracking branch 'origin/main' into jonah/omn-1050-migrat…
jonahgabriel Dec 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions docs/conventions/ERROR_CODE_STANDARDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,39 @@ NODE_COMPUTE_001 # Node compute subcategory

## Implementation Reference

### Centralized Error Code Pattern

The `CATEGORY_NNN` pattern is defined in a centralized location and imported by all modules that need error code validation.

**Centralized Pattern Location**: `src/omnibase_core/constants/constants_error.py`

This module provides the **single source of truth** for error code validation patterns:

```python
from omnibase_core.constants import ERROR_CODE_PATTERN, ERROR_CODE_PATTERN_STRING

# Compiled pattern for validation
ERROR_CODE_PATTERN.match("AUTH_001") # Returns Match object

# Raw string for JSON schema or documentation
ERROR_CODE_PATTERN_STRING # "^[A-Z][A-Z0-9_]*_\\d{1,4}$"
```

**Why Centralized?**
- Avoids pattern drift across multiple modules
- Ensures consistent validation behavior
- Single point of maintenance for pattern updates
- Thread-safe (compiled regex patterns are immutable)

### ModelErrorMetadata Validation

The `CATEGORY_NNN` pattern is enforced by `ModelErrorMetadata` in the ONEX framework.
The `ModelErrorMetadata` class imports the pattern from the centralized location.

**Location**: `src/omnibase_core/models/context/model_error_metadata.py`

**Pattern Definition**:
**Pattern Import**:
```python
# Pattern for error codes: CATEGORY_NNN (e.g., AUTH_001, VALIDATION_123)
ERROR_CODE_PATTERN = re.compile(r"^[A-Z][A-Z0-9_]*_\d{1,4}$")
from omnibase_core.constants.constants_error import ERROR_CODE_PATTERN
```

**Validation**:
Expand Down Expand Up @@ -267,7 +290,9 @@ Reserve specific numbers for standard error types:

## Related Documentation

- **Error Handling Best Practices**: `docs/conventions/ERROR_HANDLING_BEST_PRACTICES.md`
- **Centralized Error Pattern**: `src/omnibase_core/constants/constants_error.py` - Single source of truth for error code validation
- **Error Handling Best Practices**: `docs/conventions/ERROR_HANDLING_BEST_PRACTICES.md` - Comprehensive error handling patterns
- **ModelErrorMetadata**: `src/omnibase_core/models/context/model_error_metadata.py` - Error metadata model with validation
- **ModelOnexError**: Error base class and structured error context
- **Naming Conventions**: `docs/conventions/NAMING_CONVENTIONS.md`
- **Pydantic Best Practices**: `docs/conventions/PYDANTIC_BEST_PRACTICES.md`
Expand Down
34 changes: 34 additions & 0 deletions docs/conventions/ERROR_HANDLING_BEST_PRACTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,38 @@ This document establishes comprehensive error handling standards for the ONEX Fo

## ONEX Error Framework

### Centralized Error Code Pattern

ONEX uses a centralized error code pattern to ensure consistency across all error handling code. The pattern is defined once and imported wherever validation is needed.

**Single Source of Truth**: `src/omnibase_core/constants/constants_error.py`

```python
from omnibase_core.constants import ERROR_CODE_PATTERN, ERROR_CODE_PATTERN_STRING

# Validate error codes
if ERROR_CODE_PATTERN.match("AUTH_001"):
print("Valid error code")

# Use raw pattern string for JSON schemas
schema = {"pattern": ERROR_CODE_PATTERN_STRING}
```

**Pattern Format**: `CATEGORY_NNN` (e.g., `AUTH_001`, `VALIDATION_123`, `SYSTEM_01`)

**Benefits of Centralization**:
- **No Pattern Drift**: All modules use the same pattern definition
- **Single Maintenance Point**: Pattern changes propagate automatically
- **Thread-Safe**: Compiled regex patterns are immutable
- **Consistent Validation**: Same behavior across Pydantic models, validators, and utilities

**Modules Using This Pattern**:
- `omnibase_core.models.context.model_error_metadata` - Error metadata model
- `omnibase_core.models.context.model_retry_error_context` - Retry context model
- `omnibase_core.validation.validators.common_validators` - Standalone validators

For complete error code standards including valid/invalid examples and best practices, see [Error Code Standards](ERROR_CODE_STANDARDS.md).

### ModelOnexError Base Class

All ONEX errors inherit from the `ModelOnexError` base class which provides structured error context and correlation tracking:
Expand Down Expand Up @@ -1670,6 +1702,8 @@ All error handling follows ONEX principles with:

### Related Documentation

- [Error Code Standards](ERROR_CODE_STANDARDS.md) - Complete error code format specification
- [Centralized Error Pattern](../../src/omnibase_core/constants/constants_error.py) - Single source of truth for error code validation
- [ADR-012: Validator Error Handling](../architecture/adr/ADR-012-VALIDATOR-ERROR-HANDLING.md) - Decision rationale and Pydantic compatibility
- [Node Building Guide](../guides/node-building/README.md) - Node validation patterns
- [Reducer Output Model](../../src/omnibase_core/models/reducer/model_reducer_output.py) - Reference implementation
Expand Down
9 changes: 9 additions & 0 deletions src/omnibase_core/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from omnibase_core.constants import (
constants_contract_fields,
constants_effect,
constants_error,
constants_field_limits,
constants_topic_taxonomy,
handler_capabilities,
Expand Down Expand Up @@ -45,6 +46,10 @@
EFFECT_TIMEOUT_MAX_MS,
EFFECT_TIMEOUT_MIN_MS,
)
from omnibase_core.constants.constants_error import (
ERROR_CODE_PATTERN,
ERROR_CODE_PATTERN_STRING,
)
from omnibase_core.constants.constants_field_limits import (
MAX_BFS_ITERATIONS,
MAX_DESCRIPTION_LENGTH,
Expand Down Expand Up @@ -141,10 +146,14 @@
__all__ = [
"constants_contract_fields",
"constants_effect",
"constants_error",
"constants_field_limits",
"constants_topic_taxonomy",
"handler_capabilities",
"normalize_legacy_event_type",
# Error code pattern (centralized)
"ERROR_CODE_PATTERN",
"ERROR_CODE_PATTERN_STRING",
# Event type constants
"NODE_FAILURE",
"NODE_HEALTH_CHECK",
Expand Down
74 changes: 74 additions & 0 deletions src/omnibase_core/constants/constants_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# SPDX-FileCopyrightText: 2025 OmniNode Team <info@omninode.ai>
#
# SPDX-License-Identifier: Apache-2.0
"""Centralized error code constants and patterns.

This module provides the single source of truth for error code patterns
used throughout the ONEX system.

Error Code Format:
Error codes must follow the CATEGORY_NNN pattern (e.g., AUTH_001,
VALIDATION_123, SYSTEM_01). The format is validated using the regex
pattern: ^[A-Z][A-Z0-9_]*_\\d{1,4}$

For complete error code standards including valid/invalid examples,
standard categories, and best practices, see:
docs/conventions/ERROR_CODE_STANDARDS.md

Pattern Usage:
This pattern is imported by:
- omnibase_core.models.context.model_error_metadata
- omnibase_core.models.context.model_retry_error_context
- omnibase_core.validation.validators.common_validators

The centralization avoids pattern drift and ensures consistent validation
across all error handling code.

Thread Safety:
Compiled regex patterns are immutable and thread-safe.

Example:
>>> from omnibase_core.constants import ERROR_CODE_PATTERN
>>> ERROR_CODE_PATTERN.match("AUTH_001")
<re.Match object; span=(0, 8), match='AUTH_001'>
>>> ERROR_CODE_PATTERN.match("auth_001") # Invalid: lowercase
None
"""

import re

__all__ = [
"ERROR_CODE_PATTERN",
"ERROR_CODE_PATTERN_STRING",
]

# Pattern string for documentation and external use
ERROR_CODE_PATTERN_STRING: str = r"^[A-Z][A-Z0-9_]*_\d{1,4}$"
"""Raw regex pattern string for error codes.

Use ERROR_CODE_PATTERN for matching; this string is for documentation
or when a string pattern is needed (e.g., JSON schema validation).
"""

# Compiled pattern for error codes: CATEGORY_NNN format
# - Valid: AUTH_001, VALIDATION_123, NETWORK_TIMEOUT_001, SYSTEM_01
# - Invalid: E001 (lint-style, no underscore), auth_001 (lowercase)
ERROR_CODE_PATTERN: re.Pattern[str] = re.compile(ERROR_CODE_PATTERN_STRING)
"""Compiled regex pattern for validating ONEX structured error codes.

Pattern: ^[A-Z][A-Z0-9_]*_\\d{1,4}$

This pattern enforces:
- Starts with uppercase letter [A-Z]
- Followed by uppercase letters, digits, or underscores [A-Z0-9_]*
- Underscore separator before numeric suffix _
- 1-4 digit numeric suffix \\d{1,4}

Examples:
Valid: AUTH_001, VALIDATION_123, NETWORK_TIMEOUT_001, V2_AUTH_99
Invalid: E001 (lint-style), auth_001 (lowercase), AUTH (no suffix)

Note:
For lint-style short codes (W001, E001), use workflow_linter module.
Those follow a different pattern for workflow linting purposes.
"""
8 changes: 4 additions & 4 deletions src/omnibase_core/infrastructure/node_core_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,9 @@ async def _load_contract(self) -> None:
contract_service: Any = None
try:
contract_service = self.container.get_service("contract_service") # type: ignore[arg-type]
except Exception:
# Contract service not available - that's OK
except (
Exception
): # fallback-ok: contract service is optional for node operation
contract_service = None

# Check contract service - use try/except to avoid hasattr() deadlock with Mock
Expand Down Expand Up @@ -497,8 +498,7 @@ async def _emit_lifecycle_event(
event_bus: Any = None
try:
event_bus = self.container.get_service("event_bus") # type: ignore[arg-type]
except Exception:
# Event bus not available - that's OK
except Exception: # fallback-ok: event bus is optional for node operation
event_bus = None

# Check event bus - use try/except to avoid hasattr() deadlock with Mock
Expand Down
5 changes: 3 additions & 2 deletions src/omnibase_core/logging/core_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ async def _async_emit_via_logger(
try:
# Use the registry-resolved logger
logger.emit(level, message, correlation_id)
except Exception:
# Fallback to simple print if logger fails
except (
Exception
): # fallback-ok: logger failure is non-fatal in fire-and-forget logging
pass
3 changes: 1 addition & 2 deletions src/omnibase_core/logging/emit.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,5 @@ def _route_to_logger_node(
# Fallback to simple output if protocol services unavailable
pass

except Exception:
# Fallback to simple output if logger node routing fails
except Exception: # fallback-ok: logger node routing failure is non-fatal
pass
6 changes: 4 additions & 2 deletions src/omnibase_core/mixins/mixin_discovery_responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ async def stop_discovery_responder(self) -> None:
if self._discovery_unsubscribe:
try:
await self._discovery_unsubscribe()
except Exception:
pass # Ignore errors during cleanup
except (
Exception
): # fallback-ok: cleanup errors during shutdown are non-critical
pass

emit_log_event(
LogLevel.INFO,
Expand Down
Loading