Skip to content

refactor(server): compose managed provider policy outside the adapters - #475

Merged
tannerpolley merged 1 commit into
mainfrom
issue-436-418-step-4-isolate-provider-and-mcp
Nov 18, 2026
Merged

tannerpolley merged 1 commit into
mainfrom
issue-436-418-step-4-isolate-provider-and-mcp

Conversation

@tannerpolley

Copy link
Copy Markdown
Owner

Problem

Step 4 of #418. The Codex and Claude adapters still made managed-issue decisions themselves: they read the raw managedIssue role and modelRoles off the MCP session, chose the managed instructions, and decided that a "worker" loses native subagents. The MCP service also carried the propose_issue_change handler and three copies of the same thread-row loader.

The #469 Checker also noted that propose_issue_change told models approvals wait "on the Issues page". The fork's page is the Roadmap (/roadmap) and upstream's is /issues.

Fix

thread ──▶ IssueEligibility.managedIssueRole ──▶ t3OrchestrationPolicy (provider-core)
                                                   { sections, modelRoles, nativeSubagents }
                                                          │  set on the MCP session by ProviderSessionManager
                       ┌──────────────────────────────────┴──────────────────────────────┐
             Codex: sections → additionalContext entries        Claude: t3OrchestrationText → system append
                    nativeSubagents=false → features flags              nativeSubagents=false → disallowedTools
                                                                         query key ← sections (not model roles)
  • One composed policy on the session. McpProviderSessionConfig now carries orchestration: { sections, modelRoles, nativeSubagents } instead of the raw managedIssue and modelRoles. It is composed outside the adapters by t3OrchestrationPolicy, which is the only place a managed role decides instructions and native subagents. The role itself comes from IssueEligibility.managedIssueRole.
  • Adapters only translate. Codex maps sections to its capped additionalContext entries and nativeSubagents: false to its multi_agent feature flags. Claude maps them to its system-prompt append and disallowedTools.
  • Claude live-query reuse key. The key now includes the policy's sections in place of the role. A role change still restarts the query, and a model-roles refresh still does not.
  • Safety kept: if the settings file is unreadable, the role is still applied and the session keeps its previous model roles. Before this change, a worker kept its restriction in that case too.
  • Thinner MCP composition:
    • propose_issue_change moves into RepositoryOrchestrationMcp and reuses its assertCurrentRepositoryCaller;
    • delegate_task uses that same check;
    • ManagedIssueDelegation takes its thread loader once at construction, so the three inline copies of the loader are gone.
    • Order of checks and error messages are unchanged.
  • Wording: propose_issue_change now says approvals wait "in the issue panel". That panel holds the approval card on the Roadmap, on upstream's Issues page and in a thread's issue panel. The new wording is the same length, so the agent-context budget is unchanged.
  • Small fix this exposed: a managed Claude session's orchestration block was glued to the runtime block with no separator (…</pull_request_linking>Keep issues current…). Rendering from the sections gives it the same blank line every other block has. Ordinary sessions' text is byte-identical; the budget test, which measures them, is unchanged.

