Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): batch projector cursor writes #9671

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/9671/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Every orchestration event issued nine separate SQL statements to advance projector cursors. Ordinary tool activity paid that cost even when most projectors had nothing to change.

Batch the nine cursor rows into one upsert after all projectors finish, inside the existing transaction. Keep separate cursors, bootstrap order, and rollback behavior.

Part of the performance audit. This PR only batches cursor statements per event. It does not change thread-row updates or combine events across commands.

Verified:

  • 51 tests passed with vp test run src/orchestration/Layers/ProjectionPipeline.test.ts src/orchestration/Layers/OrchestrationEngine.test.ts from apps/server.
  • Tests cover the two-statement project projection, cursor rollback on write failure, replay after failure, and outer command-receipt rollback.
  • Targeted lint passed for all four changed TypeScript files.
  • vp run --filter t3 typecheck passed.
  • The audit's in-memory source harness now runs 100 activity commands in 700 SQL statements, including 100 cursor statements. Before this change, the same workload used 1,500 statements, including 900 cursor statements. These counts exclude transaction-control spans. The nine cursor rows still persist together.

No browsers or device tests were run, as requested.

Created with GPT-6 Astra (preview) in Codex.

Note

Batch projector cursor writes into one upsertMany call in ProjectionPipeline

  • Adds ProjectionStateRepository.upsertMany to the persistence and service layers, generating a single INSERT ... ON CONFLICT statement for multiple projection-state rows and treating empty input as a no-op.
  • Replaces per-projector cursor updates in projectEventDeferred with a single upsertMany call after all projectors run, so every cursor persists in one batch within the same transaction.
  • Updates integration tests to assert that failed projections or engine dispatches leave all cursors unchanged, and that successful retries advance every cursor.
  • Behavioral Change: cursor updates now commit or roll back atomically with the projection transaction; any code expecting individual per-projector cursor writes will see a single batched statement instead.
Macroscope summarized dbaede1.

Note

Medium Risk Changes transactional projection cursor semantics (all-or-nothing per event); incorrect batching or rollback could desync replay/bootstrap, though tests target failure and replay paths.

Overview Cuts per-event SQL overhead by advancing all orchestration projector cursors in one batched upsert instead of nine separate statements.

ProjectionStateRepository gains upsertMany, issuing a single INSERT … ON CONFLICT for multiple projection_state rows (empty input is a no-op). In projectEventDeferred, projectors still run sequentially with projector.apply, but cursor persistence moves to upsertMany after every projector finishes, still inside the existing transaction. Bootstrap keeps advancing cursors per projector via the existing path.

Tests add a two-statement projection check (projection work + batched cursors), and tighten rollback/replay coverage so failed projections or engine dispatches leave all cursors unchanged while successful retries advance them together.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit dbaede16ed9893b1a7b8bebcc9aa6151017f5e10. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at c1b1495

      Macroscope's review found this PR approvable — This is a narrowly scoped server performance optimization that batches existing projector cursor upserts without changing projection order, persisted data shape, transaction boundaries, or user-facing behavior. Tests cover statement reduction, rollback, replay, and command-level transaction handling.

      No code changes detected at dbaede1. Prior analysis still applies.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.5 KiB13.6 KiB+88 B (+0.6%)15.1 KiB✅
      CodexThread snapshot wire7.0 KiB7.0 KiB+8 B (+0.1%)7.3 KiB✅
      CodexLive turn WebSocket wire6.5 KiB6.6 KiB+80 B (+1.2%)7.8 KiB✅
      CodexLive turn WebSocket decoded57.0 KiB57.1 KiB+88 B (+0.2%)66.4 KiB✅
      CodexLive turn messages810+2 (+25.0%)21✅
      ClaudeTotal thread wire13.5 KiB13.6 KiB+54 B (+0.4%)15.1 KiB✅
      ClaudeThread snapshot wire7.0 KiB7.0 KiB0 B (0.0%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.5 KiB6.6 KiB+54 B (+0.8%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded57.8 KiB57.9 KiB+88 B (+0.1%)66.4 KiB✅
      ClaudeLive turn messages810+2 (+25.0%)21✅

      Baseline: 8e3aa32 · PR result: dbaede1 · 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: 113.8 KiB
      • Claude decoded thread snapshot: 114.5 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    4. Note

      🤖 GPT-6 Astra (preview) responding on behalf of Theo

      bugbot run

Sign in to join this conversation.