Repository navigation
[FD-3805] feat(prompt_agent): grade on max-steps terminal instead of retrying - #138
Open
williamloo-scale wants to merge 2 commits into
Open
williamloo-scale wants to merge 2 commits into
williamloo-scale wants to merge 2 commits into
Conversation
When a solver's A2A terminal reports failure with error_code "max_turns_reached", treat it as an expected budget outcome: log it and return the context (the prompt_response + trajectory are already recorded) so the task proceeds to grading. Previously this raised RuntimeError, which Temporal retried up to its step-attempt cap — each attempt burning another full step budget and never grading. Adds MAX_TURNS_ERROR_CODE to the a2a protocol as the cross-process contract string a harness emits for this condition. Other failure modes still raise and retry unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Both rubrics_verifier and agent_prompt_response_verifier skip any PromptResponse carrying an error_type. A max-turns terminal records error_type alongside error_code=max_turns_reached, so budget-exhausted runs — the exact case PR #138 routes to grading — were silently skipped instead of graded on their partial trajectory. Add PromptResponse.is_gradable_despite_error as the single source of truth (true only for MAX_TURNS_ERROR_CODE) and gate both verifiers' error_type skip on it, keeping the error details on the response. Tests: - test_max_turns_grading.py: the property carve-out, plus the verifier reaching grading on a max-turns error and still skipping a real crash. - test_prompt_agent.py: a failed max-turns terminal with a trajectory extension now asserts the recorded response points at the stored partial actions. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
When a solver's A2A terminal reports failure with
error_code == "max_turns_reached",PromptAgentTaskStep.executenow returns the context (logging a warning) instead of raisingRuntimeError. The task then flows on to grading (cua_evaluate) with the partial trajectory, which is already recorded inprompt_responsesbefore the failure branch.Adds
MAX_TURNS_ERROR_CODE = "max_turns_reached"toa2a_agent/protocol.pyas the cross-process contract string.Why
A max-steps/max-turns outcome is an expected budget exhaustion, not a retryable crash. Previously it raised, and the Temporal step-attempt retry (cap 3 in the scaleapi worker) re-ran the whole prompt — each attempt burning another full step budget (e.g. 3 × 500 = 1500 steps) and never grading. Now it grades once, no retry.
Other failure modes (no
error_code, or a different one) still raise and retry exactly as before.Companion change (separate repo)
The harness that produces the terminal must emit
error_code: "max_turns_reached"on its max-turns branch for this to trigger. That lives in the agent harness/gateway package (not this repo). This PR is forward-compatible: with no harness emitting the code yet, behavior is unchanged. The harness PR and this should land together.Tests
tst/unit/task_step/test_prompt_agent.py:test_max_turns_terminal_grades_without_raising— failed terminal +max_turns_reached→executereturns context, records the prompt_response with the code; no raise.test_other_failed_terminal_still_raises— failed terminal without the code still raisesRuntimeError.Full
test_prompt_agent.pysuite passes (15 tests).🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; both previous findings are addressed and no new blocking issue remains.Summary
Budget-exhausted agent runs return their saved context so downstream steps can grade partial work instead of retrying the prompt.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Agent terminal received] --> B[Save response and available trajectory] B --> C{Failed terminal?} C -->|No| F[Continue to grading] C -->|Yes| D{max_turns_reached?} D -->|Yes| F D -->|No| E[Raise failure] F --> G[Verifiers allow budget exhaustion]Reviews (2) · Last reviewed commit: "fix(verifiers): grade max-turns runs ins..." · Reviewed by Greptile