fix: reduce session event query load - #2386
Merged
Merged
Conversation
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
A session notification currently recomputes whole-chat agent status and invalidates both event timelines on every frame. The chat event query also processes historical payloads through window functions before enforcing the per-speaker page limit. This change reduces that repeated work while preserving status, pagination, and authorization behavior.
MIN(created_at), window-independentturnStartedAt, ordering, and cursors.Validation
pnpm check— exit 0; existing repository diagnostics remain. Touched-file checks are clean.pnpm typecheck— all 9 Turbo tasks pass after completing the Antigravity test fixture with its requirednoteTurnStartmock. The original CI failure was a baseline fixture omission; the interface and runtime implementation remain unchanged.env -u CI_DATABASE_URL -u DATABASE_URL VITEST_MAX_FORKS=1 pnpm test— exit 0, 10/10 Turbo tasks successful (4 cached). Server: 3,507 passed; Web: 2,434 passed; Client: 2,893 passed and 7 skipped. Remaining package and CLI batches pass. This full local run was on75752f5ac; the fixture-only follow-up passes its 14 Antigravity handler tests, and the complete GitHub CI run passes onf99e588d5(lint/typecheck, Server, Client/Web, both CLI shards, and smoke checks). CodeQL also passes.EXPLAIN (ANALYZE, BUFFERS)plans. All comparisons pass for DESC 200, ASC 2, full status, and targeted status projection.Local PostgreSQL 17.10, 2 CPUs, 1 GiB RAM, 256 MiB shared buffers, 4 MiB work_mem, existing repository migrations/indexes. One warmup plus seven measured executions per version, alternating order. Median database execution times for eight agents with 12,000 events each:
In a separate fixture with an old narration and latest
error, full Q3 drops from 26.620 ms to 0.071 ms; both narration and turn-end subplans have zero execution loops in every candidate sample. All three Q1 fixtures have zero candidate temp I/O. Full-chat Q2 remains approximately unchanged; Q1's timestamp metadata seek still filters historical rows and can increase shared-buffer hits despite the lower execution time. Synthetic local results do not establish production CPU savings.Change Surface
Notes
SessionContexttest fixture so the repository typecheck gate can pass.packages/qa/cases/runtime/provider-owned-turn-status.md; live provider/browser validation was not run, and this is not deployment qualification.Adversarial verification
Reviewed head:
f99e588d591619d0ea5fd729d2a90a82d6c4c28c. No blocking regression found in the changed paths.Merge readiness is still gated by the repository's required Code Owner approval; no approval is claimed by this author-side adversarial verification.