feat: Implement persistent agent state management and process handling#236
Open
doroteaMonaco wants to merge 7 commits intomofa-org:mainfrom
Open
feat: Implement persistent agent state management and process handling#236doroteaMonaco wants to merge 7 commits intomofa-org:mainfrom
doroteaMonaco wants to merge 7 commits intomofa-org:mainfrom
Conversation
- Added `PersistentAgentRegistry` for managing agent metadata on disk. - Introduced `AgentProcessManager` for spawning and managing agent processes. - Updated agent commands (`start`, `stop`, `list`) to utilize persistent storage. - Enhanced agent metadata structure to include process tracking and state management. - Implemented configuration validation for agent startup. - Refactored CLI context to include persistent agent registry and process manager. - Added timestamp formatting for agent start/stop events.
Collaborator
|
The code on your branch is not up to date. Please sync and merge the latest code from the main branch. |
Contributor
Author
|
Done, thanks! |
lijingrs
approved these changes
Feb 23, 2026
Collaborator
|
There are code conflicts. Could you please sync and pull the latest code, then merge it into your current branch in your IDE? |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PersistentAgentRegistryfor managing agent metadata on disk.AgentProcessManagerfor spawning and managing agent processes.start,stop,list) to utilize persistent storage.📋 Summary
This PR introduces the
PersistentAgentRegistryandAgentProcessManagersubsystems, enabling the CLI to manage agent processes with full lifecycle tracking, persistent state, and cross-platform compatibility. Agent commands now operate on real data stored in~/.local/share/mofa/agents/instead of returning hardcoded responses.🔗 Related Issues
Closes #
Related to #127
🧠 Context
Problem: The agent CLI commands (list, start, stop) were returning hardcoded stub responses without actually managing processes or persisting state.
Solution:
PersistentAgentRegistrysaves agent metadata to disk in JSON formatAgentProcessManagerspawns/terminates agent processes and tracks PIDsDesign Decisions:
🛠️ Changes
PersistentAgentRegistry(src/state/agent_state.rs) - Manages agent metadata lifecycle with disk persistenceAgentProcessManager(src/utils/process_manager.rs) - Spawns/terminates processes with platform-specific signalsagent startcommand - Validates config, creates process, records metadataagent stopcommand - Sends SIGTERM/TerminateProcess and updates stateagent listcommand - Reads from disk and displays running/stopped agents with timestampsAgentMetadatastructure - Added PID, state, timestamps, start countPersistentAgentRegistryandAgentProcessManagerformat_timestamp()for human-readable time display (src/commands/agent/list.rs)🧪 How you Tested
Unit Tests (27 total, all passing):
test_agent_metadata_lifecycle- Verifies state transitions (Stopped → Running → Stopped)test_registry_persistence- Ensures agent data survives disk I/Otest_list_running_agents- Confirms filtering logic workstest_process_manager_creation- Validates PM initializationtest_validate_config_missing_file- Error handling for missing configtest_validate_config_valid_yaml- Accepts valid YAML configtest_validate_config_invalid_yaml- Rejects malformed config📸 Screenshots / Logs (if applicable)
If breaking:
🧹 Checklist
Code Quality
cargo fmtruncargo clippypasses without warningsTesting
cargo testpasses locally without any errorDocumentation
PR Hygiene
main🚀 Deployment Notes (if applicable)
🧩 Additional Notes for Reviewers