fix(claude): preserve subagent task context snapshots#21644
Claude task frames report context usage, but the adapter drops it before clients can display it. This layer maps the latest plain-task snapshot from progress and completion frames, including completion while the parent is idle. Empty-description progress can update usage without erasing text. Both ordinary resume and buffered-wake reopening clear stale snapshots; absent completion usage preserves the last report.
Depends on the client/contract layer #21643. Rebuilt from Gigioxxβs #15446, preserving its snapshot mapping and both reset paths while adapting to current idle-completion handling. Workflow lifetime totals remain separate and never appear as context snapshots. No cumulative sum, cost or maximum-window denominator is introduced. Related #15429 remains open.
Verification: adapter definitions 176β177 (expanded cases 286β287). One rebuilt lifecycle case and an extended existing two-variant wake case fail on main, then pass here: snapshots decrease, zero is retained, missing usage preserves it, both reopen paths clear it, and idle completion is captured. An existing workflow case was extended to catch context/lifetime conflation in active and idle progress; it failed before the review fix. All nine focused adapter cases pass (278 skipped); scoped server typecheck, targeted lint/format and diff checks pass with existing diagnostics only. Two fresh whole-stack review rounds by Claude Opus 5.5 and GPT-6 Sol completed; both reviewers found no blockers in the second round. Round one caught workflow lifetime totals mislabeled as context and stale lineage context beside a newer finished child run; both were reproduced and fixed. Reviewers also ran 50 selected adapter cases successfully (237 skipped).
Headless Linux proof uses the actual adapter harness with current SDK frame types, not a live Claude invocation. Integrated web proof is in #21643. No fresh provider/account, live workflow, macOS, Windows, iOS, Android, Electron desktop or remote/relay/tunnel execution was verified; those remain human verification limits.
Implemented with GPT-6.1 Sol through the Codex harness; tests by GPT-6 Astra; adversarial reviews by Claude Opus 5.5 and GPT-6 Sol through T3 Code delegation.
Checks
- SuccessfulCodeRabbitGitHub
Review completed
- Successful
Skipped - Not affected
- SuccessfulCheckGitHub
- Skipped
- SkippedDeploy web previewGitHub
- SkippedBuild preview JS bundleGitHub
- SkippedEAS PreviewGitHub
- Successful
- Skipped
- SuccessfulNative fingerprint diffGitHub
- SkippedRelease SmokeGitHub
- SkippedTest WebGitHub
- SkippedRustGitHub
- Skipped
- SuccessfulTestGitHub
- SuccessfulBuild and TypecheckGitHub
- SkippedEAS PreviewGitHub
- Skipped
- SuccessfulLabel PR sizeGitHub
- SuccessfulLabel PR 21644GitHub
- SuccessfulPrepare PR size configGitHub
- SuccessfulCollect PR targetsGitHub
- SuccessfulTest Server 2GitHub
- SuccessfulTest Server 8GitHub
- SuccessfulTest Server 1GitHub
- SuccessfulTest Server 3GitHub
- SuccessfulTest Server 7GitHub
- SuccessfulTest Server 4GitHub
- SuccessfulTest Server 6GitHub
- SuccessfulTest Server 5GitHub
- SuccessfulLintGitHub
- CancelledNative fingerprint diffGitHub
- SuccessfulPOST to CursorGitHub
- SuccessfulChangesGitHub
Added 2 commits
Approvability
Verdict: Approved at 93c22b6
Macroscope's review found this PR approvable β This is a narrowly scoped Claude adapter bug fix that populates an existing subagent context-usage field while preserving snapshot and resume semantics. Targeted tests cover idle completion, stale snapshot clearing, decreasing values, zero values, and separation from workflow totals.
You can add or adjust custom eligibility rules. Learn more.
Thread transfer impact
β Thread transfer remains within every enforced ceiling.
βΉοΈ No successful
mainbaseline artifact is available yet. This run establishes the initial measurement.
| Provider | Metric | Main baseline | This PR | Impact | PR ceiling | |
|---|---|---|---|---|---|---|
| Codex | Total thread wire | β | 5.0 KiB | β | 6.8 KiB | β |
| Codex | Thread snapshot wire | β | 3.8 KiB | β | 4.9 KiB | β |
| Codex | Live turn WebSocket wire | β | 1.2 KiB | β | 2.0 KiB | β |
| Codex | Live turn WebSocket decoded | β | 20.9 KiB | β | 29.3 KiB | β |
| Codex | Live turn messages | β | 2 | β | 8 | β |
| Claude | Total thread wire | β | 5.0 KiB | β | 6.8 KiB | β |
| Claude | Thread snapshot wire | β | 3.8 KiB | β | 4.9 KiB | β |
| Claude | Live turn WebSocket wire | β | 1.2 KiB | β | 2.0 KiB | β |
| Claude | Live turn WebSocket decoded | β | 21.2 KiB | β | 29.3 KiB | β |
| Claude | Live turn messages | β | 2 | β | 8 | β |
Baseline: unavailable Β· PR result: 93c22b6 Β· Source CI: success
Scenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
No actionable comments were generated in the recent review. π
βΉοΈ Recent review info
βοΈ Run configuration
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
6898c358-69eb-4ae4-896b-55a33cbf74a1
π₯ Commits
Reviewing files that changed from the base of the PR and between 90df6f1425d462c234423abeab9b51783340ed0e and 93c22b64a6ef44dd0a6b714a1cbcb40e317be9d0.
π Files selected for processing: 2
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsapps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
Limit details: Youβve used all 10 included reviews currently available.
π Walkthrough
The Claude adapter now forwards usage totals from subagent progress and completion updates, clears usage when tasks are reopened, and updates workflow totals from workflow snapshots without assigning usage to workflow coordinators.
Changes: Claude usage tracking
Layer / File(s) Summary Subagent usage lifecycle
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts,apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsSubagent progress and completion updates store token and tool-use counts. Reopened tasks clear previous progress and usage. Tests cover usage updates, empty progress descriptions, and resumed tasks. Workflow usage totals
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts,apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsWorkflow completion forwards usage, and workflow snapshot tests verify updated workflow totals while coordinator usage remains undefined. Priority: β¬οΈ Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Feature
Suggested reviewers:
maria-rcks
Merge Risk: βͺ Minimal Β· up to 93c22
This change forwards subagent context usage and clears it on reopen. No actionable merge-blocking issues remain.
Pre-merge checks: Passed 4
Check name Status Explanation Title check Passed The title clearly identifies the main change: preserving Claude subagent task context snapshots. Description check Passed The description explains the problem, implementation, scope, dependencies, verification results, review coverage, and verification limits. It does not use the template headings or provide explicit mai⦠Linked Issues check Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request. Full details: Description check
Explanation
The description explains the problem, implementation, scope, dependencies, verification results, review coverage, and verification limits. It does not use the template headings or provide explicit maintainer approval, but the required information is substantially present.
β¨ Finishing Touches
π Generate docstrings
- Commit to this branch
- Create a new PR
π§ͺ Generate unit tests (beta)
- Commit to this branch
- Create a new PR
- Autofix Β· Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Usage-based review receipt
- Mode: Continue automatically
- Reviewed files: 2
- Charged: $0.50
- View usage details
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.
Validated current head 93c22b6 over #21643: current-head CI is green, with normal skipped jobs. The cancelled native fingerprint job was superseded by a successful run of the same workflow/head. Macroscope approved this head; CodeRabbit found no actionable comments, and there are no review threads. Both independent second-round full-stack reviews are clean. Provider/native/remote verification limits are explicit in the description. Ready for maintainer review; unmerged.