Skip to content

Add per-turn model selection to Runner - #6207

Merged
markstuart-oai merged 3 commits into
feat/simple-codexfrom
markstuart/sdk-controls-01-model-selection
Nov 24, 2026
Merged

markstuart-oai merged 3 commits into
feat/simple-codexfrom
markstuart/sdk-controls-01-model-selection

Conversation

@markstuart-oai

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

Copy link
Copy Markdown
Contributor

Why

When an agent starts running tests, the app doesn't know whether they'll fail. It should be able to use its usual model for routine work and switch after a failure without losing the test result.

Summary

RunConfig.model_selector lets Runner choose a model for each new request, including after tools and handoffs. The test tool sets the run context's failed flag. The selector returns review_model.

def select_model(turn):
    if turn.context is not None and turn.context.failed:
        return review_model
    return None

Pass run_config={"model_selector": select_model} to Runner. Returning None uses the agent's configured model. See the complete example.

Awaited and streamed runs select within one provider. Retries reuse the choice. Fixed overrides bypass selection. Sandbox agents need a fixed model. The selector runs once per Runner request, never for internal Codex model calls. A native child may use its own model.

Parent branch feat/simple-codex.

Test plan

Tests passed for tools, handoffs, retries, provider restrictions, guardrails and Codex approval recovery in both Runner modes.

Issue number

None.

Checks

  • I've added new tests, if relevant
  • I've run .agents/skills/code-change-verification/scripts/run.sh
  • I've confirmed all verification steps pass
  • If using Codex, I've run /review before submitting this PR

@markstuart-oai
markstuart-oai requested review from a team, rm-openai and seratch as code owners November 24, 2026 06:56
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 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-24T18:35:50.299073Z 2ec9040 New commits
🔒 Security Review ✅ Completed 2026-11-24T18:37:07.296607Z 2ec9040 New commits
ℹ️ 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.

Request changes for the missing release-contract policy entry described inline. The hosted prospective-release-contract job confirms that the new ModelSelector export prevents contract promotion.

Reviewed model selection, provider-route identity, fixed-model bypass, implicit settings, retry stability, handoffs/approval recovery, sandbox restrictions and redaction, with an independent second review. No additional actionable functional findings.

Hosted CI: 7 passed, 3 skipped, 13 running and 1 failed. Pending checks remain tracked. Static review only; no candidate code or local tests executed.

Additional independently verified blocker: #6207 (comment). My initial functional review missed that output-guardrail/server-history validation resolves the configured adapter, while dispatch uses the selected adapter. A same-provider selector can change Chat Completions to Responses after the former receives an exemption, allowing rejected output to enter server-managed history. Validate the actual resolved adapter before dispatch in both streaming and buffered paths, without calling the selector twice. Referencing the existing finding rather than duplicating inline feedback. Static inspection only.

Comment thread src/agents/__init__.py Resolved

@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 Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 797cc542af

ℹ️ 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".

Comment thread src/agents/run_internal/run_loop.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.

Re-reviewed all seven changed files at 4d93a4a with an independent second static review. Both prior blockers are addressed: actual resolved adapters now receive server-history/output-guardrail validation in streaming and buffered paths before dispatch, without re-invoking the selector; ModelSelector is registered in the release policy with narrowly supported Awaitable serialization and an exact contract-shape assertion. Nested MultiProvider routing now checks the leaf provider while preserving aliases to the same provider. No additional actionable findings.

Fresh hosted CI remains in progress (latest inspected snapshot: 1 passed, 16 running); this approval does not claim CI completion. Static review only; no local code or tests executed.

Hosted CI update (2026-11-24 07:42 UTC): 33 passed, 2 skipped; no checks remain pending in the current rollup. Approval is unchanged. No local tests were run.

@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 of the base merge and an independent review. All 14 feature patches preserve the prior approved additions/deletions. Checked integration with final-output feedback, tool-result transforms, native MCP exports and the updated RunConfig: model selection remains per request, retries reuse the selection, actual-adapter guardrail validation occurs before dispatch, and native approval recovery retains its selected model. Existing alias-contract and guardrail findings remain addressed; no actionable regression found.

Hosted CI at review: 9 passed and 15 running, with no reported failures. Pending checks remain tracked. No candidate code or local tests executed.

CI follow-up (2026-11-24 19:00 UTC): all hosted checks for the reviewed commit are terminal: 33 succeeded and 2 were skipped, with no failures. This includes the completed Codex preview-wheel verification. The PR merged at the reviewed commit. No local tests were run.

@markstuart-oai
markstuart-oai merged commit 989749a into feat/simple-codex Nov 24, 2026
26 checks passed
@markstuart-oai
markstuart-oai deleted the markstuart/sdk-controls-01-model-selection branch November 24, 2026 18:46
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