Skip to content

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

Merged
juliusmarminge merged 2 commits intomainfrom
codex/backend-perf-message-projection
Apr 1, 2026
Merged

perf(server): avoid thread-wide scans for message projection#1647
juliusmarminge merged 2 commits intomainfrom
codex/backend-perf-message-projection

Conversation

@juliusmarminge
Copy link
Copy Markdown
Member

@juliusmarminge juliusmarminge commented Apr 1, 2026

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

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 for commit d64edba. This will update automatically on new commits. Configure here.

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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

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.

@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 Apr 1, 2026
@juliusmarminge juliusmarminge force-pushed the codex/backend-perf-queries branch from 0e0bad4 to dbbf25c Compare April 1, 2026 16:37
@juliusmarminge juliusmarminge force-pushed the codex/backend-perf-message-projection branch from f07a69d to ed2220e Compare April 1, 2026 16:37
macroscopeapp[bot]
macroscopeapp bot previously approved these changes Apr 1, 2026
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 1, 2026

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.

@juliusmarminge juliusmarminge force-pushed the codex/backend-perf-message-projection branch from ed2220e to acc331e Compare April 1, 2026 16:59
@juliusmarminge juliusmarminge force-pushed the codex/backend-perf-queries branch from dbbf25c to 03d24d6 Compare April 1, 2026 16:59
@juliusmarminge juliusmarminge force-pushed the codex/backend-perf-message-projection branch from acc331e to f23d141 Compare April 1, 2026 17:06
Base automatically changed from codex/backend-perf-queries to main April 1, 2026 21:41
@macroscopeapp macroscopeapp bot dismissed their stale review April 1, 2026 21:41

Dismissing prior approval to re-evaluate f23d141

Co-authored-by: codex <codex@users.noreply.github.com>
@juliusmarminge juliusmarminge force-pushed the codex/backend-perf-message-projection branch from f23d141 to 059ff5b Compare April 1, 2026 21:41
macroscopeapp[bot]
macroscopeapp bot previously approved these changes Apr 1, 2026
Co-authored-by: codex <codex@users.noreply.github.com>
@macroscopeapp macroscopeapp bot dismissed their stale review April 1, 2026 21:45

Dismissing prior approval to re-evaluate d64edba

@juliusmarminge juliusmarminge merged commit 4963fcc into main Apr 1, 2026
12 checks passed
@juliusmarminge juliusmarminge deleted the codex/backend-perf-message-projection branch April 1, 2026 21:48
gigq pushed a commit to gigq/t3code that referenced this pull request Apr 6, 2026
Chrono-byte pushed a commit to Chrono-byte/t3code that referenced this pull request Apr 7, 2026
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