Repository navigation
refactor(enums): replace hardcoded status strings with enum references (OMN-1309) #385
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 4 commits into
main
from
jonah/omn-1309-refactor-hardcoded-status-strings
Jan 13, 2026
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
52e94eb
refactor(enums): replace hardcoded status strings with enum reference…
14d2b75
Merge main and address PR #385 review feedback (OMN-1309)
d28bbc7
fix(validation): rename MemberCasingChecker to avoid enum naming fals…
8814509
fix(enums): address PR #385 review feedback (OMN-1309)
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| # SPDX-FileCopyrightText: 2025 OmniNode Team <info@omninode.ai> | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """ | ||
| Action Status Enumeration for Action Metadata Tracking. | ||
|
|
||
| Provides status values for tracking action lifecycle in orchestrator workflows. | ||
| Actions progress through states from creation to completion or failure. | ||
|
|
||
| State Machine: | ||
| CREATED -> READY -> RUNNING -> COMPLETED | ||
| | | | ||
| v v | ||
| FAILED FAILED | ||
|
|
||
| .. versionadded:: 0.6.5 | ||
| Added as part of OMN-1309 to replace hardcoded status strings with enum references. | ||
| """ | ||
|
|
||
| from enum import Enum, unique | ||
|
|
||
|
|
||
| @unique | ||
| class EnumActionStatus(str, Enum): | ||
| """ | ||
| Action status values for action metadata tracking. | ||
|
|
||
| Represents the lifecycle states of an action within orchestrator workflows. | ||
| Inherits from ``str`` for proper JSON serialization - values serialize | ||
| to lowercase strings. | ||
|
|
||
| Attributes: | ||
| CREATED: Initial state when action is constructed but not yet ready. | ||
| READY: Action has been validated and is ready for execution. | ||
| RUNNING: Action execution is currently in progress. | ||
| COMPLETED: Action has completed successfully. | ||
| FAILED: Action has failed with an error. | ||
|
|
||
| Example: | ||
| >>> status = EnumActionStatus.CREATED | ||
| >>> str(status) | ||
| 'created' | ||
| >>> import json | ||
| >>> json.dumps({"status": status}) | ||
| '{"status": "created"}' | ||
|
|
||
| .. versionadded:: 0.6.5 | ||
| Added as part of OMN-1309 to replace hardcoded status strings. | ||
| """ | ||
|
|
||
| CREATED = "created" | ||
| READY = "ready" | ||
| RUNNING = "running" | ||
| COMPLETED = "completed" | ||
| FAILED = "failed" | ||
|
|
||
| def __str__(self) -> str: | ||
| """Return the string value of the action status.""" | ||
| return self.value | ||
|
|
||
| def is_terminal(self) -> bool: | ||
| """ | ||
| Check if this status represents a terminal state. | ||
|
|
||
| Terminal states indicate the action has finished execution | ||
| and will not transition to any other state. | ||
|
|
||
| Returns: | ||
| True if COMPLETED or FAILED, False otherwise. | ||
|
|
||
| Example: | ||
| >>> EnumActionStatus.COMPLETED.is_terminal() | ||
| True | ||
| >>> EnumActionStatus.RUNNING.is_terminal() | ||
| False | ||
| """ | ||
| return self in {EnumActionStatus.COMPLETED, EnumActionStatus.FAILED} | ||
|
|
||
| def is_active(self) -> bool: | ||
| """ | ||
| Check if this status represents an active execution state. | ||
|
|
||
| Active states indicate the action is currently being executed. | ||
|
|
||
| Returns: | ||
| True if RUNNING, False otherwise. | ||
|
|
||
| Example: | ||
| >>> EnumActionStatus.RUNNING.is_active() | ||
| True | ||
| >>> EnumActionStatus.READY.is_active() | ||
| False | ||
| """ | ||
| return self == EnumActionStatus.RUNNING | ||
|
|
||
| def is_pending(self) -> bool: | ||
| """ | ||
| Check if this status represents a pending state. | ||
|
|
||
| Pending states indicate the action has not yet started execution. | ||
|
|
||
| Returns: | ||
| True if CREATED or READY, False otherwise. | ||
|
|
||
| Example: | ||
| >>> EnumActionStatus.CREATED.is_pending() | ||
| True | ||
| >>> EnumActionStatus.RUNNING.is_pending() | ||
| False | ||
| """ | ||
| return self in {EnumActionStatus.CREATED, EnumActionStatus.READY} | ||
|
|
||
| def is_success(self) -> bool: | ||
| """ | ||
| Check if this status represents successful completion. | ||
|
|
||
| Returns: | ||
| True if COMPLETED, False otherwise. | ||
|
|
||
| Example: | ||
| >>> EnumActionStatus.COMPLETED.is_success() | ||
| True | ||
| >>> EnumActionStatus.FAILED.is_success() | ||
| False | ||
| """ | ||
| return self == EnumActionStatus.COMPLETED | ||
|
|
||
| def is_failure(self) -> bool: | ||
| """ | ||
| Check if this status represents a failure state. | ||
|
|
||
| Returns: | ||
| True if FAILED, False otherwise. | ||
|
|
||
| Example: | ||
| >>> EnumActionStatus.FAILED.is_failure() | ||
| True | ||
| >>> EnumActionStatus.COMPLETED.is_failure() | ||
| False | ||
| """ | ||
| return self == EnumActionStatus.FAILED | ||
|
|
||
| def can_transition_to(self, target: "EnumActionStatus") -> bool: | ||
| """ | ||
| Check if transitioning to the target state is valid. | ||
|
|
||
| Valid state transitions: | ||
| - CREATED -> READY (action validated and ready) | ||
| - CREATED -> FAILED (validation failure) | ||
| - READY -> RUNNING (execution started) | ||
| - READY -> FAILED (pre-execution failure) | ||
| - RUNNING -> COMPLETED (successful completion) | ||
| - RUNNING -> FAILED (execution failure) | ||
|
|
||
| Terminal states (COMPLETED, FAILED) cannot transition to any state. | ||
|
|
||
| Args: | ||
| target: The target status to transition to. | ||
|
|
||
| Returns: | ||
| True if the transition is valid, False otherwise. | ||
|
|
||
| Example: | ||
| >>> EnumActionStatus.CREATED.can_transition_to(EnumActionStatus.READY) | ||
| True | ||
| >>> EnumActionStatus.COMPLETED.can_transition_to(EnumActionStatus.RUNNING) | ||
| False | ||
| >>> EnumActionStatus.RUNNING.can_transition_to(EnumActionStatus.COMPLETED) | ||
| True | ||
| """ | ||
| valid_transitions: dict[EnumActionStatus, set[EnumActionStatus]] = { | ||
| EnumActionStatus.CREATED: {EnumActionStatus.READY, EnumActionStatus.FAILED}, | ||
| EnumActionStatus.READY: {EnumActionStatus.RUNNING, EnumActionStatus.FAILED}, | ||
| EnumActionStatus.RUNNING: { | ||
| EnumActionStatus.COMPLETED, | ||
| EnumActionStatus.FAILED, | ||
| }, | ||
| EnumActionStatus.COMPLETED: set(), | ||
| EnumActionStatus.FAILED: set(), | ||
| } | ||
| return target in valid_transitions.get(self, set()) | ||
|
|
||
|
|
||
| __all__ = ["EnumActionStatus"] | ||
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,89 @@ | ||
| """ | ||
| Node Lifecycle Status Enum. | ||
|
|
||
| Defines the lifecycle states for nodes in the ONEX system. | ||
| Used by NodeCoreBase and derived node types for tracking | ||
| initialization and cleanup phases. | ||
|
|
||
| .. versionadded:: 0.6.5 | ||
| Added as part of OMN-1309 (replace hardcoded status strings). | ||
| """ | ||
|
|
||
| from enum import Enum, unique | ||
|
|
||
|
|
||
| @unique | ||
| class EnumNodeLifecycleStatus(str, Enum): | ||
| """ | ||
| Node lifecycle status values. | ||
|
|
||
| Inherits from ``str`` to ensure proper JSON serialization - enum values | ||
| serialize directly to their lowercase string values. | ||
|
|
||
| Lifecycle Flow:: | ||
|
|
||
| INITIALIZED -> INITIALIZING -> READY -> CLEANING_UP -> CLEANED_UP | ||
| \\-> FAILED | ||
| CLEANING_UP -> CLEANUP_FAILED | ||
|
|
||
| States: | ||
| INITIALIZED: Node has been constructed but not yet started. | ||
| INITIALIZING: Node initialization is in progress. | ||
| READY: Node is fully initialized and ready for processing. | ||
| FAILED: Node initialization or processing failed. | ||
| CLEANING_UP: Node cleanup is in progress. | ||
| CLEANED_UP: Node cleanup completed successfully. | ||
| CLEANUP_FAILED: Node cleanup failed (logged but not raised). | ||
| """ | ||
|
|
||
| INITIALIZED = "initialized" | ||
| """Node has been constructed but not yet started.""" | ||
|
|
||
| INITIALIZING = "initializing" | ||
| """Node initialization is in progress.""" | ||
|
|
||
| READY = "ready" | ||
| """Node is fully initialized and ready for processing.""" | ||
|
|
||
| FAILED = "failed" | ||
| """Node initialization or processing failed.""" | ||
|
|
||
| CLEANING_UP = "cleaning_up" | ||
| """Node cleanup is in progress.""" | ||
|
|
||
| CLEANED_UP = "cleaned_up" | ||
| """Node cleanup completed successfully.""" | ||
|
|
||
| CLEANUP_FAILED = "cleanup_failed" | ||
| """Node cleanup failed (logged but not raised).""" | ||
|
|
||
| def __str__(self) -> str: | ||
| """Return the string value of the lifecycle status.""" | ||
| return self.value | ||
|
|
||
| def is_terminal(self) -> bool: | ||
| """Check if this is a terminal state (no further transitions expected).""" | ||
| return self in { | ||
| EnumNodeLifecycleStatus.CLEANED_UP, | ||
| EnumNodeLifecycleStatus.CLEANUP_FAILED, | ||
| EnumNodeLifecycleStatus.FAILED, | ||
| } | ||
|
|
||
| def is_active(self) -> bool: | ||
| """Check if this state indicates the node is actively processing.""" | ||
| return self in { | ||
| EnumNodeLifecycleStatus.INITIALIZING, | ||
| EnumNodeLifecycleStatus.READY, | ||
| EnumNodeLifecycleStatus.CLEANING_UP, | ||
| } | ||
|
|
||
| def is_error(self) -> bool: | ||
| """Check if this state indicates an error condition.""" | ||
| return self in { | ||
| EnumNodeLifecycleStatus.FAILED, | ||
| EnumNodeLifecycleStatus.CLEANUP_FAILED, | ||
| } | ||
|
|
||
|
|
||
| # Export for use | ||
| __all__ = ["EnumNodeLifecycleStatus"] |
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.