Skip to content

fix(server): identify delegated Codex threads as subagents - #36535

Closed
StiensWout wants to merge 3 commits into
pingdotgg:mainfrom
StiensWout:t3/fix-issue-36520
Closed

StiensWout wants to merge 3 commits into
pingdotgg:mainfrom
StiensWout:t3/fix-issue-36520

Conversation

@StiensWout

Copy link
Copy Markdown
Contributor

Codex children created by delegate_task had no source classification, so their MCP tool calls looked like calls from user-opened threads.

Pass the stored delegation classification through provider thread creation and send threadSource: "subagent" on Codex starts and native forks. Fresh recovery sessions use the same classification; ordinary threads keep their existing behavior. Existing native sessions are not reclassified.

Fixes #36520.

Validation: protocol tests fail before the fix and pass with it; pnpm exec vp run check:changed pingdotgg/main passes. An isolated Codex 0.169.0 app-server confirmed the start request behavior:

ordinary thread/start -> thread.threadSource: null
delegated thread/start -> thread.threadSource: "subagent"

Local Cubic found no issues; repository-specific context was unavailable for the fork.

Council review

Rounds: 1

Delegate Round 1
Claude Opus 5.5 9/10
GPT 6.1 Sol 9/10
Grok 4.7 9/10

No blocking findings. Non-blocking nit: service-side flag forwarding is verified by code review rather than a second regression test layer; tests exercise the real Codex adapter's protocol contract. The optional OpenRouter Free guest returned no substantive review.

Created with GPT 6.1 Sol in T3 Code through the Codex harness. Reviewed by Claude Opus 5.5 and Grok 4.7, with an attempted OpenRouter Free guest review.

Co-authored-by: GPT 6.1 Sol <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Grok 4.7 <[email protected]>
Co-authored-by: OpenRouter Free <[email protected]>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 14, 2026
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Nov 14, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 0c949cf

Macroscope's review found this PR approvable — Codex thread creation and forks now identify delegated threads using stored delegation metadata instead of ID prefixes. This is a narrowly scoped classification correction with no apparent material operational or customer-data risk.

You can add or adjust custom eligibility rules. Learn more.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 14, 2026
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change passes delegated-thread status through provider thread creation and forking. Codex uses the explicit status to add threadSource: "subagent" to child requests. Tests cover child creation through thread/start and thread/fork.

Changes: Codex subagent thread source

Layer / File(s) Summary
Propagate delegated-thread status
packages/provider-core/src/server/ProviderAdapter.ts, apps/server/src/orchestration-v2/ProviderTurnStartService.ts
Provider inputs add an optional isSubagent flag. Turn start derives delegated-thread status and passes it to fork and ensure calls.
Set and verify the Codex thread source
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts, packages/provider-core/src/server/IdAllocator.ts, apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
Codex runtime parameters set threadSource: "subagent" when isSubagent is true. The delegated-task thread ID uses joinId, and the prefix predicate is removed. Tests cover child requests through thread/start and thread/fork, and verify that parent requests omit the source marker.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: juliusmarminge, t3dotgg

Merge Risk: Minimal · up to 0c949

Delegated Codex child threads are now marked as subagents, and ordinary threads keep their existing behavior. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: delegated Codex threads are now identified as subagents. It follows the conventional commit format and is specific. The change set matches it: delegated-child classifi…
Description check Passed The description follows the template. It states the problem: Codex children created by delegate_task had no source classification, so their MCP tool calls looked like calls from user-opened threads. I…
Linked Issues check Passed The only linked issue, #36520, is closed. Under the assessment rules it supplies background only, so no active linked-issue coding requirements apply. For context, the reviewed head shows the delegate…
Out of Scope Changes check Passed The verified diff in ProviderTurnStartService.ts contains only isSubagent derivation and forwarding, plus the isDelegatedAppThread import. All changes trace to the single purpose of marking delegated …
Full details: Title check

Explanation

The title names the main change: delegated Codex threads are now identified as subagents. It follows the conventional commit format and is specific. The change set matches it: delegated-child classification is passed through thread creation and forking, and threadSource is set to "subagent" on Codex starts and forks.

Full details: Description check

Explanation

The description follows the template. It states the problem: Codex children created by delegate_task had no source classification, so their MCP tool calls looked like calls from user-opened threads. It describes the change, links issue #36520 for scope, and gives verification: protocol tests that fail before and pass after the fix, a check command, and an isolated Codex app-server run with observed output. It also notes the council review and the model used. The Scope section gives an issue link but does not explain why it is a bug fix rather than a feature, which is a minor gap. The template's note about agent-used models is covered by the closing line.

