Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): avoid thread-wide scans for message projection #1647

Mergedjuliusmarmingemerged 2 commits intomain fromrefs/pull/1647/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Summary

  • add keyed projected-message lookup support in the projection repository
  • stop loading every thread message row for each thread.message-sent projection update
  • extend repository coverage for the new lookup path

Stack

  • base: #1 in this stack (codex/backend-perf-queries)

Validation

  • bun run test src/persistence/Layers/ProjectionThreadMessages.test.ts src/orchestration/Layers/ProjectionPipeline.test.ts
  • bun run test src/orchestration/Layers/ProjectionSnapshotQuery.test.ts src/checkpointing/Layers/CheckpointDiffQuery.test.ts src/persistence/Layers/ProjectionThreadMessages.test.ts src/orchestration/Layers/ProjectionPipeline.test.ts src/orchestration/Layers/OrchestrationEngine.test.ts src/orchestration/Layers/CheckpointReactor.test.ts src/orchestration/Layers/ProviderRuntimeIngestion.test.ts src/orchestration/Layers/ProviderCommandReactor.test.ts
  • bun fmt
  • bun lint
  • bun typecheck (currently fails in apps/web due pre-existing @effect/atom-react / Layer.suspend errors)

Note

Medium Risk Changes the thread.message-sent projection write path to depend on a new getByMessageId query instead of scanning all messages in a thread, which could subtly affect message text/attachment merge behavior if the lookup or Option handling is incorrect.

Overview Improves message projection performance by avoiding per-event thread-wide reads when handling thread.message-sent.

Adds a keyed ProjectionThreadMessageRepository.getByMessageId API (service + SQLite implementation) and refactors the projector to fetch only the prior row for that message to compute streaming text updates and attachment retention/clearing. Tests are extended to cover the new lookup path alongside existing attachment-preservation behavior.

Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit d64edbaceb05703d0c960edfbaba3a0eeb07d2b2. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).

Note

Replace thread-wide message scan with direct lookup by messageId in projection pipeline

  • Adds getByMessageId to ProjectionThreadMessageRepository (ProjectionThreadMessages.ts), returning Option<ProjectionThreadMessage> via a targeted SQL query instead of listing all thread messages.
  • Updates the thread.message-sent handler in ProjectionPipeline.ts to use this new lookup, eliminating a full thread scan per message event.
  • Introduces a shared toProjectionThreadMessage helper to consolidate row-to-domain mapping used by both listByThreadId and getByMessageId.
Macroscope summarized d64edba.
    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

      Run ID: cc8271a2-c88d-4bae-9276-d15ac875f896

      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 `codex/backend-perf-message-projection`

      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

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

      Approvability

      Verdict: Approved

      Performance optimization that replaces a thread-wide message scan with a direct message ID lookup. The business logic is preserved and restructured using Effect's Option utilities. The PR author owns this code and tests are included.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. juliusmarminge merged this4963fcc

    5. juliusmarminge closed this

Sign in to join this conversation.