Skip to content

feat: let agent hooks request another turn before accepting a final answer - #6124

Open
markstuart-oai wants to merge 5 commits into
feat/simple-codexfrom
feat/settled-step-control
Open

markstuart-oai wants to merge 5 commits into
feat/simple-codexfrom
feat/settled-step-control

Conversation

@markstuart-oai

@markstuart-oai markstuart-oai commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

AgentHooks(step_policy=decide) lets an application request another turn when an agent proposes an answer too soon. For example, an application can require both a measurement and a calculation before accepting an answer.

The optional callback receives the run context and a SettledStep. Return "finish" for normal finalization or "continue" to try again with the same agent. The callback can be synchronous or asynchronous. Dynamic instructions can use updated context to guide the next turn. The existing turn limit still applies.

The policy runs once per proposed answer after approvals resolve. A handoff takes precedence. Candidates include text, parsed structured output and final tool results selected by tool_use_behavior. Agents without a policy keep their existing behavior.

Both choices run agent and run output guardrails. On continuation, the Runner skips end hooks. If validation fails or is cancelled, the Runner stops before the next model request, keeps the unchecked candidate out of session history and omits run data from SDK exceptions. When it can safely retain a completed tool call, it saves a placeholder for its output. Validated candidates remain in history as provisional output. Earlier stream events and tool effects cannot be undone.

Test plan

  • Two dependent tools, premature answers, handoff precedence and approval resume in both run modes.
  • History, SDK error details and model requests after guardrail tripwires, validator errors and cancellation.
  • All 56 step policy tests on Python 3.10.
  • Full local verification with 13,384 passing tests and 50 skips.

Checks

  • Regression tests
  • Repository verification via .agents/skills/code-change-verification/scripts/run.sh
  • Formatting, lint, mypy, Pyright and tests
  • Independent implementation review

@markstuart-oai
markstuart-oai requested review from a team, rm-openai and seratch as code owners November 21, 2026 05:54
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T23:02:17.389467Z 716221d New commits
🔒 Security Review ✅ Completed 2026-11-22T23:02:44.251088Z 716221d New commits

Security findings

Advisory findings (1)

ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseded by request changes: Python 3.10 cancellation assertion failures.

Approved after comprehensive static review and an independent second review. Reviewed text, structured and final-tool candidates; missing/empty content and refusal handling; approval/resume and handoff precedence; turn numbering and limits; provisional history; error-handler bypass; accepted-output guardrails and end hooks; and cancellation/error propagation. Completed tool effects are checkpointed before resumed policy evaluation and retained on policy failure, while parent cancellation joins the policy task without accepting a late finish. Existing behavior remains unchanged without a policy. No actionable findings.

Hosted check snapshot: {"SUCCESS": 14, "IN_PROGRESS": 9, "FAILURE": 1}. Pending checks require follow-up. Static review only; no candidate code or local tests executed.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes: supersedes my approval at this commit. I published that approval before inspecting the newly completed Python 3.10 failure. The hosted job reports six failures, all in new cancellation-message assertions: expected decision failed or local, actual empty string. Make these assertions compatible with supported Python 3.10 while retaining cancellation-type, checkpoint/session persistence and no-replay checks. No additional production correctness findings from the comprehensive static and independent reviews. Hosted CI is now terminal: 31 passed, 2 failed (the known Python 3.10 jobs), and 6 skipped. The request-changes decision remains in effect. No candidate code or local tests executed.

Comment thread tests/test_step_policy.py Resolved

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved after static re-review and an independent second review. The Python 3.10 cancellation-test finding is fixed: only cancellation-message matching is relaxed on Python versions below 3.11, while RuntimeError messages, cancellation types, suppressed final hooks, exactly-once tool effects, resumed output, and persisted session results remain checked. The incremental change is limited to these tests; no remaining actionable findings.

Hosted CI is complete: 33 passed and 2 skipped; no failures. Static review only; no candidate code or local tests executed.

Refresh follow-up (2026-11-22 21:45 UTC): rechecked current commit 28d818344a120756f0975bd605f4902e9336d813 against the prior reviewed patch and refreshed base. Added/deleted lines are unchanged; integration context remains sound. GitHub already associates this approval with the current commit. Reviewed the new guardrail comment: step_policy explicitly documents continued candidates as provisional and not subject to final-output guardrails; finish retains normal guardrail finalization. This is consistent with the existing final-output guardrail contract, so no actionable regression found. Earlier CI results describe the prior commit. Current hosted CI: {'SKIPPED': 2, 'SUCCESS': 19, 'IN_PROGRESS': 5}. Unfinished checks remain pending follow-up. Static review only; no candidate code or local tests executed.

Hosted CI follow-up (2026-11-22 22:10 UTC): current commit 28d818344a120756f0975bd605f4902e9336d813 completed with 33 successful checks and 4 skipped checks. No failures. Static review only; no local tests executed.

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 0fbeceb4f8

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 0fbeceb4f8

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: 28d818344a

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@jbeckwith-oai jbeckwith-oai left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed 716221d2011da0649f3117c27019dc5f96f341ea. Continuation candidates now run both agent and run output guardrails before persistence or the next model turn. Checked fresh and approval-resumed runs in streamed and non-streamed modes, successful continuation without end hooks/final output/completion sentinel, blocked-candidate removal, preservation of sanitized completed-tool effects, validator errors, cancellation, and held session writes. The new matrix and documentation match this stronger continuation contract. Independent static review found no actionable regressions.

Hosted CI at review: 8 successful checks, 2 skipped, 16 in progress. CI remains pending follow-up. Static review only; no candidate code or local tests executed.

Hosted CI follow-up (2026-11-22 23:25 UTC): all 33 executed checks passed; 4 checks skipped. No checks remain pending for this commit. Static review only; no candidate code or local tests executed.

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.

2 participants