Skip to content

perf(plugins): Read the newest History replacement with one query - #4231

Merged
BYK merged 1 commit into
mainfrom
feat/prompt-history-newest-replacement
Nov 24, 2026
Merged

BYK merged 1 commit into
mainfrom
feat/prompt-history-newest-replacement

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

loadHistory finds the newest compaction or handoff with the paged eventStore.query({ limit: 1 }). When one exists, that method also runs a hasOlder check as a second query, after the first query finishes. Prompt history never reads its result.

About 20% of production plugin.prompt_history.load spans run this extra query. Their p50 is about 62 ms, against about 17 ms without it, so the unused query adds about 45 ms at p50.

The event store gets loadLatestEventOfTypes(conversationId, types): one query for the newest row of the given types. EXPLAIN shows one index scan on (conversation_id, type, seq). startedAtMs and the returned contexts do not change, and the existing prompt-history scenario already covers a compaction.

Related: #3784.

via @BYK.

--

View Session [Sentry]

Prompt history found the newest compaction or handoff through the paged
event query, which also checks for older matches in a second, sequential
query that prompt history never reads. The event store now reads the
newest event of the given types directly.

Co-Authored-By: BYK <[email protected]>
@sentry-junior
sentry-junior Bot requested a review from BYK November 24, 2026 19:17
@vercel

vercel Bot commented Nov 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 24, 2026 7:17pm UTC

Request Review

@blacksmith-sh

This comment has been minimized.

@BYK
BYK merged commit d105c5a into main Nov 24, 2026
82 of 84 checks passed
@BYK
BYK deleted the feat/prompt-history-newest-replacement branch November 24, 2026 20:25

This branch was successfully deployed

1 active deployment
Preview – junior-docs — df235e33 Deployed Nov 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant