Skip to content

perf(server,client-runtime): [NBR] cut shell snapshot decoded bytes by 80% and live shell WS wire by 60% - #48467

Open
t3dotgg wants to merge 1 commit into
mainfrom
nbr/shell-opt
Open

t3dotgg wants to merge 1 commit into
mainfrom
nbr/shell-opt

Conversation

@t3dotgg

@t3dotgg t3dotgg commented Dec 3, 2026

Copy link
Copy Markdown
Member

Shell snapshots send ~55 fields per thread row including dozens of null/false/[] defaults and repeated IDs/paths (~1.5 KB/row, 43.4 KB decoded for 27 rows), initial WebSocket shell snapshots emit all projects twice when repository identities are already resolved, and live ShellStream updates broadcast the full ~1.5 KB thread shell row on every tool tick, thread.visit, and 5s cursor-floor heartbeat.

This adds opt-in compact shell wire encoding and sparse ShellStream deltas transparently at the client-runtime boundary across web, desktop, and mobile while keeping legacy clients 100% compatible:

  • Compact shell wire codec + ID table (withCompactShellWire): Omits null/scalar/empty-array defaults and derived fields (providerInstanceId, visibleItemCount, updatedAt, default lineage), and applies 2-pass frequency-gated string interning (ids) across shell snapshots, getOlderSettledThreads, getThreadFamily, and getArchivedShellSnapshot.
  • Sparse ShellStream deltas (cursor + thread.patched): Replaces 5s cursor-floor resends with a ~30 B cursor frame and small per-thread updates with sparse thread.patched diffs (bounded 2,048-entry LRU, safe snapshot reload on missing target), and fixes duplicate initial WS projects emission.

Measured transferBudgetV2 Wire Reductions

Scenario Metric Before (main) After (nbr/shell-opt) Reduction
fleet shell snapshot (27 rows) HTTP decoded 43,426 B 8,532 B -80.4%
fleet shell snapshot (27 rows) HTTP gzip wire 2,067 B 1,250 B -39.5%
measured turn, shell WS wire 665 B 272 B -59.1%
reconnect, shell (replay) WS wire 894 B 326 B -63.5%

Verification

  • vp run check:changed: pass (format, lint, knip, graphql, typecheck across 39 packages, 10 test files / 147 tests including orchestrationV2ShellWire.test.ts, ShellStream.test.ts, http.test.ts, shellReducer.test.ts, and transferBudgetV2.integration.test.ts).

Created with Gemini 4 Neon in Antigravity.

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:XXL 1,000+ changed lines (additions + deletions). labels Dec 3, 2026
@macroscopeapp

macroscopeapp Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 0ab2606

Macroscope's review found this PR approvable — Optimizes shell snapshots and live updates through compact encoding and sparse patches while preserving legacy responses for clients that do not opt in. The changes remain confined to transport and client state, with full-row fallback and snapshot recovery safeguards.

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

@blacksmith-sh

blacksmith-sh Bot commented Dec 3, 2026

Copy link
Copy Markdown

Found 2 test failures on Blacksmith runners:

Failures

Test View Logs
src/state/shell-sync.test.ts/environment shell cold start >
buffers opening-session snapshots until initialConfig validates environmentId and disc
ards mismatches
View Logs
src/state/shell-sync.test.ts/environment shell cold start >
takes a socket snapshot when the early HTTP load stalls without a usable cursor
View Logs

Fix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 1 1 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 1 1 0 (0.0%) 8 ✅

Other scenarios

4 of 64 scenario measurements changed or failed.

Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex fleet shell snapshot HTTP decoded 42.4 KiB 8.3 KiB −34.1 KiB (−80.4%) 53.7 KiB ✅
Codex stale shell reload HTTP decoded 42.4 KiB 8.3 KiB −34.1 KiB (−80.4%) 53.7 KiB ✅
Claude fleet shell snapshot HTTP decoded 43.0 KiB 8.3 KiB −34.6 KiB (−80.6%) 53.7 KiB ✅
Claude stale shell reload HTTP decoded 43.0 KiB 8.3 KiB −34.6 KiB (−80.6%) 53.7 KiB ✅
All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex short turn resume WebSocket decoded 10.5 KiB 10.5 KiB 0 B (0.0%) 12.7 KiB ✅
Codex short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn running, cold open HTTP decoded 281.7 KiB 281.7 KiB 0 B (0.0%) 302.7 KiB ✅
Codex long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Codex long turn running, history page HTTP decoded 92.5 KiB 92.5 KiB 0 B (0.0%) 107.4 KiB ✅
Codex long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Codex long turn finished, cold open HTTP decoded 381.5 KiB 381.5 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, socket cold open WebSocket decoded 381.6 KiB 381.6 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, work page HTTP decoded 78.3 KiB 78.3 KiB 0 B (0.0%) 200.2 KiB ✅
Codex long turn finished, work page rows 75 75 0 (0.0%) 150 ✅
Codex idle thread resume WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell snapshot HTTP decoded 42.4 KiB 8.3 KiB −34.1 KiB (−80.4%) 53.7 KiB ✅
Codex fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Codex fleet shell subscribe WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Codex fleet shell resume check rows 0 0 0 0 ✅
Codex stale shell reload HTTP decoded 42.4 KiB 8.3 KiB −34.1 KiB (−80.4%) 53.7 KiB ✅
Codex stale shell reload rows 27 27 0 (0.0%) 27 ✅
Codex stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Codex stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex stale todo list cold open HTTP decoded 72.4 KiB 72.4 KiB 0 B (0.0%) 83.0 KiB ✅
Codex stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Codex stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅
Claude short turn resume WebSocket decoded 10.6 KiB 10.6 KiB 0 B (0.0%) 12.7 KiB ✅
Claude short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn running, cold open HTTP decoded 283.3 KiB 283.3 KiB 0 B (0.0%) 302.7 KiB ✅
Claude long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Claude long turn running, history page HTTP decoded 93.4 KiB 93.4 KiB 0 B (0.0%) 107.4 KiB ✅
Claude long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Claude long turn finished, cold open HTTP decoded 384.2 KiB 384.2 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, socket cold open WebSocket decoded 384.3 KiB 384.3 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, work page HTTP decoded 79.2 KiB 79.2 KiB 0 B (0.0%) 200.2 KiB ✅
Claude long turn finished, work page rows 75 75 0 (0.0%) 150 ✅
Claude idle thread resume WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell snapshot HTTP decoded 43.0 KiB 8.3 KiB −34.6 KiB (−80.6%) 53.7 KiB ✅
Claude fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Claude fleet shell subscribe WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Claude fleet shell resume check rows 0 0 0 0 ✅
Claude stale shell reload HTTP decoded 43.0 KiB 8.3 KiB −34.6 KiB (−80.6%) 53.7 KiB ✅
Claude stale shell reload rows 27 27 0 (0.0%) 27 ✅
Claude stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Claude stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude stale todo list cold open HTTP decoded 73.4 KiB 73.4 KiB 0 B (0.0%) 83.0 KiB ✅
Claude stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Claude stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅

Baseline: e00ef1f · PR result: 0ab2606 · Source CI: failure

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 Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

This change adds compact shell snapshot encoding with optional ID interning and adds cursor and sparse thread-patch events to shell streams. Server endpoints and client requests opt into compact responses. The client decodes compact snapshots, applies stream deltas, and requests a fresh snapshot when a patch target is missing.

Changes: Compact Shell Wire and Stream Deltas

