Choose delegate models and run `clai2` reviews in a separate directory

Merged
DS
1mo ago
+1265-35

This pull request was posted by codex-tui using gpt-6.1-sol on behalf of David.

No linked issue; David requested this feature.

CLAI2 delegates can select a configured model per call. A new read-only Review specialist can start in another directory with its own repository instructions and fresh history.

New public surface: SubAgents.workspace_resolver, WorkspaceResolver, DelegationWorkspaceRequest, delegate_task(working_directory=...), DelegationTask.working_directory, DelegationTasks.delegate(working_directory=...), CoderSettings.delegate_models/DelegateModel, CoderSettings.review_agent, and the PluginHost.resolve_model()/model_settings() services.

Enable Review specialist in the coder settings, then dispatch. A delegate model menu is optional and uses your own keys and models:

delegate_task(
    agent_name='Review',
    working_directory='/path/to/repository',
    task='Read changes.diff and review the affected code. Return findings with file paths.',
)

Verification: harness workspace tests, CLAI2 routing tests, sandbox boundary regression, settings compatibility, stock Review model services, startup import boundaries, API compatibility, targeted coverage, documentation parity and snippets, targeted Pyright, commit hooks, and the coder settings editor in a fresh tmux session all passed. Three fresh Luna pre-push reviews completed; subsequent remediation is locally checked under the exhausted review budget.

Existing sessions retain their defaults. Deliberate scope: CLAI2 directory selection is restricted to Review; sandbox and custom policy wrappers are rejected. Review and the model menu are separate opt-ins; no review model or tier is prescribed.

PR decisions

2026-10-27 · Approved delegate model and directory design · iter -

  • Decision: David approved per-call delegate_models menu selection, workspace_resolver plus working_directory enabled only for Review in CLAI2, a maintained chain:review-light checked for freshness before dispatch, and one PR with separate harness and CLAI2 commits.
  • Why: Reuses the existing model menu and limits directory rebinding to an isolated read-only reviewer; phase 2 is authorized.
  • Source: https://github.com/pydantic/pydantic-ai/tree/clai2-delegate-model-and-directory

2026-10-27 · Expose session model services to isolated delegates · iter -

  • Decision: PluginHost.resolve_model and model_settings forward the session model services; configured SubAgents share only model resolution and model defaults with isolated delegates.
  • Why: Review needs existing account, plugin-provider, chain and saved-settings resolution without inheriting parent tools or adding a second resolver implementation.
  • Source: https://github.com/pydantic/pydantic-ai/tree/clai2-delegate-model-and-directory

2026-10-27 · pre-push review 1 of 3 at 5964424c757650f878768a0d3dfcdb79be9d8f4b · iter -

2026-10-27 · pre-push review 1 of 3 outcome at 5964424c757650f878768a0d3dfcdb79be9d8f4b · iter -

2026-10-27 · Preserve upstream CLAI2 module renames during merge · iter -

  • Decision: Resolve the coder import through runtime.session and retain the new host services and Review directory entries alongside the renamed plugins/factories.py file-map entry.
  • Why: Upstream PR 11353 renamed private modules without aliases; retaining old imports would break the integration.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11353

2026-10-27 · pre-push review 2 of 3 at 5f361e77864168d256c1bdf9188092ff0057c3ac · iter -

2026-10-27 · pre-push review 2 of 3 outcome at 5f361e77864168d256c1bdf9188092ff0057c3ac · iter -

  • Decision: Finding: local directory rebinding can discard a sandbox policy wrapper. Reproduced with BubblewrapWorkspace; rejecting unsupported wrappers within the Review-only resolver. An unrestricted plain local parent already reads the same fixture path, so a general directory approval gate would not restore a missing boundary there.
  • Why: Candidate tree 5549ca8254118b56e0c8e1b617aaeac75fa44f94 reviewed over prior 5964424c7. Native follow-up and Veria converged on directory trust; fixture repro showed parent BubblewrapWorkspace/LocalWorkspaceBackend became LocalWorkspaceBackend and read the hidden fixture. The new wrapper-rejection test failed before the fix in both cases.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11569#discussion_r4390544816

2026-10-27 · pre-push review 3 of 3 at f706427c4e9bfeeb3e2c32e8cb02ac99856d20e8 · iter -

2026-10-27 · pre-push review 3 of 3 outcome at f706427c4e9bfeeb3e2c32e8cb02ac99856d20e8 · iter -

2026-10-27 · CI startup regression and additive feature registry · iter -

  • Decision: Keep delegate settings JSON-shaped at startup; validate and convert with locally imported ModelSettingsForm only when configured. Register SUPPORTED_FEATURES as a growing collection.
  • Why: The existing prompt-ready test reproduced an eager-import regression. API design permits additive registries; existing feature names and downgrade behavior remain intact. Three substantive local reviews are exhausted; verify this CI remediation locally and through hosted gates.
  • Source: https://github.com/pydantic/pydantic-ai/actions/runs/40533095719