Native execution fixes are untouched. Writer routing is also untouched: Writers have no linkedIssue, so they get no managed policy, as before. No schema, event or outbox change, and nothing in issue links or backfill (#455).

Closes #436. Part of #418 (step 4 of 4).

Evidence

Tests changed or added (no new files):

Suite Case
provider/ManagedIssueDelegation.test.ts Worker policy removes Agent/Task/TeamCreate and puts the managed block in its own paragraph. This fails on main, where the block was glued on.
same New: role changes (none → root → worker) give three different live-query keys; a model-roles refresh keeps the worker's key.
same Root keeps native subagents.
ProviderSessionManager.fork.test.ts New: a thread with a linked issue gets a worker policy on its MCP session at open; an ordinary thread gets native subagents. This covers the projection → role → session chain end to end.
OrchestratorMcpService.fork.test.ts New: propose_issue_change refuses an outside client ("Issue proposals require a managed thread.") and a retired root's subtree, and never reaches the proposal service.
CodexAdapterV2.fork.test.ts, CodexDeveloperInstructions.fork.test.ts, orchestrationInstructions.fork.test.ts Moved to the new policy input. The last checks ordinary text is byte-identical.

Registration and outside clients. propose_issue_change keeps McpSchema.EnabledWhen = hiddenFromOutsideClients, and its declaration is unchanged apart from the description. McpToolAccess.toLayer refuses to build a thread-bound tool without it. The toolkit layer builds in AgentContextBudget.test.ts, toolkits/core.test.ts and McpHttpServer.test.ts, all of which pass. The existing outside-client cases in McpToolAccess.test.ts pass.

Result-read acknowledgement. The read path (pageIncludesTerminalTaskResult) is untouched. Its truncated-read and direct-read acknowledgement cases in OrchestratorMcpToolkit.integration.fork.test.ts and the base integration test pass. No new case was added, because nothing in that path changed.

Runs (agent-heavy, Node from vite-plus fallback-bin):

  • Focused set, 20 files: 1063 passed, 6 failed. One failure was my own: the new Claude assertion expected one newline before the managed block instead of two. After fixing it, a rerun of that file and the instructions fork test gave 10/10.
    • Files: ManagedIssueDelegation, CodexDeveloperInstructions (+fork), AgentContextBudget, orchestrationInstructions (+fork), Codex and Claude adapters (+fork), ProviderSessionManager (+fork), OrchestratorMcpService (+fork), OrchestratorMcpToolkit integration (+fork), toolkits/core, McpToolAccess, McpHttpServer, IssueEligibility.
    • All remaining failures are the five known 16 tests already fail on main in files check:changed rarely selects #470 cases: Claude monitor typing (fork and base), Claude roster, and Codex native subagents (worker and root). The Codex ones fail because upstream added delegate_task to Codex's direct-only tools.
  • vp run check:changed:
  • Evals (free checks only, no paid runs):
    • mcp-tool-use --context: 104 tools, tool descriptions 28473 chars, unchanged because the new wording is the same length;
    • --dry-run --cases mcp-tool-use/cases/issue-blockers.ndjson: all 4 requests built;
    • AgentContextBudget passes against the committed budget with no change.
    • No eval case added: this corrects a factual location rather than fixing an observed model failure, and a new case could not be shown failing without a paid run.

Integration pass. Isolated dev server in this worktree's .t3 with seeding off, using the free Replay provider and the in-app browser. The browser tab was hidden, so it produced no screenshot frames; I read state from the page DOM and the t3 thread show CLI instead.

Flow Result
Start thread start on Replay; the turn completes and renders.
Queued work A message sent during a running showcase turn returned delivery: "queued" and ran after it.
Question The question replay waited (--wait exit 2). Answered "Strict schemas" in the UI; the turn completed with the answer shown.
Cancel Clicked "Stop generation" during a showcase turn; the thread became interrupted.
Restart recovery Stopped the dev server by its PIDs (server 3822615, web 3822566, cwd checked) with a turn in flight and a queued follow-up. After restart the timeline shows "Cancelled because the server shut down…", then "T3 Code restarted and resumed this turn", then the queued follow-up running. The thread settled completed.
Sibling completion Not reachable with Replay. The Replay agent only replays recorded ACP frames and never calls T3's MCP tools, so it cannot start delegated children. Managed admission also requires Codex or Claude. Sibling completion and delegated-result recovery after restart for both cohort owners are covered by step 3's committed-event fixture tests in DelegatedCompletionDelivery.fork.test.ts.

The dev server was stopped by its PIDs at the end, and the browser tab was closed.

Footprint

Whole-file numstat against the plan pin 7d32075e37 (fork totals, not issue-only counts):

File Before (main a93975b795) +/− After +/−
Adapters/CodexAdapterV2.ts 529 / 124 523 / 124
Adapters/ClaudeAdapterV2.ts 1032 / 566 1030 / 566
mcp/OrchestratorMcpService.ts 455 / 225 415 / 225
orchestration-v2/Orchestrator.ts 1671 / 771 1671 / 771
EffectWorker.ts 92 / 14 92 / 14
ProjectionStore.ts 595 / 114 595 / 114

Against the newest sync base b387e3a179: Codex 477/124 → 471/124, Claude 365/44 → 363/44, MCP 373/203 → 333/203; the others are unchanged.

Residual-hunk ledger

Codex adapter. Managed-policy hunks left, all protocol translation of the composed policy:

  • buildCodexTurnStartParams takes orchestration and passes it to buildCodexAdditionalContext;
  • codexThreadRuntimeParams maps nativeSubagents: false to features.multi_agent{,_v2}: false;
  • startNativeTurn forwards session.orchestration.

Its other fork hunks are not managed policy and stay: approval prompts, plan artifacts, native-child metadata, command output, stop/release handling, Cyber Access and usage-limit failure mapping.

Claude adapter. Managed-policy hunks left, all protocol translation:

  • makeClaudeQueryOptions takes orchestration and renders it with t3OrchestrationText;
  • claudeMcpQueryOverrides maps nativeSubagents: false to disallowedTools;
  • the effective query key includes disallowedTools and the policy's sections;
  • the call site forwards the policy.

Its other fork hunks stay: native and background ownership, output paths, question, cancellation and wake attachment, monitors and goals.

OrchestratorMcpService. Issue hunks in delegate_task are one-line calls into ManagedIssueDelegation:

  • resolveIssue, startWorker, linkUnmanaged and withQueueNote;
  • assertCurrentRepositoryCaller;
  • the linkedIssue gates: the workspace is chosen by issue work, the command carries issue, and the workspace-preparation listener is skipped.

The repository methods arrive as ...repositoryMcp.methods. Its remaining fork hunks are not issue policy and stay:

Orchestrator.ts, EffectWorker.ts, ProjectionStore.ts. Unchanged by this step. What remains is listed in the step 1 to 3 ledgers: the cohort-owner accessor and the null-parentRunId branches, the typed issue-effect hooks, and the issue reads.

Outside the six tracked files:

  • ProviderSessionManager.syncModelRoles composes the session policy (span name kept);
  • IssueEligibility.managedIssueRole owns the role decision;
  • provider-core/orchestrationInstructions owns the composer and the text.

Merge Danger

Door: two-way. No migration and no persisted-format change. The MCP session config is in-memory and rebuilt on each prepare.

Blast radius:

  • the T3 instructions Codex and Claude receive: whitespace only, and only in managed Claude sessions;
  • Claude's native-subagent restriction for issue workers;
  • live-query reuse when a thread's role changes;
  • propose_issue_change routing.

Live userdata was not read or copied. The dev server ran on this worktree's own state and was stopped.

Implemented with Claude Opus 5.5 through the Claude Code harness in T3 Code.

🤖 Generated with Claude Code

The MCP session now carries one composed orchestration policy (instruction
sections, model roles, native-subagent switch). Codex and Claude only
translate it. The managed role comes from IssueEligibility, the
propose_issue_change handler moves to RepositoryOrchestrationMcp, and
ManagedIssueDelegation takes its thread loader once. The tool description
now points at the issue panel instead of the Issues page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tannerpolley
tannerpolley marked this pull request as ready for review November 18, 2026 02:16
@tannerpolley
tannerpolley merged commit d107c3f into main Nov 18, 2026
@tannerpolley
tannerpolley deleted the issue-436-418-step-4-isolate-provider-and-mcp branch November 18, 2026 02:16
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.

#418 step 4: Isolate provider and MCP managed policy and verify delegation integration

1 participant