Repository navigation
perf(workspace): index event polls and share cached stream heads - #789
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Type-filtered event polls and newest-event lookups walked workspace timestamp indexes and filtered unrelated history, producing multi-second queries. Add concurrent partial indexes for posted messages, agent controls, and tool results, and use matching constant predicates for those known prefixes while preserving existing subtype/LIKE behavior for all callers.
Share newest-event positions across workers through a one-second Redis cache. ORM event inserts, edits, and deletions invalidate it after commit using generation keys, preventing an in-flight old query from repopulating the current generation. Cached heads cannot regress a cursor behind returned messages or a valid incoming cursor. Empty streams are cached without inventing a cursor or dropping history.
Coordinate identical cache fills with token-owned Redis locks and a bounded 100 ms wait; Redis failures and contention fall through to normal queries. Authentication and visibility checks remain before response-cache access. Existing cache scopes and response freshness remain unchanged.
Validation: 50 focused polling, privacy, cursor-race, invalidation/rollback, and cache tests passed, including eight concurrent requests against disposable Redis with one fill and expiry verification. Read-only comparisons on production data returned identical IDs/payloads for old/new predicates in both sort directions. After migration 083, the six tested queries use their intended indexes and execute in 0.028–0.115 ms inside PostgreSQL (roughly 1–4 ms from the backend host). The old parameterized predicates also benefit from the new indexes. Current connector message cursors are already persisted and resumed; no client history behavior was changed. Live API/load validation will follow deployment.
Production verification: released as fd8df41. 50 focused tests passed, including real Redis concurrency. All 101 deployment health checks passed; 13 event-stream connections returned 500 during replacement. The subsequent 60-second sample contained 19,920 application requests, mean 72 ms / p95 203 ms, with zero 5xx. Event polls averaged 68 ms / p95 197 ms; CPU averaged 67%. New index query plans execute in 0.028–0.115 ms internally; production-data comparisons preserved results. Natural-traffic comparisons do not establish an additional mean-latency improvement from Redis beyond the indexes.