Repository navigation
Conversation
…OpenHands#5627) A /goal loop that was in flight when the process stopped left its last persisted goal status active=True ("running"): a graceful shutdown cancels the loop inside close() with _closing set (the cancel handler then records nothing), and a hard kill never runs close() at all. After the restart no loop exists, yet the stale status made a UI render a dead goal as running forever and /goal/stop could not clear it. EventService.start() now reconciles the loaded state: when the last persisted goal status is active, it appends a "goal" state-update event with the same objective/iteration/max_iterations/verdict and active=False, status="interrupted" -- the same terminal record /goal/stop writes -- keeping the goal resumable via /goal/resume. The state-lock acquisition runs in a worker thread per the agent-server concurrency rules. Terminal statuses (complete/capped) and conversations without goal events are left untouched. Co-authored-by: openhands <openhands@all-hands.dev>
|
Closing in favour of #5772, which fixes the same issue (#5627) and has been approved. The core approach here — reconciling the stale goal status in This comment was created by an AI agent (OpenHands) on behalf of Graham Neubig. |
HUMAN:
AGENT:
Why
Fixes #5627. When the agent server stops while a
/goalloop is active, the loop is cancelled but no terminal goal status is recorded: a graceful shutdown cancels it insideclose()with_closingset (the cancel handler deliberately records nothing), and a hard kill never runsclose()at all. After the restart the last persistedgoalstatus still saysactive: true, status: "running"while no loop exists, so a UI shows a running goal indefinitely and/goal/stopcannot clear it (there is no task to cancel).Summary
EventService.start()now reconciles the loaded state next to the existing stale-RUNNINGexecution-status reconcile: when the last persisted goal status isactive: true, it appends agoalConversationStateUpdateEventwith the sameobjective,iteration,max_iterations, andverdict, andactive: false, status: "interrupted"— the same terminal record/goal/stopwrites.run_in_executor), per the agent-server concurrency rules inopenhands-agent-server/AGENTS.md.complete/capped) and conversations without any goal status are left untouched; the goal event value shape is unchanged, so no schema or REST contract change.Issue Number
#5627
How to Test
uv run pytest tests/agent_server/test_goal_loop.py— 23 passed, including three new regression tests:test_restart_reconciles_stale_running_goal_status— hard-kill simulation: a persistedactive: truestatus is reconciled tointerruptedwith identical fields, exactly one new event is appended, and/goal/resumeis admitted afterwards and drives the loop tocomplete.test_goal_loop_graceful_shutdown_reconciles_on_restart— a real loop is caught mid-audit,close()tears the service down (no status recorded), and the reload reconciles the stale status.test_restart_preserves_terminal_goal_status— acompletestatus gains no extra event on reload, and a conversation without goal events stays goal-event-free..venv):tests/agent_server/test_goal_loop.py,test_event_service.py,test_switch_llm_survives_reload.py,test_run_admission.py,test_conversation_lease.py,test_conversation_service.pyall green;ruff check+ruff format --checkandpyrightclean on the changed files.mainand pass with the fix.Video/Screenshots
Not a visual change; the How to Test section covers the observable behavior via the goal-status events.
Design Doc
Small, single-site fix; no design doc needed.
Type
Notes
The issue's alternative (recording
interruptedin the cancel handler duringclose()) would not cover a hard kill, which is why the fix reconciles instart()from the loaded state, as the triage suggested. TheF11.goal-restart-activemap bullet lives in the still-open verify-agent-server PR #5621, so it is out of scope here.