Skip to content

Comments

fix(kernel): include Running in state transitions#211

Open
wysh3 wants to merge 3 commits intomofa-org:mainfrom
wysh3:fix/agent-state-running-transitions
Open

fix(kernel): include Running in state transitions#211
wysh3 wants to merge 3 commits intomofa-org:mainfrom
wysh3:fix/agent-state-running-transitions

Conversation

@wysh3
Copy link
Contributor

@wysh3 wysh3 commented Feb 22, 2026

Summary

AgentState::Running existed as a valid state variant but was excluded from
is_active() and had zero transitions defined in can_transition_to(). This PR
fixes both gaps and adds test coverage.

Motivation

Agents in the Running state were incorrectly reported as inactive by
is_active(), which only checked for Ready and Executing. Additionally, any
call to state.transition_to(AgentState::Running) would always return
AgentError::invalid_state_transition because the state machine had no
transitions defined for Running — making it unreachable via the public API
despite being a valid enum variant used by the runtime.

Changes

  • mofa-kernel: Updated AgentState::is_active() to return true for
    Running (in addition to Ready and Executing)
  • mofa-kernel: Added 6 missing transitions to can_transition_to():
    • Ready → Running
    • Running → Paused
    • Running → Executing
    • Running → ShuttingDown
    • Running → Error(_)
    • Running → Failed
  • mofa-kernel: Added test_agent_state_running_transitions (12 assertions
    covering valid/invalid transitions and transition_to() return values)
  • mofa-kernel: Added test_agent_state_is_active (8 assertions covering
    all relevant states)

Related Issues

Closes #199

Found during codebase audit — AgentState::Running was defined and handled in
Display but missing from the state machine logic.

Testing

  • cargo fmt --check — clean
  • cargo clippy -p mofa-kernel — exit 0, no new warnings
  • cargo test -p mofa-kernel82 passed, 0 failed

Checklist

  • cargo fmt --check passes
  • cargo clippy passes with no warnings
  • cargo test passes
  • Architecture layer rules respected (see CONTRIBUTING.md)
  • Relevant documentation updated

Running state existed but was excluded from is_active() causing agents in
Running state to be reported as inactive. can_transition_to() also had no
transitions defined for Running, making it unreachable from Ready.

Changes:
- is_active() now returns true for Running state
- Added transitions: Ready->Running, Running->Paused, Running->Executing,
  Running->ShuttingDown, Running->Error, Running->Failed
- Added test_agent_state_running_transitions covering all new transitions
- Added test_agent_state_is_active covering all states
@lijingrs
Copy link
Collaborator

Hi :
We noticed that many PR checks are failing, which is likely caused by not pulling the latest code.
Our basic check commands are as follows:

cargo clippy --workspace --all-features -- -D errors
cargo test --workspace --all-features
cargo build --examples
cargo doc --workspace --no-deps --all-features
cargo doc --workspace --no-deps --all-features --document-private-items

Please verify this. If you confirm the code is correct, just leave a comment, and we will merge it and test it ourselves.

@wysh3
Copy link
Contributor Author

wysh3 commented Feb 22, 2026

@lijingrs Just merged the latest from main, now all checks are passing now. Feel free to merge and test whenever you're ready, and let me know if you spot any issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(kernel): AgentState::Running missing from is_active() and state machine transitions

2 participants