Skip to content

[FD-3805] feat(prompt_agent): grade on max-steps terminal instead of retrying - #138

Open
williamloo-scale wants to merge 2 commits into
mainfrom
wloo/prompt-agent-max-steps-grade-no-retry
Open

williamloo-scale wants to merge 2 commits into
mainfrom
wloo/prompt-agent-max-steps-grade-no-retry

Conversation

@williamloo-scale

@williamloo-scale williamloo-scale commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What

When a solver's A2A terminal reports failure with error_code == "max_turns_reached", PromptAgentTaskStep.execute now returns the context (logging a warning) instead of raising RuntimeError. The task then flows on to grading (cua_evaluate) with the partial trajectory, which is already recorded in prompt_responses before the failure branch.

Adds MAX_TURNS_ERROR_CODE = "max_turns_reached" to a2a_agent/protocol.py as 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 → execute returns context, records the prompt_response with the code; no raise.
  • test_other_failed_terminal_still_raises — failed terminal without the code still raises RuntimeError.

Full test_prompt_agent.py suite passes (15 tests).

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence 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.

  • Max-turns failures now reach grading without retrying.

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]
Loading

Reviews (2) · Last reviewed commit: "fix(verifiers): grade max-turns runs ins..." · Reviewed by Greptile

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>
@williamloo-scale
williamloo-scale requested a review from a team as a code owner October 9, 2026 06:40
@williamloo-scale williamloo-scale changed the title feat(prompt_agent): grade on max-steps terminal instead of retrying feat(prompt_agent): grade on max-steps terminal instead of retrying [FD-3805] Oct 9, 2026
Comment thread src/agent_env/task_step/task_steps/prompt_agent.py
Comment thread tst/unit/task_step/test_prompt_agent.py
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>
@williamloo-scale williamloo-scale changed the title feat(prompt_agent): grade on max-steps terminal instead of retrying [FD-3805] [FD-3805] feat(prompt_agent): grade on max-steps terminal instead of retrying Oct 12, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant