fix(kanban): make worker termination and retries fail closed - #69942
Draft
vutruongduc wants to merge 6 commits into
Draft
vutruongduc wants to merge 6 commits into
vutruongduc wants to merge 6 commits into
Conversation
Contributor
Related to #69036 (worker-group reclamation) and #63637 (runtime ownership). This PR also changes terminal tool barriers and iteration-exhaustion/notifier semantics, so it is not a duplicate; please choose whether to consolidate the overlapping lifecycle work. |
Collaborator
|
Thanks for the extensive worker-lifecycle hardening. The core premise remains live on current main: Problems
Suggested changes
Automated hermes-sweeper review. |
This branch has not been deployed
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.
What does this PR do?
This fixes a Kanban worker incident in which a worker successfully called a terminal task tool, continued through its remaining model iterations, and left its task lease active. The same run was then reported as a timeout with
max_runtime=0s, even though the actual trigger was iteration-budget exhaustion.The root causes were split across the worker lifecycle: terminal task transitions were handled like ordinary tool calls, ownership was not fenced at every API/tool boundary, process cleanup targeted a PID instead of the whole worker process group, and the per-task retry policy was not persisted and reported end to end. A refunded
execute_codecall could also make the cleanup-reserve counter disagree with the hard API-call limit, while a persisted local-shell snapshot could restore an older budget into later tool calls.The fix makes worker shutdown fail closed while preserving message-role alternation and existing non-worker behavior.
Related Issue
No public issue. This was reproduced from an operator incident in a scheduled Kanban workflow.
Type of Change
Changes Made
kanban_completeandkanban_blockcalls as terminal barriers: skip later calls in the batch with paired tool results and do not make another model call. A failed terminal transition still lets the worker continue.iteration_exhaustedfrom wall-clocktimed_out, preserve effective budget metadata, and avoid misleadingmax_runtime=0snotifications.max(0, min(iteration_budget.remaining, max_iterations - api_call_count)). This prevents a refundedexecute_codecall from bypassing the hard API limit.mktemp, which keeps concurrent snapshot updates atomic on macOS Bash 3.2 whereBASHPIDis empty.max_retries >= 1persistence and readback.max_retries=1blocks on the first abnormal outcome without an automatic retry.How to Test
Run the directly related lifecycle and environment suite with file retries disabled:
HERMES_PYTHON=/path/to/python scripts/run_tests.sh --file-retries 0 -j6 tests/agent/test_kanban_stop.py tests/agent/test_turn_finalizer_iteration_limit_exit.py tests/gateway/test_kanban_notifier.py tests/hermes_cli/test_kanban_core_functionality.py tests/hermes_cli/test_kanban_diagnostics.py tests/hermes_cli/test_kanban_notify.py tests/run_agent/test_run_agent.py tests/run_agent/test_tool_batch_segmentation.py tests/tools/test_kanban_tools.py tests/tools/test_base_environment.py tests/tools/test_local_env_blocklist.py tests/tools/test_local_env_session_leak.py tests/tools/test_local_shell_init.py tests/tools/test_terminal_env_bridge.py tests/tools/test_local_env_iteration_budget.pyStable focused regressions:
tests/tools/test_local_env_iteration_budget.py::test_kanban_budget_refreshes_after_snapshottests/tools/test_base_environment.py::TestAtomicSnapshotWrite::test_temp_path_is_allocated_atomically_with_mktempObserved results on macOS:
git diff --check: clean.Checklist
Code
fix(scope):,feat(scope):, etc.)Documentation & Housekeeping
cli-config.yaml.exampleupdate is N/A; no new global config key is addedCONTRIBUTING.mdandAGENTS.mdupdates are N/Amax_retriesAdditional hook-consent regression
The rollout canary also exposed that an explicit top-level
--accept-hooksflag was ignored byhermes hooks listandhermes hooks doctorbecause management commands intentionally skip full agent startup. The CLI now registers configured hooks only when this explicit flag is present; ordinary hook inspection remains non-mutating and mtime-drift protection is unchanged.Focused hook and parser validation: 117 tests passed across 4 files, 0 failed.