fix(claude): report subagent model and effort #7287
main fromrefs/pull/7287/head·opened View on GitHubProblem#
Claude file-defined subagents were seeded with the parent session's model and effort. The Agents panel therefore showed the parent settings for every subagent, and authoritative model snapshots that arrived late never reached the client.
Fix#
- leave subagent model and effort unknown unless the Agent launch explicitly overrides them
- reconcile authoritative model snapshots before or after
task.started - capture each subagent's effort through the SDK's typed
SubagentStartandSubagentStophooks - emit late identity corrections and bound pending refinements to avoid unbounded session growth
- cover parent non-inheritance, event ordering, terminal-task correction, explicit overrides, and cache eviction
Verification#
pnpm exec vp test run apps/server/src/provider/Layers/ClaudeAdapter.test.ts(74 passed)pnpm exec vp test run packages/client-runtime/src/state/subagentRuntime.test.ts(48 passed)pnpm exec vp run --filter t3 typecheck- targeted format, lint, diff, and changed-file secret checks
Fixes #7281
Model: GPT-5.6 Sol Harness: Codex in T3 Code
Note
Medium Risk Changes runtime event payloads and task identity logic in the Claude provider path; incorrect linkage could affect UI/analytics for subagents, but scope is localized to adapter event emission with heavy test coverage.
Overview
Fixes misattributed subagent model/effort in the Claude adapter: file-defined agents no longer inherit the parent session’s selection when the Agent tool omits overrides. Identity is seeded only from explicit launch input, then refined from subagent assistant snapshots and SDK SubagentStart / SubagentStop hooks (effort).
Late or early identity is handled via a bounded pending-refinement map (model + effort, cap 256): snapshots that beat task_started apply on start; snapshots or hooks that arrive after terminal rows emit task.updated corrections. Error frames with model <synthetic> are ignored. Repeated task_started on resume keeps the original Agent tool_use_id so snapshots still link correctly.
Tests add invokeSubagentEffortHook and broaden scenarios (non-inheritance, ordering, post-completion correction, resume, synthetic models, explicit overrides, eviction).
Note
Fix subagent model and effort attribution in ClaudeAdapter#
- Subagent
task.startedevents no longer infer model or effort from the parent session; they use explicit Agent-tool overrides, buffered runtime refinements, or existing task metadata. - Adds
SubagentStart/SubagentStophook callbacks to capture effort metadata, either buffering it for unregistered tasks or emittingtask.updatedcorrections for registered tasks. - Replaces the model-only pending buffer with a model-and-effort refinement buffer capped at 256 entries with FIFO eviction, keyed by a generic identity string.
- Filters the synthetic error-frame model sentinel out of subagent attribution so progress retains the real model.
- Risk:
task.startednow reports unknown model/effort when no explicit override or runtime refinement is available — checkmakeClaudeAdapterin ClaudeAdapter.ts for the fallback removal.
Summary by CodeRabbit#
- Improvements
- Improved accuracy of subagent model and effort attribution.
- File-defined agents now display their own metadata instead of inheriting values from the parent session.
- Updated task information when more authoritative metadata becomes available.
- Preserved attribution when tasks are resumed.
- Unspecified effort remains blank unless explicitly provided.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This production change alters Claude task lifecycle events and adds SDK hook-driven reconciliation for subagent model, effort, and resume identity. The scope is localized and well tested, but the new asynchronous state and event-ordering logic is complex enough to merit human review.
Not approved because:
- Monthly spending limit reached (workspace setting). Approvability relies on correctness review in order to determine eligibility
t3dotgg(GitHub profile, opens in a new tab) added labelsvouch:trusted
t3dotgg(GitHub profile, opens in a new tab) removed labelsvouch:unvouched
Merged current
mainand resolved the conflicts with #7583, which landed a narrower version of the snapshot/task_started race fix (model only, keyed by parent_tool_use_id). This branch's pending-refinement buffer subsumes that behavior, so I kept the refinement implementation and removed the now-redundantpendingTaskModelsmap.Two notes for reviewers:
- #7583's new test ("a subagent snapshot that beats task_started still wins over the seed") asserted that a subagent with no explicit effort override inherits the parent session's effort. That inheritance is exactly the misattribution this PR removes, so the assertion now expects
undefined; the model assertions (including propagation intotask.progress) are unchanged, and effort attribution is covered by the SubagentStart-hook tests here. - Everything else merged cleanly. All 82 ClaudeAdapter tests pass locally.
- #7583's new test ("a subagent snapshot that beats task_started still wins over the seed") asserted that a subagent with no explicit effort override inherits the parent session's effort. That inheritance is exactly the misattribution this PR removes, so the assertion now expects
Independent reproduction, plus one data point on
AgentInfo.modelthat may be useful here.Prevalence. I compared the label on every
local_agenttask in my local event store against themodel:each agent file declares, normalizing effort and[1m]suffixes. Over 241 tasks: 192 wrong attask_started(79%), and 35 still wrong at rest (14%) after snapshot refinement had its chance. One task recorded"model": "claude-opus-5"ontask.startedand"model": "gpt-5.6-luna"ontask.progressseconds later, for the same task id, which matches your reading that routing was correct and only the label was wrong.The 79%→14% gap is the part I found interesting: refinement does most of the work, so the residual is concentrated in children that never stream an assistant snapshot the parent sees.
One possible addition.
query.supportedAgents()returnsAgentInfo[], andAgentInfo.modelis documented as "Model alias this agent uses. If omitted, inherits the parent's model" (sdk.d.ts:97-109). It resolves off the cached initialization result rather than a per-task control request. Probing my installed CLI 2.1.245:claude (inherits) Explore (inherits) general-purpose (inherits) Plan (inherits) statusline-setup sonnet theo-composer cursor/composer-2.5That would give a launch-time value between an explicit
Agentoverride and the parent fallback, so a definition-pinned agent starts with its own alias rather than blank, while genuinely inheriting agents still fall through. It is an alias, not the resolved API id, so your snapshot path would still be the authority that corrects it.Worth noting the built-in defaults are version-sensitive: on the SDK-bundled 2.1.170
Explorereportshaiku, but on 2.1.245 it inherits. So this helps custom agents much more than stock ones, and it does not reach effort at all, sinceAgentInfohas no effort field. It may well not be worth the extra surface here.Composition. I have a separate fix for a different bug in this file, the parent context meter counting subagent tokens (#5942, PR #8453). I applied your branch and mine together on today's
main: they typecheck, and the suite passes at 85 tests once three shared tests are reconciled. Only the test file collides; the source changes are independent. Happy to rebase mine whenever yours lands.Independent Windows test report for 1f67bd5580cd182871adb6f16a73053e10bbaee0. I checked this PR because we use a local Claude SDK / hybrid-router setup and had patched the same parent-model/effort attribution problem locally.
Results#
- Unmodified PR checkout:
pnpm exec vp test run apps/server/src/provider/Layers/ClaudeAdapter.test.ts packages/client-runtime/src/state/subagentRuntime.test.ts— 133 passed, 2 files. - Additional local, synthetic matrix: parameterized the existing “uses a subagent snapshot that arrives before task.started” test across five snapshot model identifiers (
gpt-6-astra,gpt-5.6-sol,gpt-5.6-luna,claude-opus-5,claude-fable-5-1) and five hook effort strings (low,medium,high,xhigh,max). All 25 combinations passed. With that one test expanded to 25, the same two-file run passes 157 tests. pnpm exec vp run --filter t3 typecheck— passed with the matrix in place.git diff --check— passed.
The matrix emits an assistant snapshot with
parent_tool_use_id, invokes the existinginvokeSubagentEffortHook(harness, "SubagentStart", "task-model", effort)helper, then emits the matchingtask_started. It asserts thattask.startedpreserves the exact snapshot model and hook effort instead of the parent session'sclaude-opus-4-6/maxselection. The original suite also exercises unknown metadata, explicit overrides, late corrections and resumed-task identity.Boundaries#
These are adapter/client-runtime tests with synthetic SDK input, not real provider calls or a rendered sidebar check. The matrix treats model names and effort values as metadata: it does not establish that every model supports every effort, that a hybrid router applies them, or that the live CLI emits each tested hook payload. No production T3 instance was replaced or restarted, and this is not a latest-main integration/rebase test.
Environment: Windows x64, Node 25.8.0, pnpm 11.10.0, lockfile-installed SDK 0.3.170. Node is outside the repository's declared
^24.13.1range, so this is supplementary Windows evidence, not a replacement for supported-runtime CI.For our use case, preserving runtime-reported model IDs and effort is preferable to upstreaming our local frontmatter/alias display workaround. I did not find an additional issue in the tested metadata path that warrants a competing PR.
Test report prepared with Codex Desktop (local configuration: GPT-6 Astra, medium).
- Unmodified PR checkout:
Thanks for the PR. We're not taking changes to the orchestration and provider layers right now: that part of the server is being rewritten for V2, and merging into the current code would either conflict with or be thrown away by that work.
Closing for now. If this is still an issue once V2 lands, please reopen (or open a fresh PR against the new code) and we'll take a proper look.
juliusmarminge closed this
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
193f8299-2d53-4fed-b5c4-3ca7c1fac745📥 Commits
Reviewing files that changed from the base of the PR and between 6c583620ff7ad3235b135af7107c0543467eecfa and f4af34a467ee3b21ca09b6a9f76845cc3f1a1456.
📒 Files selected for processing (2)
apps/server/src/provider/Layers/ClaudeAdapter.test.tsapps/server/src/provider/Layers/ClaudeAdapter.tsLimit details: You’ve used all 10 included reviews currently available.
📝 Walkthrough
Walkthrough#
ClaudeAdapter now tracks subagent model and effort from authoritative assistant snapshots and lifecycle hooks. It buffers early metadata, updates existing tasks, preserves resumed-task identity, ignores synthetic models, and stops inheriting parent attribution for file-defined agents.
Changes#
Subagent attribution
apps/server/src/provider/Layers/ClaudeAdapter.tsapps/server/src/provider/Layers/ClaudeAdapter.tsSubagentStartandSubagentStophooks capture effort. Early values are buffered, and later changes emittask.updated.apps/server/src/provider/Layers/ClaudeAdapter.test.tsPriority: ➖ Normal
Estimated code review effort: 4 (Complex) | ~45 minutes
Severity of issue fixed: Medium
Merge Risk: ⚪ Minimal · up to
f4af3The change corrects Claude subagent model and effort attribution, with broad regression coverage and no identified merge-blocking risk.
Sequence Diagram(s)#
Suggested reviewers:
juliusmarminge,t3dotgg🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
#7281: they prevent parent metadata inheritance, refine model data from authoritative snapshots, capture effort from lifecycle hooks, preserve unknown values, ignore syntheti…#7281. No unrelated code changes are identified.✨ Finishing Touches
🧪 Generate unit tests (beta)
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.
Comment `@coderabbitai help` to get the list of available commands.