fix(agent, cron): handle final reports at iteration limits - #50967
Closed
helix4u wants to merge 2 commits into
Closed
fix(agent, cron): handle final reports at iteration limits#50967helix4u wants to merge 2 commits into
helix4u wants to merge 2 commits into
Conversation
helix4u
marked this pull request as ready for review
June 22, 2026 18:07
19 tasks
Contributor
|
Merged via #50989 (#50989). Both of your commits were cherry-picked onto current main with your authorship preserved in git log (3972701, ae7e857). This fixes exactly the symptom NilVaw reported: a complete cron report landing on the last allowed API call was marked incomplete and raised as a RuntimeError whose text was the report itself. Your turn_finalizer change (text_response → completed=True) and the cron-side delivery of max-iteration summaries both landed. Thanks! |
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?
Fixes two completion-state boundary cases where Hermes can produce usable final text at the iteration limit, but downstream code still treats the turn as incomplete.
First,
agent.turn_finalizer.finalize_turn()now treats a normal finaltext_response(...)as completed even when it lands on exactly the last allowed API call. The previous predicate requiredapi_call_count < max_iterations, so a successfultext_response(finish_reason=stop)atapi_call_count == max_iterationsreturnedcompleted=False.Second, cron now handles the related but distinct max-iteration fallback-summary path. A cron run can hit
max_iterations_reached(...), receive a non-empty fallback report from the no-tools summary call, and still havecompleted=Falsein the generic agent result. Cron should deliver that report instead of raisingRuntimeError(<full report>).The generic max-iteration semantics stay intact for interactive and worker paths. The cron-specific exception only applies when
failedis not true, the exit reason ismax_iterations_reached(...), and the fallback response is non-empty.Related Issue
Discord support thread: https://discord.com/channels/1053877538025386074/1518634271122784427
Supersedes #50980; the cron fallback-summary fix has been consolidated here so the support thread has a single review target.
Separate related PR:
Type of Change
Changes Made
agent/turn_finalizer.py: treattext_response(...)exits with a final response as completed even when they happen on the last allowed API call.cron/scheduler.py: let cron deliver a non-emptymax_iterations_reached(...)fallback response instead of raising it as an error whencompleted=False.tests/agent/test_turn_finalizer_cleanup_guard.py: add regression coverage for a final text response at the max-iteration boundary, while keeping true max-iteration summary turns incomplete.tests/cron/test_scheduler.py: add regression coverage for cron delivering a non-empty max-iteration fallback report.How to Test
scripts/run_tests.sh -j 4 tests/agent/test_turn_finalizer_cleanup_guard.py tests/cron/test_scheduler.pycompleted=True.completed=False.max_iterations_reached(...)fallback response instead of failing the run.failed=True, empty incomplete output, or explicit errors still fail.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AFor New Skills
N/A
Screenshots / Logs
Focused test run:
scripts/run_tests.sh -j 4 tests/agent/test_turn_finalizer_cleanup_guard.py tests/cron/test_scheduler.pyResult: 169 tests passed.