Repository navigation
fix(search): Bound the event search backfill scan - #3956
Merged
Merged
Conversation
The heartbeat backfill counted the whole backlog in one query that joined every event of the Conversations active in the last week. In production it ran for 1.5 to 4 minutes, past the 10 s run budget, so each run stored nothing. Its 60 s claim expired before the query ended, so runs overlapped. A run now walks the active Conversations newest first, one page at a time from the activity index, with a cursor in state. Each Conversation stores its missing lexemes and probes for a missing vector on the primary keys, under a 5 s statement timeout. A run holds its claim until it ends. `completed` now means a whole pass stored nothing. Co-Authored-By: BYK <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
BYK
approved these changes
Nov 21, 2026
BYK
enabled auto-merge (squash)
November 21, 2026 19:31
Contributor
|
3 screenshot changes — 3 changed · 0 added · 0 removed Review screenshots in Frameshift
|
22 tasks done
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The heartbeat backfill from #3755 stores nothing in production and loads the database.
Production, 2026-11-21 18:20–19:07 UTC,
sentry/juniorspans:limit_reached, with 0 lexemes and 0 vectors stored.count(*) filter … GROUP BY … HAVINGover every event of the Conversations active in the last week) took p50 141 s and max 256 s. The 10 s budget started before the scan, so each run passed its deadline before the first Conversation.What changes:
junior_conversations_last_activity_idx. A cursor in state lets each run continue where the last one stopped. For each Conversation, the run stores the missing lexemes with the existing per-Conversation anti-join, limited to the room left in the run. Then it checks for one event that has lexemes but no vector of the model, on the primary keys (NOT EXISTS … LIMIT 1). It embeds only when it finds one. The global count is gone.statement_timeoutat 5 s. A Conversation whose query times out is skipped, and the pass goes on. The embedding call runs outside the transaction, so it holds no connection while it waits for the model.finally. The TTL, now 5 minutes, only frees the claim of a run that died. The 10 s budget starts after the claim and covers the page reads too.completednow means a whole pass stored and skipped nothing.limit_reachedmeans the run stopped at its budget with Conversations left in the pass.pass_endedmeans a pass reached the end but stored or skipped rows, so the next run starts a new pass. Onlycompletedsets the 10-minute done marker.Telemetry: the
backlog.*attributes are gone, because a bounded run cannot count the whole backlog. New attributes onevent_search.backfill:conversation.count,skipped.count,pass.conversation.countandpass.event.count.lexeme.count,vector.countandoutcomestay. The TELEMETRY.md row already coversapp.event_search.backfill.*.Query plans: local Postgres 17 seeded with 50,800 Conversations (600 active), 403k events, 356k lexeme rows and 198k vectors:
junior_conversations_last_activity_idx, then a top-N sort of the 563 active rowsjunior_conversation_event_lexemes_pk, Nested Loop Anti Join onjunior_conversation_event_embeddings_pkjunior_conversation_event_lexemes_pk, anti join onjunior_conversation_event_embeddings_pkjunior_conversation_events_type_idx, Nested Loop Anti Join onjunior_conversation_event_lexemes_pkjunior_conversation_events, two nested-loop left joins, GroupAggregateOn the same data, with a fake embedder, 15 runs (p50 455 ms, max 2.2 s) drained the seeded backlog of about 8,000 rows. The last run, a clean pass over all 600 active Conversations, returned
completed.Voyage cost: unchanged from #3755. A run embeds at most 256 events of at most about 2,000 tokens each.
via @BYK.
--
View Session [Sentry]