Repository navigation
Use blocks_pkey for failed parent answer lookups in the chat feed - #1354
Merged
Merged
Conversation
Comparing answer.id::text to the stored blockId forced a sequential scan of blocks once per parent-handled ask, which took 3-7s per feed load on a host with ~28k blocks. Compare as uuid instead, casting only canonical lowercase ids so malformed values still match nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
On a host with ~28k blocks, chat streams took 2–7 s to load. The feed's open-input lookup (
FAILED_PARENT_INPUT_SQLinapps/server/src/chat/feed.ts, used bylistOpenInputsandlistBlockEntries) comparedanswer.id::textto the storedblockId. Postgres can't useblocks_pkeyfor that comparison, so it scanned every block once per parent-handled ask. One measured stream did 1,046 inner seq scans and took 6.94 s; that query accounted for 4.1 s of a 4.17 scomposeStreamFeedcall.Fix
Compare
answer.idas a uuid. Only canonical lowercase ids are cast, which is the same set the text comparison could match, so a malformedblockIdstill matches nothing instead of failing the query.Validation
blockIddoesn't break the feed, and withenable_seqscan = offthe plan usesblocks_pkey on blocks answer. The test fails when the old::textcomparison is restored.pnpm run check, plusvitestonstream-service.test.tsandtest/chat: 299 passed.🤖 Generated with Claude Code