fix(claude): preserve subagent task context snapshots#21644

open2
claude-context/client-support
claude-context/claude-adapter
opened5d agobyJJulius Marminge
View on GitHubTwo-way sync enabledPR last imported 4h ago

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

All checks passed

Added 2 commits

  • fix(claude): preserve subagent task context snapshots5befc57
  • fix(claude): keep workflow totals separate from task context93c22b6
Synced from GitHub

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.

Synced from GitHub

Thread transfer impact

βœ… Thread transfer remains within every enforced ceiling.

ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

ProviderMetricMain baselineThis PRImpactPR ceiling
CodexTotal thread wireβ€”5.0 KiBβ€”6.8 KiBβœ…
CodexThread snapshot wireβ€”3.8 KiBβ€”4.9 KiBβœ…
CodexLive turn WebSocket wireβ€”1.2 KiBβ€”2.0 KiBβœ…
CodexLive turn WebSocket decodedβ€”20.9 KiBβ€”29.3 KiBβœ…
CodexLive turn messagesβ€”2β€”8βœ…
ClaudeTotal thread wireβ€”5.0 KiBβ€”6.8 KiBβœ…
ClaudeThread snapshot wireβ€”3.8 KiBβ€”4.9 KiBβœ…
ClaudeLive turn WebSocket wireβ€”1.2 KiBβ€”2.0 KiBβœ…
ClaudeLive turn WebSocket decodedβ€”21.2 KiBβ€”29.3 KiBβœ…
ClaudeLive 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.

Synced from GitHub

Review in Change Stack β†’

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.ts
  • apps/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.ts
Subagent 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.ts
Workflow 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 nameStatusExplanation
Title checkPassedThe title clearly identifies the main change: preserving Claude subagent task context snapshots.
Description checkPassedThe 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 checkPassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes checkPassedCheck 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

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.