2026-10-27 · Checked CI remediation at ab1b6932203e133b63b567aeee367b59394449a1 · iter -

2026-10-27 · Cover direct task-owner directory guard · iter -

  • Decision: Add a public DelegationTasks test proving a rejected resume leaves the full record unchanged; mark only intentionally unreachable test callbacks as no-cover.
  • Why: CI test jobs passed; combined coverage reported the direct owner guard and five test-only callback lines. No production behavior changes in this repair.
  • Source: https://github.com/pydantic/pydantic-ai/actions/runs/40535833502

2026-10-27 · Checked coverage repair at 411396db3d1b6867299e7ea3caf5cda854714d7b · iter -

2026-10-27 · Generalize shipped Review instructions and example · iter -

  • Decision: Remove internal pre-push workflow terminology from Review instructions and user documentation. Keep the caller-owned saved-chain freshness check in plain language.
  • Why: The specialist and reference should describe code review and directory selection for any CLAI user; no tool or configuration behavior changes.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11569#discussion_r4391194454

2026-10-27 · Separate Review from delegate model choices · iter -

  • Decision: David selected keeping the documented Coder plus SubAgents composition and adding a separate Review opt-in. review_agent defaults false; the model menu alone adds neither Review nor directory rebinding. Menu keys and model tiers remain user-defined; remove the opinionated review-light examples.
  • Why: Independent settings let any delegate use configured models without changing the roster, and let Review inherit the existing model when no menu is configured.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11569#discussion_r4391193580
  • Supersedes: Approved delegate model and directory design

2026-10-27 · Checked Review opt-in revision at 20ecd5c441376ab06dd8c020c5ee2cd1adb6bba6 · iter -

2026-10-27 · Retain documented Coder composition · iter -

  • Decision: Net-neutral skip: keep Coder(sub_agents=False) plus a separately configured SubAgents rather than adding forwarding arguments to Coder.
  • Why: Coder README explicitly recommends separate composition for a custom roster or model menu; SubAgents.combine deliberately refuses differing resolver/shared-capability policies. David confirmed this boundary. Replied with source evidence, reacted down and resolved the thread.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11569#discussion_r4391326915

2026-10-27 · Current-head CI and review closeout at 20ecd5c441376ab06dd8c020c5ee2cd1adb6bba6 · iter -

  • Decision: CI passed on the revised head. Closed fixed Review opt-in/docs threads and replied/reacted to the sandbox finding. Obtain a new clean douwebot approval on this same head.
  • Why: CI run 40540994763 succeeded, including combined coverage. Valid findings received up reactions and fix replies; the documented composition boundary received a source-backed reply and down reaction. No new compatibility regression.
  • Source: https://github.com/pydantic/pydantic-ai/actions/runs/40540994763

2026-10-27 · Use an extensible workspace request object · iter -

  • Decision: WorkspaceResolver receives the parent context and a frozen keyword-only DelegationWorkspaceRequest with agent_name and directory.
  • Why: The new unreleased callback avoids adjacent positional strings and can gain optional request fields without changing resolver function signatures; follows DynamicAgentSpec precedent.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11569#discussion_r4391566916

2026-10-27 · Retain pre-budget resume validation · iter -

  • Decision: Net-negative skip deleting the resolved-directory comparison. Share its error text with the owner guard and document why early validation is required.
  • Why: Executed a public toolset probe with max_calls=2: current guard permits the valid second generation after rejecting a changed directory; deleting only that guard consumes the budget and leaves generation 1. The owner remains responsible for direct callers and authoritative validation.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11569#discussion_r4391567832

2026-10-27 · Share the Review specialist name · iter -

  • Decision: Use REVIEW_AGENT_NAME for the Review agent definition and directory-resolver guard; keep construction in coder capability composition.
  • Why: A shared name avoids drift without a single-use factory, which repository rules discourage. Review stays a separate opt-in and receives only its declared read-only capabilities.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11569#discussion_r4391568442

2026-10-27 · Managed PR stop after second startup failure · iter -

2026-10-27 · Isolate startup timing on exact commits · iter -

  • Decision: Manager directed serial alternating startup checks, three runs each on detached20ecd5c44,98f2bd7d0,886998092 in one environment; do not change the timeout or dispatch another local pre-push review.
  • Why: The working-tree timeout had not established a regression on a commit. Quote: "If 20ecd5c44 also fails or runs within about 2 s of the timeout, treat it as load, not a regression"; quote: "If only the local commits fail reproducibly and 20ecd5c44 passes with margin, it is regression two: find which commit, report it with the evidence, and stop."
  • Source: https://github.com/pydantic/pydantic-ai/pull/11569
  • Supersedes: Managed PR stop after second startup failure

