Repository navigation
feat(models): add registration event models for 2-way registration pattern #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jonahgabriel
merged 13 commits into
main
from
jonah/omn-891-infra-mvp-modelnodeintrospectionevent-and
Dec 17, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f977b30
feat(models): add registration event models for 2-way registration pa…
jonahgabriel 4c59d72
Merge main into feature branch, bump INFRA_MAX_UNIONS to 185
jonahgabriel fc87fe6
docs(validation): fix INFRA_MAX_UNIONS docstring to reflect current v…
jonahgabriel 428405b
docs(validation): fix INFRA_MAX_UNIONS docstring to reflect current v…
jonahgabriel 08ee269
docs(validation): fix INFRA_PATTERNS_STRICT documentation to match so…
jonahgabriel 03ecd9d
feat(models): add validation enhancements for registration models
jonahgabriel b5fccc2
feat(models): add validation enhancements per PR review feedback
jonahgabriel 8984f1e
fix(validation): address PR review - restore strict patterns, add val…
jonahgabriel dd2bc87
fix(models): address PR #50 review - node_type validation, test cover…
jonahgabriel 9ba08ec
feat(models): replace dict[str, Any] with strongly-typed Pydantic models
jonahgabriel 3a0acdd
refactor(models): remove backwards compat cruft, reduce unions 210→200
jonahgabriel 56f67ff
fix(models): address PR #50 review - dict access, docs, test coverage
jonahgabriel 1b3b7e6
fix(models): address PR #50 review - semver utility, docs, test coverage
jonahgabriel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| # Copyright (c) 2025 OmniNode Team | ||
| """ONEX Infrastructure Models. | ||
|
|
||
| This module provides shared models for the omnibase_infra package. | ||
| """ | ||
|
|
||
| from omnibase_infra.models.registration import ( | ||
| ModelNodeHeartbeatEvent, | ||
| ModelNodeIntrospectionEvent, | ||
| ModelNodeRegistration, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "ModelNodeHeartbeatEvent", | ||
| "ModelNodeIntrospectionEvent", | ||
| "ModelNodeRegistration", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| # Copyright (c) 2025 OmniNode Team | ||
| """Registration models for ONEX 2-way registration pattern.""" | ||
|
|
||
| from omnibase_infra.models.registration.model_node_capabilities import ( | ||
| ModelNodeCapabilities, | ||
| ) | ||
| from omnibase_infra.models.registration.model_node_heartbeat_event import ( | ||
| ModelNodeHeartbeatEvent, | ||
| ) | ||
| from omnibase_infra.models.registration.model_node_introspection_event import ( | ||
| ModelNodeIntrospectionEvent, | ||
| ) | ||
| from omnibase_infra.models.registration.model_node_metadata import ModelNodeMetadata | ||
| from omnibase_infra.models.registration.model_node_registration import ( | ||
| ModelNodeRegistration, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "ModelNodeCapabilities", | ||
| "ModelNodeHeartbeatEvent", | ||
| "ModelNodeIntrospectionEvent", | ||
| "ModelNodeMetadata", | ||
| "ModelNodeRegistration", | ||
| ] |
169 changes: 169 additions & 0 deletions
169
src/omnibase_infra/models/registration/model_node_capabilities.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| # Copyright (c) 2025 OmniNode Team | ||
| """Node Capabilities Model. | ||
|
|
||
| This module provides ModelNodeCapabilities for strongly-typed node capabilities | ||
| in the ONEX 2-way registration pattern. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pydantic import BaseModel, ConfigDict, Field | ||
|
|
||
|
|
||
| class ModelNodeCapabilities(BaseModel): | ||
| """Strongly-typed node capabilities model. | ||
|
|
||
| Replaces dict[str, Any] with explicit capability fields. | ||
| Uses extra="allow" to support custom capabilities while | ||
| providing type safety for known fields. | ||
|
|
||
| Known capability fields are typed explicitly. Additional custom | ||
| capabilities can be added via the extra="allow" config, and they | ||
| will be stored as model extra fields accessible via model_extra. | ||
|
|
||
| Attributes: | ||
| postgres: Whether node has PostgreSQL capability. | ||
| read: Whether node has read capability. | ||
| write: Whether node has write capability. | ||
| database: Whether node has generic database capability. | ||
| processing: Whether node has processing capability. | ||
| batch_size: Optional batch size limit. | ||
| max_batch: Optional maximum batch size. | ||
| supported_types: List of supported data types. | ||
| routing: Whether node has routing capability. | ||
| config: Nested configuration dictionary. | ||
| transactions: Whether node supports transactions. | ||
| feature: Generic feature flag. | ||
|
|
||
| Example: | ||
| >>> caps = ModelNodeCapabilities( | ||
| ... postgres=True, | ||
| ... read=True, | ||
| ... write=True, | ||
| ... ) | ||
| >>> caps.postgres | ||
| True | ||
|
|
||
| >>> # Custom capabilities via extra="allow" | ||
| >>> caps = ModelNodeCapabilities( | ||
| ... custom_capability=True, # type: ignore[call-arg] | ||
| ... another_field="value", # type: ignore[call-arg] | ||
| ... ) | ||
| >>> caps.model_extra["custom_capability"] | ||
| True | ||
| """ | ||
|
|
||
| model_config = ConfigDict( | ||
| extra="allow", # Accept additional fields not explicitly defined | ||
| frozen=False, # Allow updates (ModelNodeRegistration is mutable) | ||
| from_attributes=True, | ||
| ) | ||
|
|
||
| # Database capabilities | ||
| postgres: bool = Field(default=False, description="PostgreSQL capability") | ||
| read: bool = Field(default=False, description="Read capability") | ||
| write: bool = Field(default=False, description="Write capability") | ||
| database: bool = Field(default=False, description="Generic database capability") | ||
| transactions: bool = Field(default=False, description="Transaction support") | ||
|
|
||
| # Processing capabilities | ||
| processing: bool = Field(default=False, description="Processing capability") | ||
| batch_size: int | None = Field(default=None, description="Batch size limit") | ||
| max_batch: int | None = Field(default=None, description="Maximum batch size") | ||
| supported_types: list[str] = Field( | ||
| default_factory=list, description="Supported data types" | ||
| ) | ||
|
|
||
| # Network capabilities | ||
| routing: bool = Field(default=False, description="Routing capability") | ||
|
|
||
| # Generic feature flag (used in tests) | ||
| feature: bool = Field(default=False, description="Generic feature flag") | ||
|
|
||
| # Configuration (nested) - using constrained types instead of Any | ||
| config: dict[str, int | str | bool | float] = Field( | ||
| default_factory=dict, description="Nested configuration" | ||
| ) | ||
|
|
||
| def __getitem__(self, key: str) -> object: | ||
| """Enable dict-like access to capabilities. | ||
|
|
||
| Args: | ||
| key: The capability name to retrieve. | ||
|
|
||
| Returns: | ||
| The capability value (from known field or model_extra). | ||
|
|
||
| Raises: | ||
| KeyError: If key is not found in known fields or model_extra. | ||
|
|
||
| Example: | ||
| >>> caps = ModelNodeCapabilities(postgres=True, custom=42) | ||
| >>> caps["postgres"] | ||
| True | ||
| >>> caps["custom"] # Custom capability from model_extra | ||
| 42 | ||
| """ | ||
| if key in type(self).model_fields: | ||
| return getattr(self, key) | ||
| extra = self.model_extra or {} | ||
| if key in extra: | ||
| return extra[key] | ||
| raise KeyError(key) | ||
|
|
||
| def __contains__(self, key: object) -> bool: | ||
| """Enable membership testing for capabilities. | ||
|
|
||
| Returns True if key is a known field OR exists in model_extra. | ||
|
|
||
| Args: | ||
| key: The capability name to check. | ||
|
|
||
| Returns: | ||
| True if the key exists as a known field or in model_extra. | ||
|
|
||
| Example: | ||
| >>> caps = ModelNodeCapabilities(postgres=True, custom=42) | ||
| >>> "postgres" in caps | ||
| True | ||
| >>> "custom" in caps # Custom capability in model_extra | ||
| True | ||
| >>> "unknown" in caps | ||
| False | ||
| """ | ||
| if not isinstance(key, str): | ||
| return False | ||
|
|
||
| # Check known fields first (access via class to avoid deprecation) | ||
| if key in type(self).model_fields: | ||
| return True | ||
|
|
||
| # Check model_extra for custom capabilities | ||
| return bool(self.model_extra and key in self.model_extra) | ||
|
|
||
| def get(self, key: str, default: object = None) -> object: | ||
| """Safely get a capability value with optional default. | ||
|
|
||
| Args: | ||
| key: The capability name to retrieve. | ||
| default: Value to return if key is not found (defaults to None). | ||
|
|
||
| Returns: | ||
| The capability value if found, otherwise the default value. | ||
|
|
||
| Example: | ||
| >>> caps = ModelNodeCapabilities(postgres=True) | ||
| >>> caps.get("postgres") | ||
| True | ||
| >>> caps.get("unknown", False) | ||
| False | ||
| >>> caps.get("unknown") # Returns None by default | ||
| """ | ||
| try: | ||
| return self[key] | ||
| except KeyError: | ||
| return default | ||
|
|
||
|
|
||
| __all__ = ["ModelNodeCapabilities"] | ||
98 changes: 98 additions & 0 deletions
98
src/omnibase_infra/models/registration/model_node_heartbeat_event.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| # Copyright (c) 2025 OmniNode Team | ||
| """Node Heartbeat Event Model. | ||
|
|
||
| This module provides ModelNodeHeartbeatEvent for periodic node heartbeat broadcasts | ||
| in the ONEX 2-way registration pattern. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from datetime import UTC, datetime | ||
| from uuid import UUID | ||
|
|
||
| from pydantic import BaseModel, ConfigDict, Field, field_validator | ||
|
|
||
| from omnibase_infra.utils.util_semver import validate_semver as _validate_semver | ||
|
|
||
|
|
||
| class ModelNodeHeartbeatEvent(BaseModel): | ||
| """Event model for periodic node heartbeat broadcasts. | ||
|
|
||
| Nodes publish this event periodically to indicate they are alive and | ||
| report current health metrics. Used by the Registry node to detect | ||
| node failures and track resource usage. | ||
|
|
||
| Attributes: | ||
| node_id: Node identifier. | ||
| node_type: ONEX node type string. | ||
| node_version: Semantic version of the node emitting this event. | ||
| uptime_seconds: Node uptime in seconds (must be >= 0). | ||
| active_operations_count: Number of active operations (must be >= 0). | ||
| memory_usage_mb: Optional memory usage in megabytes. | ||
| cpu_usage_percent: Optional CPU usage percentage (0-100). | ||
| correlation_id: Request correlation ID for tracing. | ||
| timestamp: Event timestamp. | ||
|
|
||
| Example: | ||
| >>> from uuid import uuid4 | ||
| >>> event = ModelNodeHeartbeatEvent( | ||
| ... node_id=uuid4(), | ||
| ... node_type="effect", | ||
| ... node_version="1.2.3", | ||
| ... uptime_seconds=3600.5, | ||
| ... active_operations_count=5, | ||
| ... memory_usage_mb=256.0, | ||
| ... cpu_usage_percent=15.5, | ||
| ... ) | ||
| """ | ||
|
|
||
| model_config = ConfigDict( | ||
| frozen=True, | ||
| extra="forbid", | ||
| from_attributes=True, | ||
| ) | ||
|
|
||
| # Required fields | ||
| node_id: UUID = Field(..., description="Node identifier") | ||
| # Design Note: node_type uses relaxed `str` validation (not `Literal`) to support | ||
| # custom node types during development. This is intentional - heartbeats may come | ||
| # from experimental or plugin nodes not in the standard ONEX type set. For strict | ||
| # validation, see ModelNodeIntrospectionEvent which uses Literal["effect", "compute", | ||
| # "reducer", "orchestrator"]. Tests explicitly verify custom types are accepted. | ||
| node_type: str = Field(..., description="ONEX node type") | ||
| node_version: str = Field( | ||
| default="1.0.0", | ||
| description="Semantic version of the node emitting this event", | ||
| ) | ||
|
|
||
| @field_validator("node_version") | ||
| @classmethod | ||
| def validate_semver(cls, v: str) -> str: | ||
| """Validate that node_version follows semantic versioning.""" | ||
| return _validate_semver(v, "node_version") | ||
|
|
||
| # Health metrics | ||
| uptime_seconds: float = Field(..., ge=0, description="Node uptime in seconds") | ||
| active_operations_count: int = Field( | ||
| default=0, ge=0, description="Number of active operations" | ||
| ) | ||
|
|
||
| # Resource usage (optional) | ||
| memory_usage_mb: float | None = Field( | ||
| default=None, ge=0, description="Memory usage in megabytes" | ||
| ) | ||
| cpu_usage_percent: float | None = Field( | ||
| default=None, ge=0, le=100, description="CPU usage percentage (0-100)" | ||
| ) | ||
|
|
||
| # Metadata | ||
| correlation_id: UUID | None = Field( | ||
| default=None, description="Request correlation ID for tracing" | ||
| ) | ||
| timestamp: datetime = Field( | ||
| default_factory=lambda: datetime.now(UTC), description="Event timestamp" | ||
| ) | ||
|
|
||
|
|
||
| __all__ = ["ModelNodeHeartbeatEvent"] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.