feat: add Idle agent state — smart idle detection + wake-on-demand#792
Open
AL-ZiLLA wants to merge 1 commit intoRightNow-AI:mainfrom
Open
feat: add Idle agent state — smart idle detection + wake-on-demand#792AL-ZiLLA wants to merge 1 commit intoRightNow-AI:mainfrom
AL-ZiLLA wants to merge 1 commit intoRightNow-AI:mainfrom
Conversation
Idle agents (no pending crons, active schedules, or background tasks) are now marked Idle instead of Crashed when they time out. This eliminates unnecessary auto-recovery cycles that burn LLM credits on agents with no work to do. Smart detection: before marking an unresponsive agent as Crashed, the heartbeat monitor checks for pending cron jobs, active background tasks, and non-reactive schedules. Only agents with real work are recovered. Wake-on-demand: idle agents automatically transition back to Running when a message arrives (API, channel, or inter-agent), a cron job fires, or a manual restart is triggered. UI: TUI shows [IDL] badge (yellow), dashboard shows warning badge for idle agents. Backward compatible — agents with active work still crash and recover normally. No config changes required. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Idlevariant toAgentStateenum — agents with no pending work are marked Idle instead of Crashed when they time outThe Problem
OpenFang treats "idle" and "crashed" identically. If an agent doesn't heartbeat within the timeout, it's marked Crashed and auto-recovered — even if it has nothing to do. This burns LLM credits on pointless recovery calls for agents that are simply idle between tasks.
The Fix
Before marking an agent as Crashed, the heartbeat checker now asks: does this agent have a reason to be alive right now?
An agent is marked Crashed (and auto-recovered) if ANY of:
If NONE of those are true → marked Idle (new state), NOT Crashed. No auto-recovery.
An Idle agent wakes up when:
Files Changed
openfang-types/src/agent.rsIdlevariant toAgentStateenumopenfang-kernel/src/heartbeat.rsopenfang-kernel/src/cron.rshas_due_jobs_soon()methodopenfang-kernel/src/background.rshas_task()methodopenfang-kernel/src/kernel.rsopenfang-cli/src/tui/theme.rs[IDL]badge for idle stateopenfang-cli/src/tui/screens/comms.rsopenfang-api/static/js/pages/comms.jsTest plan
cargo build --workspace --lib— compiles cleancargo test --workspace— all tests pass (2200+, 0 failures)cargo clippy -p openfang-types -p openfang-kernel -p openfang-api --all-targets -- -D warnings— zero warningsBackward compatible
serde(rename_all = "snake_case")ensuresIdleserializes as"idle"in JSON_ => ...catch-alls handle the new variant gracefully🤖 Generated with Claude Code