Skip to content

perf(server): trim stale context-window rows and drop dead replay RPC - #4791

Merged
t3dotgg merged 3 commits into
mainfrom
t3code/trim-snapshot-context-window
Jul 28, 2026
Merged

perf(server): trim stale context-window rows and drop dead replay RPC#4791
t3dotgg merged 3 commits into
mainfrom
t3code/trim-snapshot-context-window

Conversation

@t3dotgg

@t3dotgg t3dotgg commented Jul 28, 2026

Copy link
Copy Markdown
Member

Thread detail snapshots shipped every context-window.updated activity a thread ever produced, while both web and mobile only read the latest row (web walks the array backwards in deriveLatestContextWindowSnapshot; mobile skips the kind entirely). On long threads that history was 24–37% of snapshot bytes.

Snapshots now retain only the newest context-window row. Live thread.activity-appended events are untouched, so streaming updates still flow and supersede the retained row client-side. Verified on cloned real data that the served row is byte-identical to the latest stored row and that deriveLatestContextWindowSnapshot returns the same result before and after.

Measured on real thread snapshots (uncompressed HTTP bytes):

thread before after
4206468e (10.6k activities) 6.85 MB 4.83 MB -29.5%
31e722de 1.83 MB 1.19 MB -35.2%
0fc086cc 1.74 MB 1.11 MB -36.5%
292eb4be 0.83 MB 0.59 MB -29.0%

This also removes the orchestration.replayEvents websocket RPC. No client in any released version calls it (checked v0.0.20 through v0.0.29 plus current web/mobile/desktop/client-runtime), and it let a single call serialize the entire event store uncompressed. The project-event enrichment helpers in ws.ts existed only for that handler and go with it.

Stacks cleanly with #4788 (HTTP gzip): these cut bytes at the source, gzip compresses what remains; on the largest thread the combined result is 6.85 MB → ~0.9 MB gzip.

Tests:

  • vp test apps/server/src/server.test.ts apps/server/test/ packages/contracts packages/client-runtime (801 passed)
  • typecheck across server, contracts, client-runtime, web, mobile

Built with Claude Fable 5 in Claude Code.

🤖 Generated with Claude Code


Note

Medium Risk
Snapshot shaping must stay equivalent to client meter logic; removing a public RPC is a breaking change for any external caller, though shipped clients reportedly never used it.

Overview
Thread detail snapshots now drop redundant context-window.updated activities before payload projection, keeping only the latest resolvable row per turn (aligned with the web client’s deriveLatestContextWindowSnapshot rules). Live thread.activity-appended events are unchanged, so streaming updates still apply on the client.

The orchestration.replayEvents WebSocket RPC is removed from contracts and the server, along with project-event repository-identity enrichment that existed only for that handler. Related server tests are deleted or trimmed.

Reviewed by Cursor Bugbot for commit 22bd560. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Trim stale context-window rows from thread snapshots and remove the replayEvents RPC

  • Adds dropStaleContextWindowActivities in ActivityPayloadProjection.ts to keep only the last valid context-window.updated activity per turn in thread snapshots, preventing malformed rows from shadowing earlier valid ones.
  • Removes the orchestration.replayEvents RPC from contracts, server routing, and auth scope — including all event-enrichment helpers that resolved repository identity.
  • Behavioral Change: thread snapshots now omit superseded context-window.updated rows; clients previously receiving multiple rows per turn will see only the latest resolvable one.

Macroscope summarized 22bd560.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c0f74c5a-fd0c-45b9-94f1-f53a8f0a76b2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch t3code/trim-snapshot-context-window

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Jul 28, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 2f6aad1. Configure here.

Comment thread apps/server/src/orchestration/ActivityPayloadProjection.ts
@macroscopeapp

macroscopeapp Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

Performance optimization that trims redundant context-window rows from snapshots (clients only read the latest value per turn) and removes unused replay RPC code. The new filtering logic is thoroughly tested to produce semantically equivalent results for clients, making this a safe optimization with dead code cleanup.

You can customize Macroscope's approvability policy. Learn more.

t3dotgg and others added 2 commits July 28, 2026 15:33
Thread detail snapshots shipped every context-window.updated activity a
thread ever produced — often a third of all snapshot bytes — while both
clients only read the latest one. Snapshots now retain just the newest
row; live activity events are untouched so streaming updates still
supersede it client-side.

Also removes the orchestration.replayEvents websocket RPC: no client in
any released version (checked back through v0.0.20) calls it, and it let
one call serialize the entire event store.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A live thread.reverted makes the client drop activities from discarded
turns. Keeping only the thread-wide latest row could leave the meter
empty when that row belonged to a reverted turn; per-turn retention
keeps a resolvable value on every surviving turn (97% of rows are
still trimmed on real data).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@t3dotgg
t3dotgg force-pushed the t3code/trim-snapshot-context-window branch from c1a8050 to 08b6d3a Compare July 28, 2026 22:34
Comment thread apps/server/src/orchestration/ActivityPayloadProjection.ts
The client's deriveLatestContextWindowSnapshot skips rows without a
finite non-negative usedTokens during its backward walk. Retention now
uses the same validity rule, so a malformed latest row passes through
untouched instead of displacing the turn's last resolvable row.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@t3dotgg
t3dotgg merged commit 5fcdefd into main Jul 28, 2026
17 checks passed
@t3dotgg
t3dotgg deleted the t3code/trim-snapshot-context-window branch July 28, 2026 22:50
github-actions Bot added a commit to omarcresp/t3code-flake that referenced this pull request Jul 29, 2026
## What's Changed
* Add OTA update checks to mobile settings by @juliusmarminge in pingdotgg/t3code#4686
* fix(mobile): threads load snapped to bottom on iOS by @t3dotgg in pingdotgg/t3code#4689
* feat: default sidebar v2 on for nightly and dev builds by @t3dotgg in pingdotgg/t3code#4491
* fix(web): 33 web UI fixes by @maxktz in pingdotgg/t3code#4700
* Make mobile Thread List v2 the default by @juliusmarminge in pingdotgg/t3code#4717
* Fix mobile showcase workflow without Clerk by @juliusmarminge in pingdotgg/t3code#4718
* Fix relay credential lookup for unlinked environments by @juliusmarminge in pingdotgg/t3code#4692
* Settle merged PR threads immediately by @t3dotgg in pingdotgg/t3code#4704
* feat(web): add maria's sidebar header artwork toggle by @maxktz in pingdotgg/t3code#4652
* feat(web): add appearance settings category by @maxktz in pingdotgg/t3code#4715
* fix(desktop): allow updater-controlled relaunch by @0x4bs3nt in pingdotgg/t3code#4721
* fix(web): prevent diff panel scroll jumping by @0x4bs3nt in pingdotgg/t3code#4724
* Link inline code file paths in chat markdown by @juliusmarminge in pingdotgg/t3code#4726
* Fix Android showcase capture and rebuild v2 queued rows by @juliusmarminge in pingdotgg/t3code#4730
* perf(server): negotiate permessage-deflate on the websocket by @t3dotgg in pingdotgg/t3code#4705
* docs: overhaul agent guidance by @t3dotgg in pingdotgg/t3code#4782
* Prevent sidebar row labels from truncating by @juliusmarminge in pingdotgg/t3code#4789
* perf(server): gzip large thread snapshots by @t3dotgg in pingdotgg/t3code#4788
* fix(web): stashed prompts now survive switching providers by @t3dotgg in pingdotgg/t3code#4787
* Fix Git ref refresh resource storms by @juliusmarminge in pingdotgg/t3code#4727
* perf(server): trim stale context-window rows and drop dead replay RPC by @t3dotgg in pingdotgg/t3code#4791
* fix(web): defer command palette filesystem navigation by @juliusmarminge in pingdotgg/t3code#2109
* fix(release): skip scripts during Vercel installs by @t3dotgg in pingdotgg/t3code#4796
* refactor(client): share filesystem browse navigation by @juliusmarminge in pingdotgg/t3code#4797
* fix(mobile): defer filesystem navigation by @juliusmarminge in pingdotgg/t3code#4799
* refactor(server): use native HTTP compression streams by @juliusmarminge in pingdotgg/t3code#4798
* Remove Connect waitlist and add GA announcement tooling by @juliusmarminge in pingdotgg/t3code#4691


**Full Changelog**: pingdotgg/t3code@v0.0.29...v0.0.30

## What's Changed
* Add OTA update checks to mobile settings by @juliusmarminge in pingdotgg/t3code#4686
* fix(mobile): threads load snapped to bottom on iOS by @t3dotgg in pingdotgg/t3code#4689
* feat: default sidebar v2 on for nightly and dev builds by @t3dotgg in pingdotgg/t3code#4491
* fix(web): 33 web UI fixes by @maxktz in pingdotgg/t3code#4700
* Make mobile Thread List v2 the default by @juliusmarminge in pingdotgg/t3code#4717
* Fix mobile showcase workflow without Clerk by @juliusmarminge in pingdotgg/t3code#4718
* Fix relay credential lookup for unlinked environments by @juliusmarminge in pingdotgg/t3code#4692
* Settle merged PR threads immediately by @t3dotgg in pingdotgg/t3code#4704
* feat(web): add maria's sidebar header artwork toggle by @maxktz in pingdotgg/t3code#4652
* feat(web): add appearance settings category by @maxktz in pingdotgg/t3code#4715
* fix(desktop): allow updater-controlled relaunch by @0x4bs3nt in pingdotgg/t3code#4721
* fix(web): prevent diff panel scroll jumping by @0x4bs3nt in pingdotgg/t3code#4724
* Link inline code file paths in chat markdown by @juliusmarminge in pingdotgg/t3code#4726
* Fix Android showcase capture and rebuild v2 queued rows by @juliusmarminge in pingdotgg/t3code#4730
* perf(server): negotiate permessage-deflate on the websocket by @t3dotgg in pingdotgg/t3code#4705
* docs: overhaul agent guidance by @t3dotgg in pingdotgg/t3code#4782
* Prevent sidebar row labels from truncating by @juliusmarminge in pingdotgg/t3code#4789
* perf(server): gzip large thread snapshots by @t3dotgg in pingdotgg/t3code#4788
* fix(web): stashed prompts now survive switching providers by @t3dotgg in pingdotgg/t3code#4787
* Fix Git ref refresh resource storms by @juliusmarminge in pingdotgg/t3code#4727
* perf(server): trim stale context-window rows and drop dead replay RPC by @t3dotgg in pingdotgg/t3code#4791
* fix(web): defer command palette filesystem navigation by @juliusmarminge in pingdotgg/t3code#2109
* fix(release): skip scripts during Vercel installs by @t3dotgg in pingdotgg/t3code#4796
* refactor(client): share filesystem browse navigation by @juliusmarminge in pingdotgg/t3code#4797
* fix(mobile): defer filesystem navigation by @juliusmarminge in pingdotgg/t3code#4799
* refactor(server): use native HTTP compression streams by @juliusmarminge in pingdotgg/t3code#4798
* Remove Connect waitlist and add GA announcement tooling by @juliusmarminge in pingdotgg/t3code#4691


**Full Changelog**: pingdotgg/t3code@v0.0.29...v0.0.30

Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.0.30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 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