Full details: Linked Issues check

Explanation

The only linked issue, #36520, is closed. Under the assessment rules it supplies background only, so no active linked-issue coding requirements apply. For context, the reviewed head shows the delegated-child classification path: ProviderTurnStartService.ts (verified by diff) derives isSubagent from isDelegatedAppThread(projection.thread) and passes it to session.forkThread and each session.ensureThread call. The summary states that CodexAdapterV2.ts maps isSubagent to threadSource: "subagent" in codexThreadRuntimeParams. I could not read the CodexAdapterV2.ts diff or the test diff because their blobs were unavailable. The file read was truncated before codexThreadRuntimeParams. The mapping therefore rests on the change summary, not on a code-level check.

Full details: Out of Scope Changes check

Explanation

The verified diff in ProviderTurnStartService.ts contains only isSubagent derivation and forwarding, plus the isDelegatedAppThread import. All changes trace to the single purpose of marking delegated Codex children with threadSource "subagent". The change summary places the other changes in the same chain: the optional isSubagent fields in ProviderAdapterV2EnsureThreadInput and ProviderAdapterV2ForkThreadInput (ProviderAdapter.ts), the CodexAdapterV2.ts mapping, and the replay tests for thread/start and thread/fork. The IdAllocator.ts change removes isDelegatedTaskThread and its prefix constant, which replaces the earlier ID-based classification. This removal is related to the purpose, but I could not confirm that no other caller still imports isDelegatedTaskThread. No unrelated change was demonstrated. Several files were verified only through the summary, because the CodexAdapterV2.ts and test diffs were unavailable.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

Note

This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 080916e and 0c949cf.

Files selected for processing: 3

  • apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
  • apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
  • packages/provider-core/src/server/IdAllocator.ts

Limit details: You’ve used all 10 included reviews currently available.

@macroscopeapp
macroscopeapp Bot dismissed their stale review November 14, 2026 07:41

Dismissing prior approval to re-evaluate 080916e

macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Nov 14, 2026
Main's pingdotgg#36525 marks delegate_task children as Codex subagents by thread ID
prefix on thread/start. This branch reads the thread's stored delegation
classification instead, which also covers native forks, recovery sessions
and tasks delegated from linked environments, so the merge keeps that one
signal and drops the ID-prefix check, its helper and its duplicate test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@macroscopeapp
macroscopeapp Bot dismissed their stale review November 14, 2026 08:05

Dismissing prior approval to re-evaluate 0c949cf

@github-actions github-actions Bot added size:M 30-99 changed lines (additions + deletions). and removed size:S 10-29 changed lines (additions + deletions). labels Nov 14, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

The automated pipeline ran the reported steps in the real app without this change, and the problem did not appear. So it cannot show that this change fixes anything.

What was run on a8e60d4602, the commit before this change:

On each commit, configure the same stdio MCP logger for params._meta["x-codex-turn-metadata"]. Open a new Codex thread through the web client. Submit the same prompt asking the parent to call the logger with label parent, then use T3 delegate_task to create one new Codex child using gpt-6-luna without a worktree, have it call the same logger with label child, and wait for completion. Compare the actual logged metadata. Both base and head omitted thread_source for the parent and included thread_source: "subagent" for the child.

How: Manual real-app comparison: separate worktrees running vp run dev, fresh isolated T3 databases with T3CODE_DEV_SEED=0, synthetic project, isolated Codex homes, real Codex CLI 0.169.0 using gpt-6-luna. Web client driven through the preview browser at 1280x800 in light theme. Replay scenarios were unsuitable because this requires Codex-specific MCP behavior. Both recordings and screenshots were inspected; final screenshots matched a second capture taken at least 500 ms later. Servers, tabs, worktrees and scratch state were cleaned up.

Closing this pull request. #36520 has been asked for the missing steps; once the problem can be shown this can be reopened, or the fix built again.

@juliusmarminge juliusmarminge added takeover:blocked Takeover blocked; reason in the PR body and removed takeover:in-progress A takeover lead is working on this PR labels Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). takeover:blocked Takeover blocked; reason in the PR body vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Codex delegate_task children start with no threadSource, so their MCP servers see them as user threads

2 participants