Repository navigation
perf(sessions): reduce CPU work when listing session previews - #131341
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Land-ready owner review for source b10e1dee540c6760fead5fc965be14de9138b36b. The unnecessary work was owned by Best-fix verdict: this repairs the producer selector shared by single and batch reads. Adding consumer guards would leave the work intact; another cache or a database change would introduce unnecessary ownership and lifecycle complexity. Inspected the complete reader/display owner, transcript normalization, SQLite probe ordering, row and batch callers, and relevant sibling tests. Current main still has the eager selector. Production LOC: +7/-7 (net 0); tests: +112/-2 (net +110). No API, config, schema, dependency, or cache additions. Regression proof: before the production change, the four new single/batch initial/widening cases failed solely because an older nested text accessor was read three times instead of zero. Exact preview/title assertions and the 48 prior tests passed. After the change, all 52 tests pass; the older accessor is untouched. A fresh rerun against the committed source also passed all 52 tests in five files. Real SQLite reads and the canonical projector remain active in these tests. Verified local commands: node scripts/run-vitest.mjs src/gateway/session-transcript-title-reader.markdown.test.ts src/gateway/session-transcript-title-reader.placeholder.test.ts src/gateway/session-display-projection.test.ts src/gateway/session-transcript-readers.test.ts src/gateway/session-title-inbound-metadata.test.ts
node scripts/check-changed.mjs -- src/gateway/session-transcript-title-reader.ts src/gateway/session-transcript-title-reader.markdown.test.ts
git diff --checkThe complete changed gate passed, including types, formatting, lint, and architectural guards. Fresh independent prepublication autoreview returned no findings; the patch has not changed since that review. Native review artifacts validate with Proof limits: no live performance measurement or storage/RPC/cache benchmark. This is a bounded behavior-neutral selector optimization, with deterministic reader-boundary regression evidence; synthetic projection timing is not a production speedup claim. No visual output or Codex/provider runtime contract changes. Exact-head hosted CI: run 33130672002, attempt 1 completed successfully for Live merge policy inspection found no enforced independent-approval rule for this PR. The active default-branch rules enforce linear history, deletion/non-fast-forward protection, and the Actions-owned CI gate; the CI gate is satisfied. The two changed files are not restricted CODEOWNERS paths. Latest ClawSweeper status is review-started only, with no findings or Rank-up moves published; no review finding is being waived. Native landing preparation passed: |
|
Merged via squash.
|
What Problem This Solves
Resolves unnecessary Gateway CPU work when listing session previews: a readable newest reply still caused older, discarded tail messages to be projected and Markdown-flattened. The ordinary probe contains up to 20 messages, with bounded widening when newer rows are not displayable.
Why This Change Was Made
Use native reverse short-circuit traversal in the existing title-reader selector. Each visited row still passes through the same transcript normalization and canonical display projector; traversal ends as soon as the newest visible text is found. This removes the eager maps and reversed-array allocation without changing visibility, suppression, Markdown flattening, truncation, null results, title selection, probe limits, or cache behavior.
Production LOC: +7/-7 (net 0). Tests: +112/-2 (net +110). No new production API, dependency, configuration, schema, or cache. AI-assisted with Codex.
User Impact
Session lists produce the same titles and previews while avoiding unnecessary work on older messages. Hidden, tool, system, thinking-only, suppressed control replies, and Markdown that flattens to empty still fall through according to the existing display rules. There is no visual or protocol change.
Release-note context: reduce redundant transcript projection when generating session-list last-message previews.
Evidence
Four new regression cases exercise the actual single-session and batched title readers, both with immediate success and bounded widening. They instrument an older nested text accessor at the existing storage-reader seam while retaining real SQLite reads, transcript normalization, and display projection. The observed row is outside the first-user head probe.
Before the production change, all four cases failed because the older text accessor was read three times after a valid newer preview was available; the exact title/preview assertions and all 48 existing tests passed. After the change, all 52 tests pass and the older accessor is untouched.
Focused test command (five files, 52 passed):
Changed-file validation passed, including core and core-test typechecks, formatting, lint, dead-export and boundary guards, and import-cycle checks:
A local synthetic benchmark using the real display projector and 20 assistant messages (19 older 8,560-byte Markdown messages plus one short newest reply), over 100 iterations, measured 2,000 versus 100 projections and approximately 159.92 ms versus 0.25 ms. Outputs also matched empty, tool-only, hidden-last, suppressed-control, and empty-after-flattening cases. This excludes storage, RPC, and cache costs and is not a measured production speedup.
No production service or live state was accessed or changed. This is a bounded behavior-neutral optimization; deterministic reader-boundary regression proof is used rather than visual evidence. Fresh independent autoreview and exact-head CI are recorded in the landing proof.