Stop the AI flow when a worker or reviewer turn is incomplete#24257
Stop the AI flow when a worker or reviewer turn is incomplete#24257luisorofino wants to merge 1 commit into
Conversation
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b71179f44e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if require_complete and response.stop_reason != StopReason.END_TURN: | ||
| raise IncompleteResponseError( | ||
| f"{self._scope.owner_id} finished with stop_reason=" | ||
| f"{response.stop_reason.value!r} (expected END_TURN); the turn is incomplete.", | ||
| stop_reason=response.stop_reason, | ||
| ) |
There was a problem hiding this comment.
Preserve token accounting for incomplete required turns
When require_complete=True and the terminal response is MAX_TOKENS/OTHER, this raises before returning a ReActResult or attaching the accumulated total_input/total_output. In the orchestrated phase path, _start_task only increments phase totals after process.start(...) returns, so a truncated worker/reviewer turn produces a failed checkpoint that omits the tokens spent on that API call; during goal retries it can also drop already accumulated reviewer/compaction tokens. Please carry the token totals on the exception or record them before raising so failure checkpoints remain accurate.
Useful? React with 👍 / 👎.
Validation ReportAll 21 validations passed. Show details
|
What does this PR do?
Adds an
IncompleteResponseErrorexception and arequire_completeflag toReActProcess.start(). Whenrequire_complete=True, the method raises if the terminal stop reason is anything other thanEND_TURN(i.e.MAX_TOKENSorOTHER). The flag is opted in at the worker and reviewer call sites inAgenticPhase._start_task,_run_reviewer_once, and the worker-retry path in_drive_goal_loop. Subagents and the memory step are deliberately left on the defaultrequire_complete=False.Motivation
During a demo run, a worker agent hit
max_tokensmid-task — its output was cut off. BecauseAgenticPhaseignored the stop reason, the truncated result was handed straight to the goal reviewer. The reviewer (correctly) rejected the incomplete work, and the retry path then crashed the run.The root issue is that a truncated turn is not a valid basis for goal validation or for advancing the flow — the model wanted to produce more output and was stopped. Rather than silently proceeding into the reviewer with half-finished work, we now fail fast with a clear, deliberate error.
Subagents keep their existing soft behavior (
[SUBAGENT HIT MAX_TOKENS — RESPONSE MAY BE TRUNCATED]prefix) because a truncated subagent is a localized, recoverable degradation, not a reason to abort the whole run.Review checklist (to be filled by reviewers)
qa/requiredif this PR needs QA validation, orqa/skip-qaif it does not. Exactly one of the two is required.backport/<branch-name>label to the PR and it will automatically open a backport PR once this one is merged