2026-10-27 · Exact-commit startup matrix clears the stop · iter -

  • Decision: Resume the managed PR lifecycle and push the two preserved commits. No second regression was reproduced; the timeout is not counted as a commit regression. Keep the timeout unchanged and local pre-push review budget at three.
  • Why: Nine serial alternating startup checks on clean detached20ecd5c44,98f2bd7d0,886998092 all passed in one environment. Test-call times were2.622–5.390 seconds; outer wall times6.975–16.831 seconds. Full commands, timings and logs are preserved in local-notes/startup-matrix-report.md and startup-matrix-results.json.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11569
  • Supersedes: Managed PR stop after second startup failure

2026-10-27 · Resume push and three-thread closeout at 886998092c87e3450d38c15b8f244d5080d46b34 · iter -

  • Decision: Pushed98f2bd7d0 and886998092 after the exact-commit startup matrix passed. Replied/reacted/resolved all three open threads and request douwebot on the new head.
  • Why: Tree a8bf49470c3387e8f6341062f82ab7a3046b3c73 was clean. Request-object finding fixed; deleting the early guard refuted by a public max_calls probe; specialist name shared with factory relocation deliberately skipped. No fourth local pre-push review.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11569

2026-10-27 · Clean hosted approval and CI retry on 886998092c87e3450d38c15b8f244d5080d46b34 · iter -

  • Decision: Douwebot approved the current head with no new comments. Retry failed CI jobs once for test_resizing_reaches_the_command TimeoutError; do not classify it as a flake before the retry result.
  • Why: Hosted run40553487661 succeeded; approval5671858105 says No blocking findings. COMMENTED reviews on current head are author replies; older bot comments retain original20ecd5c44 review IDs. CI40553059375 attempt1 failed only test on3.11 all-extras shard2/3, with terminal-resize timeout.
  • Source: https://github.com/pydantic/pydantic-ai/actions/runs/40553059375

2026-10-27 · Automated merge gates passed on 886998092c87e3450d38c15b8f244d5080d46b34 · iter -

  • Decision: CI attempt2 passed, including coverage; clean current-head douwebot approval and all resolved threads remain valid. Human approval and the manager-selected additional-review surface are pending.
  • Why: The terminal-resize timeout passed on the single unchanged-head retry, with no package-version changes. Exact-commit startup isolation passed all9 runs. Additional review and human reviewer questions were raised through the structured tool; final metadata review awaits those gates.
  • Source: https://github.com/pydantic/pydantic-ai/actions/runs/40553059375/attempts/2

2026-10-27 · David selected pydanty review-lite and owns human approval · iter -

  • Decision: Run pydanty:review-lite on886998092, then final metadata validation and monitor until merge. Human approval is arranged by David; quote: "do not request a reviewer".
  • Why: Follow the requested 2h30m budget and gh-fresh15-minute polling handshake; no pushes or thread edits while pydanty:is-working. Fetch and classify any remediation commits under the exhausted three-review budget gate.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11569

2026-10-27 · Pydanty review-lite verdict and annotation fixes · iter -

  • Decision: Pydanty requested two future imports; place each after its module docstring. Optional repeated lazy-validation and printable-guard helpers are net-neutral skip: both are short local expressions with existing central rules.
  • Why: Run df_run_c7ebf1509bb64f978dca at886998092 posted CHANGES_REQUESTED; working label cleared and fetch found no remediation commits. Four review units were incomplete. Module docstrings remain first statements; targeted tests pass.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11569#issuecomment-6450010190

2026-10-27 · Forward model services in open_stock_agent · iter -

  • Decision: Net-positive do optional suggestion3: forward open_stock_agent existing private ModelResolver and stock ModelDefaults into SessionPlugins.
  • Why: Production-wide grep found two SessionPlugins constructors and two PluginHost constructors; headless/web route through create_shell, and loader hosts already forward. Public Review test failed Unknown model before fix and passes after, including selected-model defaults. Preserve the stock entry point exclusion of saved CLI settings/chains.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11569#issuecomment-6450010190

2026-10-27 · Checked pydanty remediation at 65e8880c80958add0ddf3e325608d20d0b882946 · iter -

2026-10-27 · Pydanty remediation automated gates passed at 65e8880c80958add0ddf3e325608d20d0b882946 · iter -

  • Decision: CI and fresh clean douwebot approval passed on the remediation head; proceed with final metadata check and monitor without requesting a human reviewer.
  • Why: CI40567080609 succeeded including coverage. Douwebot40567267329 approved in review5672924116 with no new comments. All threads resolved. Human approval remains absent, and Pydanty formal CHANGES_REQUESTED at886 remains visible after its required fixes were addressed.
  • Source: https://github.com/pydantic/pydantic-ai/actions/runs/40567080609

2026-10-27 · Final metadata findings at 65e8880c8 · iter -

  • Decision: Add workspaces and model settings topic labels. Skip the requested closing issue reference: this maintainer-requested feature has no linked issue.
  • Why: The final metadata check found the two missing material topics. The founding dispatch explicitly states there is no GitHub issue, so inventing a closing reference would be inaccurate. Title, decisions mirror and verification otherwise conform.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11569

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.