Skip to content

perf(history): reduce redundant reads#1944

Merged
zerob13 merged 1 commit into
devfrom
codex/history-read-hot-path
Jul 11, 2026
Merged

perf(history): reduce redundant reads#1944
zerob13 merged 1 commit into
devfrom
codex/history-read-hot-path

Conversation

@zerob13

@zerob13 zerob13 commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

What changed

  • Add an indexed hasMessages(sessionId) query using SELECT 1 ... LIMIT 1 and use it where session orchestration only needs a boolean.
  • Treat missing file, link, and assistant-block buckets from successful bulk reads as authoritative empty results instead of issuing per-message fallback queries.
  • Preserve legacy user-row/header fallback, assistant raw-content fallback, title generation, draft reuse, and conservative error handling.
  • Keep the implementation rationale, boundaries, validation, and rollback notes in one document: docs/architecture/history-read-hot-path/spec.md.

Why

The send path was materializing full history for a boolean check. Structured history assembly also repeated single-message queries after successful bulk reads returned empty buckets. The earlier isolated baseline measured the smallest fixture moving from 8 full reads / 120 SQL statements to 7 / 105 after the existence query, then to 7 / 35 after removing the empty-bucket N+1 fallback. This PR ports only those two low-risk fixes onto the latest dev; it does not include the benchmark platform or broader audit work.

Impact

  • Less synchronous SQLite work before sending a message.
  • Query counts no longer grow per message solely because file/link/assistant bulk buckets are empty.
  • No database migration, cache, runtime flag, event bus, observer, history projection, or snapshot lifecycle change.

Validation

  • Targeted Vitest: 307 passed, 2 native-ABI skips.
  • Electron native SQLite: 3/3 passed; the existence query uses the existing session index.
  • pnpm run typecheck:node
  • pnpm run format:check
  • pnpm run i18n
  • pnpm run lint
  • git diff --check origin/dev...HEAD

Full suite, E2E, and full build were intentionally not run; the change is covered by focused contract tests and real SQLite verification.

Summary by CodeRabbit

  • Performance Improvements

    • Session history checks now determine whether messages exist without loading the full message history.
    • Reduced unnecessary reads when preparing messages for sending.
    • Missing structured message data is handled as empty content without extra lookups.
  • Tests

    • Added coverage for message-existence checks, indexed queries, and structured-content loading behavior.
  • Documentation

    • Added architecture documentation describing the history-read optimization and verification criteria.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

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

Review profile: CHILL

Plan: Pro

Run ID: e2ba4b94-87f3-4493-98ad-8fe546de8f3c

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:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/history-read-hot-path

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.

@zerob13 zerob13 marked this pull request as ready for review July 11, 2026 11:41
@zerob13 zerob13 merged commit 1a57d15 into dev Jul 11, 2026
4 checks passed
@zhangmo8 zhangmo8 deleted the codex/history-read-hot-path branch July 13, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant