Repository navigation
perf: avoid unused session lifecycle read snapshots - #169748
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR makes lifecycle timestamp reads opt-in while preserving coherent snapshots for restart-safe chat admission. Example: Read metadata for agent:main:qualified-lifecycle.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it provides a focused, maintainer-directed optimization absent from current main, with no introduced correctness or security defect found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway session readers and native model preparation request worker-owned entry and membership facts; restart-safe chat admission additionally consumes lifecycle timestamps for reset freshness. flowchart TD
A[Metadata and observer readers] --> B[Qualified session reader]
C[Chat admission] --> B
B --> D[Worker entry facts]
D --> E[Atomic entry and membership query]
B --> F[Requested lifecycle snapshot]
F --> G[Entry and transcript header]
H[Native model preparation] --> D
Technical reviewBest possible solution: Retain the caller-level optimization and the existing coherent lifecycle snapshot wherever reset freshness requires it. Do we have a high-confidence way to reproduce the issue? Current-main source shows unused lifecycle requests selecting the deferred snapshot path; the reported workload attributes a matching transaction reduction to the candidate. Is this the best way to solve the issue? The patch reuses the existing atomic query and worker owner, preserves the actual lifecycle consumer, and introduces no competing cache or public setting. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 23a6da89a61a. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +4, Tests +70, Docs +7. Total +81 across 9 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed October 12, 2026, 5:33 AM ET / 09:33 UTC (Revision 3). |
Make qualified Gateway lifecycle timestamps opt-in and remove unused native model lifecycle reads. Preserve the coherent entry/header snapshot for restart-safe chat admission and all membership/source-authority checks. Reuses the existing atomic entry-facts read, removing one BEGIN/COMMIT pair per warmed turn. No schema, permissions, or update behavior changes. Regression covers current entry and membership facts after in-process writes and explicit legacy lifecycle timestamp recovery.
What Problem This Solves
Gateway metadata and native model ownership reads request lifecycle timestamps that their consumers never use. That request forces a deferred read transaction even when the existing entry-facts query already returns an atomic result.
User Impact
Internal SQL reduction with unchanged session data, membership authorization, reset behavior, and user-facing contracts. No schema migration, update step, or configuration change.
Why This Change Was Made
Make lifecycle timestamps opt-in for qualified Gateway reads, remove unused lifecycle requests from native model preparation, and explicitly retain them for restart-safe chat admission. This reuses the existing single-query/retained-facts path; it adds no transaction helper, cache, SQL, or engine branch. PostgreSQL single-statement reads therefore remain plain queries.
Removed work and accepted edge case: metadata/observer/model ownership consumers no longer obtain unused lifecycle timestamps. A concurrent lifecycle-only change cannot affect their result because these consumers do not use those timestamps. Reset/admission consumers still request a coherent entry/header snapshot. Membership and live source-authority checks remain intact.
Evidence
One live baseline/candidate pair uses the shared SQL workload with transaction attribution, synthetic provider and isolated state. The task copy only restores census instrumentation, moves scratch to external storage, and disables evidence archives; workload and assertions are unchanged.
Measured base
9c54108f9f20a39211a5aba3a2bd2d6f8393d1a5against patch headbbbe89debcbda75097ca3e55efd041717cd1612b, before integrating main's static fixes. Values below are aggregate counts divided by 10 warmed turns (one pair, not repeated-sample medians).The deterministic saving is one redundant read envelope per warmed turn: 2 SQL statements removed, with no added request. The complete exact-entry family saves 22 statements and 2 requests across the sample; across the entire workload it changes from 277 statements / 124 requests to 245 / 122.
Raw totals rose because the candidate workload took 532.6 seconds on a heavily contended host versus 103.5 seconds for the baseline, allowing additional periodic work. For example, warmed
database.domain.publishchanges from 389 statements / 92 requests to 674 / 175, and transcript exports from 20 / 4 to 85 / 17. Additional cleanup/health/maintenance families also enter the warmed phase. All four candidate MAIN statements are existing periodic GitHub OAuth record reads fromgithub-oauth-lifecycle.ts:reconcileRecords; the changed entry-read owner adds none. Whole-workload totals are 9,337 → 10,072 statements and 1,687 → 1,963 requests. This is owner-attributed SQL proof, not a latency improvement claim.Gateway-main-thread T1 call sites in the changed area: 0 → 0. Final integrated-head CI's repository-wide worker ratchet is 544 → 544, and its dialect ratchet passes. No database call or synchronous fallback was added.
All 13 chat turns, child execution, cron, compaction, and clean shutdown succeeded. The final driver assertion reported one separate control-plane failure:
mentions.dismissreturnedUNAVAILABLEafter the unchanged mention Inbox refresh owner logged failures. This is a recorded validation gap; the warmed-turn measurements are complete. An earlier attempt failed during the connection handshake before any turn and is excluded. No SQL execution errors or transaction pairing anomalies were observed.The storage regression reads qualified entry/membership facts, commits changed values, verifies the next read sees both, and verifies explicit lifecycle reads recover the legacy transcript-header timestamp. Existing ordered-read and lifecycle tests remain applicable. Local oxfmt, focused type-aware oxlint, and diff checks pass; focused owner tests and broad static checks run in PR CI under the requested relaxed testing workflow. Codex autoreview: scoped clean, one round, no actionable findings. No SDK surface or update/Doctor/schema/plugin-loading/service lifecycle change, so no SDK diff or published-driver update cell is needed.
Complete warmed deferred-read census
Counts are per warmed turn (10-turn sample). Each transaction has one deferred BEGIN and one matching COMMIT.
session-row-facts—session-entry-read.worker.ts:readSessionRowDatabaseFactssession-row-backfill—session-accessor.sqlite-active-events.ts:readSessionTranscriptBoundedMessageTailPagesession-exact-entries—session-entry-read.worker.ts:readExactSessionEntriesWithLifecyclesession.entry.read—session-entry-cohort.worker.ts:readSessionEntryCohortsession-pending-input-history—session-pending-input-history.kernel.ts:readPendingInputHistoryInDatabasesession-activity-summary-source—session-transcript.worker.ts:readRequesttranscript-anchors—session-transcript-anchor-read.kernel.ts:readSessionTranscriptAnchorFactsInDatabasesession-entryexport —session-accessor.sqlite-read.ts:readTranscriptExportSnapshotReadOnlySynctranscript-hydration—session-accessor.sqlite-active-context.ts:readSessionTranscriptBoundedActiveContextCoresession-entry-list,agentDatabaseDeletion.snapshot, andworkers.placementRecoveryCandidates, each 0.2.The retained envelopes protect related rows within the owning process. No retained envelope relies on an unsupported external writer. Size-limiting SQL JSON projections are unchanged.
LOC: production +9/−5, test +70/−0, docs +7/−0. No changelog edit: release-note context is retained here.
An earlier CI run hit an inherited type-suppression inventory expectation and the built-CLI lifecycle failure also recorded in main run 38220958692. The inventory fix was integrated, and both jobs pass on the final head.
Integrated main through
fdbe95f5d1d68c160d8d281560b7ea43894bf00dwithout conflicts to include the inventory fix (64f11ced232c7) and existing Knip export cleanup (f0a14bf986e60). The measured owner implementation is unchanged by integration. Final integrated-head CI has green production types, all test-type stripes, core/extension lint, source contracts/export checks, Madge architecture, guards, and T1/dialect ratchets. The changed freshness test file passes all 8 cases (11.56s Vitest / 12.97s wrapper; new case 1.701s) in job 114736157967. Local test suites were waived by the requested CI-first workflow. The final CI aggregate is red only for the inherited corruption-fixture expectation detailed below; no PR-caused static or test failure remains. Full-tree and script Knip export scans pass. The production scan has only the precisely attributed inherited export finding below. All static requirements are passed or independently attributed to main.The integrated-head production Knip scan reports only the pre-existing
src/gateway/control-ui-public-session-card-render.ts: renderPublicSessionCardSvgexport. The identical rule and file fail in main job 114717131950; main already fixes it in802f3415be1f. The PR neither changes that module nor its consumers. The initial 600-second scan timed out under local contention; the same scan was retried serially with a 30-minute wall-clock allowance and no rule changes.Final CI inherited-failure disposition: job 114736158090 fails only
sessions-resolve-projection.test.ts/preserves warm and cold storage-reader outcomes for mismatched-window rows(expectedtarget-id, receivedundefined). Its checkout log explicitly identifies mergeb5f152ec824d3c2d55f5d70f0f1151f0016cc14e, combining this head with main2c7cc827b309c6a2da1cd6c2aa5cb930eb326030. That main commit addscurrent_session_idtoloadSessionEntrySnapshot's SELECT; the existingparseSqliteSessionEntryRecordrejects a row whose current session ID differs from its JSON session ID. The test deliberately creates that mismatch but retains its old expectation. This is the synchronous list-reader path, not either changed lifecycle-read path. The failing test and parser are unchanged by this PR. Focused local comparisons were attempted, then stopped during slow fixture startup once the actual CI checkout and source change established attribution; they are not claimed as passing proof. Landing uses the authorized inherited-failure exception.