Skip to content

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

Open
juliusmarminge wants to merge 2 commits into
claude-context/client-supportfrom
claude-context/claude-adapter
Open

juliusmarminge wants to merge 2 commits into
claude-context/client-supportfrom
claude-context/claude-adapter

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

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.

@juliusmarminge juliusmarminge changed the title claude context/claude adapter fix(claude): preserve subagent task context snapshots Oct 19, 2026
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Oct 19, 2026
@juliusmarminge juliusmarminge added the macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews label Oct 19, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ No successful main baseline 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.

@coderabbitai

coderabbitai Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

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 90df6f1 and 93c22b6.

📒 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 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

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.

@juliusmarminge

Copy link
Copy Markdown
Member Author

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews size:M 30-99 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant