Skip to content
Source
Sign inSign up
pingdotgg/t3code

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

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/4791/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

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):

threadbeforeafter
4206468e (10.6k activities)6.85 MB4.83 MB-29.5%
31e722de1.83 MB1.19 MB-35.2%
0fc086cc1.74 MB1.11 MB-36.5%
292eb4be0.83 MB0.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](https://cursor.com/bugbot) for commit 22bd5607166e914d3c7c0d2b420d194546d9c51d. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

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.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      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.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. 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](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 2f6aad199dbbaaac71cc70ab116f2cfef255a755. Configure [here](https://www.cursor.com/dashboard/bugbot).
    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      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](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).

Sign in to join this conversation.