Repository navigation
[BACKPORT] fix(sessions): avoid OOM while archiving thousands of session generations - #128980
Conversation
…s are built (#112424) * fix(sessions): keep gateway responsive during transcript archiving * test(sessions): strengthen archive worker coverage * fix(sessions): bound archive worker concurrency * test(sessions): normalize rollback paths on Windows * fix(sessions): load source archive worker on node 22 * fix(sessions): align archive fencing with session windows * test(sessions): adapt cleanup race to archive worker * fix(sessions): harden archive worker lifecycle * style(sessions): format archive lifecycle tests * fix(sessions): release writer lane during archive work --------- Co-authored-by: Josh Lehman <[email protected]> (cherry picked from commit 9bfe292)
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 2:32 AM ET / 06:32 UTC. ClawSweeper reviewWhat this changesThis PR backports worker-based SQLite transcript archiving and writer-lane release behavior to the pinned release branch, with a related session-title fence and a UI-test stability cherry-pick. Merge readinessNo blocking patch defect found. This is a release-branch backport of merged session-archive fixes; its persisted-state and Gateway-availability impact require maintainer release inclusion review after exact-head archive and packaging checks finish. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: FAIL (partial) — step 2 Assertions:
How this fits togetherSQLite session maintenance plans archive-and-delete work for old transcript generations, then revalidates the database before reclaiming rows. The Gateway invokes these lifecycle paths while serving RPCs, and the new worker moves expensive archive creation off its event loop. flowchart LR
A[Session maintenance] --> B[Deletion plan and state snapshot]
B --> C[Archive worker]
C --> D[Final snapshot validation]
D --> E[SQLite state reclamation]
C --> F[Durable transcript archive]
G[Gateway requests] --> A
Decision needed
Why: The patch changes persisted transcript reclamation and Gateway lifecycle ordering on a release branch, so release scope acceptance is a maintainer decision. Before merge
Agent review detailsSecurityNone. PR surfaceSource +489, Tests +1574, Config 0, Other +5. Total +2068 across 29 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the bounded worker backport only once exact-head validation proves archive-before-delete, same-store writer progress, and packaged Worker availability on the release branch. Do we have a high-confidence way to reproduce the issue? Yes, from source: the release base retains full transcript content in deletion plans, while this branch replaces that path with snapshot-only plans and a Worker. I did not execute the heavy archive scenario in this read-only review. Is this the best way to solve the issue? Yes: the branch ports the already-merged upstream worker, writer-lane, and title-admission design rather than creating a release-only alternative; the remaining question is release inclusion and exact-head validation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 6335d9777138. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
(cherry picked from commit 141a16f)
(cherry picked from commit 871abad)
|
/merge |
What Problem This Solves
On the pinned release branch, one logical session can accumulate thousands of historical SQLite transcript generations. When normal session maintenance exceeds
maxEntries, it eagerly reads every generation into archive deletion plans containing the complete serialized transcript and retains the entire batch on the gateway heap. The resulting repeated transcript reads and retained strings can exhaust the Node.js V8 heap even when no individual session is unusually large.Why This Change Was Made
Backport the existing upstream fix from #112424 (
9bfe292c8686c9f55282fb5773b8729f96b68051) and its direct writer-lane follow-up #119460 (141a16f7b39b0ee1ddda13bc898de02214cb7cf1) tosjf_openclaw_2026-07-31instead of creating a divergent release-only implementation. Archive plans now retain lightweight SQLite state snapshots; an existing upstream worker materializes one transcript archive at a time, and snapshot validation protects concurrent writes before state is reclaimed. The writer lane is released during expensive archive work.The release branch also lacks the narrowly related background-title admission fix from #123608 (
530b33e4e37264c89ecd5abdd06279dd23d5c867). Backport only itschat-send-background.tslifecycle fence: dashboard title generation now holds the same session work admission as deletion, preventing a concurrent title metadata update from invalidating the archive snapshot. The unrelated 37 files from #123608 are intentionally excluded.The broader CI matrix also exposed a pre-existing release-branch-only responsive-layout test race:
checks-ui-e2e (1/4)reported the identical CTAx=31versus stale nudgex=302already fixed upstream in #116613. Include its exact one-file, test-only cherry-pick (871abad910e76e76cf9f5922ce091ede076bbd3b), preserving the original author and all layout assertions; it makes no production changes.User Impact
Gateways can maintain sessions with many historical transcript generations without retaining all transcript contents on the main V8 heap. Existing transcripts remain complete and durable, concurrent session changes remain protected, and unrelated gateway requests stay responsive while archives are built.
Evidence
node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfooxfmt --checkpassed.dist/config/sessions/session-accessor.sqlite-archive.worker.js.Upstream: #112424, #119460, the targeted lifecycle fix from #123608, and the test-only CI fix from #116613