Layer / File(s) Summary
Compact encoding and ID interning
packages/contracts/src/orchestrationV2ShellWire.ts
A schema wrapper omits configured shell defaults and interns repeated snapshot strings. Decoding restores omitted values and resolves valid ID-table indexes.
Shell wire schemas and codec validation
packages/contracts/src/orchestrationV2.ts, packages/contracts/src/orchestrationV2ShellWire.test.ts
Shell schemas add compact-format options and markers, plus cursor and sparse thread-patch stream variants. Tests cover encoding, decoding, size limits, and invalid indexes.
Compact snapshot endpoints
apps/server/src/orchestration-v2/http.ts, apps/server/src/orchestration-v2/http.test.ts, apps/server/src/ws.ts
HTTP and WebSocket snapshot responses add compact-format markers when requested. Archived-shell, thread-family, and older-settled responses accept the corresponding options.
Shell stream deltas and enrichment
apps/server/src/orchestration-v2/ShellStream.ts, apps/server/src/orchestration-v2/ShellStream.test.ts, apps/server/src/ws.ts, apps/server/integration/transferBudgetV2.integration.test.ts
The server emits eligible sparse patches and cursor events, filters enrichment snapshots, and retains full updates for unsupported cases. Tests cover stream behavior and reconstruct shell state from updates and patches.
Client requests and shell state updates
packages/client-runtime/src/state/*, packages/contracts/src/environmentHttp.ts
Client requests enable compact responses. Snapshot decoding handles deferred pull-request links, and shell reducers apply cursor and patch events and report missing patch targets.

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant EnvironmentShellState
  participant subscribeOrchestrationV2Shell
  participant applyShellStreamWireOptions
  participant applyShellStreamEventsWithStatus
  EnvironmentShellState->>subscribeOrchestrationV2Shell: compact and delta subscription options
  subscribeOrchestrationV2Shell->>applyShellStreamWireOptions: stream and wire options
  applyShellStreamWireOptions-->>EnvironmentShellState: compact snapshots, cursor events, and thread patches
  EnvironmentShellState->>applyShellStreamEventsWithStatus: apply stream events
  applyShellStreamEventsWithStatus-->>EnvironmentShellState: updated snapshot and missing-target status
Loading

Suggested reviewers: juliusmarminge, saphid

Merge Risk: Minimal · up to 0ab26

This change shrinks shell snapshot and live WebSocket payloads through opt-in compact encoding and sparse patches. Legacy clients keep full updates, and the client reloads a snapshot when a patch target is missing. No concrete merge-blocking defect was established.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two main outcomes: smaller shell snapshot decoded bytes and smaller live shell WebSocket wire size. The changeset adds compact shell wire encoding, ID interning, and sparse ShellSt…
Description check Passed The description follows the template's main sections. It covers the problem (oversized shell rows, duplicate initial WS projects, full-row live updates), the change (compact wire codec, ID table, spar…
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: Title check

Explanation

The title names the two main outcomes: smaller shell snapshot decoded bytes and smaller live shell WebSocket wire size. The changeset adds compact shell wire encoding, ID interning, and sparse ShellStream deltas that serve those goals, so the title matches the main change. It uses the conventional commit form and is a single sentence. It is somewhat dense with the [NBR] tag and specific percentages, which are the author's reported measurements.

Full details: Description check

Explanation

The description follows the template's main sections. It covers the problem (oversized shell rows, duplicate initial WS projects, full-row live updates), the change (compact wire codec, ID table, sparse ShellStream deltas, duplicate-project fix), and verification (a measurement table and a check:changed run with named test files). The Scope section is missing. It does not link an issue or state that the work is a bug fix rather than a feature. The perf work also reads as a feature-level change, so the scope justification is needed. The description also does not state what could not be checked. The template asks for that, and the author does not say whether any manual checks were run against legacy clients, even though the description claims full compatibility.

Resolution

Add a Scope section that links the issue showing the bug or the maintainer request. Explain why the duplicate project emission and the payload size are bugs and not feature work. State any checks that were not run, such as manual testing against legacy clients or the web, desktop, and mobile apps. Consider whether the Verification section should mention the 'Created with' line as the template requires the model and harness name, which it does include.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e00ef1f and 0ab2606.

Files selected for processing: 19

  • apps/server/integration/transferBudgetV2.integration.test.ts
  • apps/server/src/orchestration-v2/ShellStream.test.ts
  • apps/server/src/orchestration-v2/ShellStream.ts
  • apps/server/src/orchestration-v2/http.test.ts
  • apps/server/src/orchestration-v2/http.ts
  • apps/server/src/ws.ts
  • packages/client-runtime/src/state/olderSettledThreads.test.ts
  • packages/client-runtime/src/state/olderSettledThreads.ts
  • packages/client-runtime/src/state/orchestration.ts
  • packages/client-runtime/src/state/shell.ts
  • packages/client-runtime/src/state/shellPullRequests.ts
  • packages/client-runtime/src/state/shellReducer.test.ts
  • packages/client-runtime/src/state/shellReducer.ts
  • packages/client-runtime/src/state/shellSnapshotHttp.ts
  • packages/client-runtime/src/state/threadFamilies.ts
  • packages/contracts/src/environmentHttp.ts
  • packages/contracts/src/orchestrationV2.ts
  • packages/contracts/src/orchestrationV2ShellWire.test.ts
  • packages/contracts/src/orchestrationV2ShellWire.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

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

size:XXL 1,000+ changed lines (additions + deletions). 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.

1 participant