Repository navigation
fix(sessions): reduce history stalls during cron cleanup - #155998
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. Reviewed September 22, 2026, 7:57 PM ET / 23:57 UTC (Revision 2). ClawSweeper reviewWhat this changesSeparates cron session-retention reads from foreground history reads while keeping both worker queues under the existing database cleanup owner. Merge readiness✅ Ready for maintainer review Keep open: current main still shares the reader queue, and this PR addresses the remaining contention with convincing scoped performance evidence. No blocking correctness finding was identified. Priority: P2 Review scores
Verification
How this fits togetherSession readers serve conversation history and supply expired-session candidates to cron cleanup. Their lifecycle owner retains database access, rejects revoked results, and drains workers before a database closes. flowchart TD
A[History and exact-entry requests] --> B[Foreground reader queue]
C[Cron retention sweep] --> D[Maintenance reader queue]
B --> E[Shared database lifecycle owner]
D --> E
E --> F[SQLite session store]
B --> G[History results]
D --> H[Validated cleanup candidates]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +40, Tests +154, Docs +5. Total +199 across 11 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep foreground and maintenance reads independently scheduled under one database lifecycle owner, preserving existing admission, cleanup, and storage contracts. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main queues foreground reads behind full-store cron validation in a single-worker pool, consistent with the recorded contention measurements. This review did not execute a runtime reproduction. Is this the best way to solve the issue? Yes: a bounded second queue reuses the existing reader and lifecycle contracts without duplicating storage policy or changing persisted state. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7a66ecd22a43. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
51f46b4 to
38543f6
Compare
|
Merged via squash auto-merge.
|
Related: #155414
What Problem This Solves
Fixes history and exact-entry reads waiting behind full-store validation during cron session retention.
User Impact
Foreground reads can complete while cron discovery validates a large session store. One additional reader worker is created on demand. In the synthetic Linux replay below, observed warm RSS increased by 19–159 MiB, and the cold 64 MiB shared-store foreground p95 increased from 425 to 655 ms. Workers retain the existing 30-minute idle retirement and critical-memory cleanup behavior.
Why This Change Was Made
Cron target discovery, validation, and reader cleanup use one bounded maintenance lane within the existing session database lifecycle owner. Foreground history and entry reads keep their queue. Both lanes preserve admission, per-lane cleanup sequence receipts, alias custody, revocation, failed-close retention, and the Bun retirement path. Whole-store corruption and participant checks, logical-agent throttling, exact deletion guards, schemas, retention, and update behavior remain unchanged.
The raw pool exports are private; internal callers and tests use the production lane interface.
Evidence
Frozen ABBA comparison against
9c87f193a96f759e5d08e1a2a314c9e4d4911104, using built workers on one Blacksmith Testbox: Node 24.19.0, Linux, 4 visible CPUs, 16 GB RAM. Each variant has two process replicates, six warm passes per process, two logical agents, and three foreground reads per agent. The table reports medians of each process's p95, with whole-pass CPU/wall differences and process-wide RSS observations.Every qualified cell has matching foreground output and final-store hashes, identical asserted runtime/resource identity, and observed foreground arrival while discovery is pending. Cold process CPU increased 10–16% in the shared-store cases. Other maintenance work remains visible: the 640 MiB pass still reached 394 ms maximum event-loop delay. These measurements describe the synthetic workload; they do not establish aggregate Gateway CPU savings.
*The same-store entry + history-page cell is a separate matched ABBA comparison on a fresh lease with the same visible Node/CPU/RAM profile; its clocks and resource identity are qualified independently. Its queue column includes all attributed reader requests. Cold page p95 increased from 509 to 716 ms. All four raw page captures independently match the source namespace derived from the owner-declared database path, logical agent, session, and stored transcript generation. Replacing only that verified fixture-specific token yields identical messages and pagination across all runs. The initial unnormalized page comparison is excluded; the original lease expired before correction, so no successful retry or same-host continuity is claimed for it.
Actual active-close proof joined both busy reader lanes, rejected the revoked foreground result, pruned no rows, preserved all 1,026 stored rows and their digest, and allowed a fresh-generation read. Critical-memory reclamation left both reader pools at zero workers. This proves closure through the physical database path; the rejected lexical-alias probe is excluded.
Focused owner, entry-reader, and cron coverage passed 81 unique cases across runs. The new two-case lifecycle suite and the existing concurrent-cleanup case preserve the native cleanup boundary. Required changed checks passed, including core and all 25 test typecheck shards, formatting, lint, import cycles, storage guards, and all three dead-export scans. Independent P0–P2 review is clean.
pnpm test src/config/sessions/session-transcript-worker-lanes.test.ts --maxWorkers=1passed: 12 ms test time, 65.73 s cold wrapper wall (91% of Vitest duration was transformation). The existing concurrent reaper-cleanup case passed in 12.94 s test time / 125.17 s cold wrapper wall; these costs include the real reader/writer lifetime boundary. The exact-head CI run 35799286375 passed after incorporating the canonical main fixture fixes8ce411c1aedfand46dfea6a4201. The original failing run remains attributable to those independently reproduced main defects; it was not blindly rerun. The refresh preserved the stable patch ID and all touched production/test bytes.Only the two raw pool export modifiers changed after the frozen measurement. Source reconstruction and normalized test-call binding checks verified unchanged pool construction, execution, and lifecycle behavior.
CI-reported case time by changed test file follows. These sums exclude shared collection, transformation, setup, and teardown wall costs; they are not incremental CI job wall time.
src/agents/cli-runner/session-history.async.test.tssrc/agents/sessions/session-manager-hydration-stream.test.tssrc/agents/sessions/session-manager-hydration.test.tssrc/config/sessions/session-transcript-worker-lanes.test.tssrc/cron/session-reaper.test.tssrc/gateway/server-methods/question.own-run.test.tssrc/gateway/server-methods/question.session-access.test.ts