Skip to content

fix(sessions): release writer lane during transcript archival - #119460

Merged
fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:codex/fix-sqlite-archive-writer-lane-20260805
Aug 5, 2026
Merged

fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:codex/fix-sqlite-archive-writer-lane-20260805

Conversation

@fuller-stack-dev

Copy link
Copy Markdown
Member

Related: #112423
Follow-up to #112424

What Problem This Solves

Fixes an issue where SQLite session cleanup, lifecycle mutation, deleted-agent purge, or disk-budget eviction could keep the per-store writer lane occupied while a transcript archive was built. A newly arriving write to the same store then waited for archive materialization even though the CPU-heavy archive work already ran in a Worker.

Why This Change Was Made

Archive callers now plan under a short SQLite writer section, release the writer while the archive is materialized, then reacquire it and revalidate authoritative rows, references, and admission state before deleting. Maintenance archival follows the same boundary.

This preserves extract-before-delete and lifecycle invalidation without polling, retries, request-time caches, fallback readers, config, or protocol changes.

User Impact

Same-store session writes can continue while low-priority transcript archival is pending. Archive correctness, shared-generation protection, and disk-budget behavior are preserved.

This PR does not claim to fix cold chat.metadata preparation. A proof-only cold metadata probe exceeded 2 seconds while writer and system-presence responsiveness passed, so that remains a separate lifecycle/catalog investigation.

Evidence

  • Red proof on unmodified base: lifecycle cleanup paused in archive materialization and a same-store writer failed the 500 ms liveness bound; the ordinary direct-delete control passed. Blacksmith Testbox tbx_01kz7hgs8vy7qx6h9cggbjhm5z, Actions run 30959924647.
  • Exact change proof: 19/19 focused lifecycle and disk-budget tests passed, including cleanup, lifecycle mutation, historical-generation, direct-delete negative control, and eviction paths.
  • Built Gateway proof: a randomized roughly 64 MiB transcript was deleted while same-store sessions.patch and unrelated system-presence RPCs remained below 500 ms; the archive byte length and SHA-256 matched, and session, transcript, FTS, and window rows were removed.
  • Production build passed.
  • Blacksmith Testbox tbx_01kz7yxwa13gxb9dpxck25sfsy, Actions run 30971926178.
  • pnpm check:changed passed for core, coreTests on the reviewed diff.
  • Autoreview: clean, no accepted/actionable findings; patch correctness 0.96.
  • Direct AWS Crabbox was attempted for base and head, but four fresh instances lost SSH after sync before executing repository code. Runs run_505553e9541e and run_261a03a9e071; no AWS result is claimed.

AI-assisted: yes. I reviewed the ownership boundaries, competing hypotheses, final diff, and validation results.

@openclaw-barnacle openclaw-barnacle Bot added size: L maintainer Maintainer-authored PR labels Aug 5, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 5, 2026, 12:14 AM ET / 04:14 UTC.

ClawSweeper review

What this changes

This PR changes SQLite session archival to plan under the writer lane, materialize the archive outside it, then reacquire and validate before deleting persisted transcript state.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: current main still holds the per-store writer during archive materialization, while this branch releases it and revalidates authoritative state before deletion. The patch appears correct; its maintainer/protected status requires the normal exact-head refresh before merge.

Priority: P1
Reviewed head: a2ac1bc8169a42a8594448a69113c969a5468e84

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused race coverage, reported built-Gateway proof, and a coherent owner-boundary fix support a normal good rating pending exact-head refresh.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its body nevertheless reports a built-Gateway 64 MiB after-fix run with archive-integrity and responsiveness checks.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its body nevertheless reports a built-Gateway 64 MiB after-fix run with archive-integrity and responsiveness checks.
Evidence reviewed 6 items Current-main behavior: Current main awaits archive materialization inside the writer-held cleanup path, so the reported writer-liveness gap remains unresolved there.
Branch ownership boundary: The PR plans under the writer, materializes outside it, then commits only after the final transaction revalidates planned entries and transcript state.
Deletion invariant: The shared delete owner rereads live references and compares the materialized snapshot before reclaiming rows, preventing stale or newly referenced transcript deletion.
Findings None None.
Security None None.

How this fits together

SQLite lifecycle maintenance archives session transcripts before reclaiming their rows, while Gateway session writes serialize through a per-store writer lane. This change separates slow archive construction from the final state-changing transaction so unrelated writes can continue.

flowchart LR
A[Lifecycle cleanup or eviction] --> B[Plan under store writer]
B --> C[Worker builds archive]
C --> D[Revalidate under store writer]
D --> E[Delete transcript and session rows]
F[Concurrent session write] --> G[Store writer lane]
G --> D
Loading

Before merge

  • Resolve merge risk (P1) - The PR is behind current main; refresh the exact merge head and confirm the prior ClawSweeper rank-up moves before merging.
  • Complete next step (P2) - The repair is concrete and source-supported, but the MEMBER author and maintainer label require a maintainer-owned exact-head merge review rather than automated repair dispatch.
Agent review details

Security

None.

PR surface

Source +59, Tests +207. Total +266 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 198 139 +59
Tests 1 207 0 +207
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 405 139 +266

Review metrics

Metric Value Why it matters
Production versus test delta production +198/-139 (net +59); tests +207/-0 The added production surface is justified by explicit plan/materialize/commit ownership and revalidation across four archival callers.

Stored data model

Persistent data-model change detected: serialized state: src/config/sessions/session-accessor.sqlite-cleanup-race.test.ts, serialized state: src/config/sessions/session-accessor.sqlite-lifecycle.ts, serialized state: src/config/sessions/session-accessor.sqlite-projection.ts, serialized state: src/config/sessions/session-history-eviction.ts, unknown-data-model-change: src/config/sessions/session-accessor.sqlite-cleanup-race.test.ts, unknown-data-model-change: src/config/sessions/session-accessor.sqlite-lifecycle.ts, and 2 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #112423
Summary: This PR addresses the remaining writer-lane responsiveness subset of the canonical SQLite archival issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Refresh the exact merge head (recommended)
    Rebase or refresh review against current main, then verify the concurrency proof and existing rank-up moves on the resulting head before merge.
  2. Pause for a narrower review
    Pause if the refreshed merge result changes the lifecycle ordering or invalidates the supplied writer-progress proof.

Technical review

Best possible solution:

Land one canonical plan → materialize → revalidate-and-delete flow across lifecycle cleanup, bulk mutation, deleted-agent purge, and disk-budget eviction.

Do we have a high-confidence way to reproduce the issue?

Yes, from source and supplied proof: current main awaits archive materialization inside the writer lane, and the branch's gated race tests exercise same-store writer progress while archival is paused.

Is this the best way to solve the issue?

Yes. Reusing the established post-writer finalizer and retaining final snapshot/reference/admission validation is the narrowest owner-boundary repair; moving the work to callers or adding a fallback would duplicate policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against c925634ae83b.

Labels

Label changes:

  • add P1: Large transcript archival can block same-store session writes in an active Gateway workflow.
  • add merge-risk: 🚨 session-state: The patch changes ordering around archive-before-delete and persisted transcript reclamation.
  • add merge-risk: 🚨 availability: The patch changes when the per-store writer is held during Gateway session maintenance.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its body nevertheless reports a built-Gateway 64 MiB after-fix run with archive-integrity and responsiveness checks.

Label justifications:

  • P1: Large transcript archival can block same-store session writes in an active Gateway workflow.
  • merge-risk: 🚨 session-state: The patch changes ordering around archive-before-delete and persisted transcript reclamation.
  • merge-risk: 🚨 availability: The patch changes when the per-store writer is held during Gateway session maintenance.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its body nevertheless reports a built-Gateway 64 MiB after-fix run with archive-integrity and responsiveness checks.

Evidence

What I checked:

Likely related people:

  • Josh Avant: Current-main blame attributes the lifecycle cleanup and after-release maintenance structure to the latest shared session implementation commit. (role: recent area contributor; confidence: medium; commits: 618fba92bf01; files: src/config/sessions/session-accessor.sqlite-lifecycle.ts, src/config/sessions/session-accessor.sqlite-maintenance.ts)
  • HermanZeng: The related merged PR established the worker materialization and final-revalidation architecture extended by this branch. (role: archive-worker design author; confidence: medium; commits: 9bfe292c8686; files: src/config/sessions/session-accessor.sqlite-lifecycle.ts, src/config/sessions/session-history-eviction.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Refresh the branch against current main and recheck the resulting exact head.
  • Confirm the latest ClawSweeper comment's rank-up moves before merging.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper

clawsweeper Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(sessions): release writer lane during transcript archival This is item 1/1 in the current shard. Shard 10/16.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Maintainer exact-head refresh complete for a2ac1bc8169a42a8594448a69113c969a5468e84 against current main at 4b7a989a8bfe722548e209c83a52671780df5c11.

ClawSweeper rank-up moves checked:

  • Exact-head maintainer review: complete; no findings, and the plan -> materialize outside writer -> authoritative revalidation -> commit boundary remains the best-fit repair.
  • Rebase/refresh suggestion: no branch rewrite performed. The 11 intervening main commits do not touch the four changed files, archive materialization, lifecycle fencing, or the SQLite writer queue, so they do not invalidate the red/green proof or merge decision.

Required CI is green (openclaw/ci-gate), hosted exact-head gate verification passed, and the prior fresh autoreview had no accepted/actionable findings. Cold chat.metadata/catalog readiness latency remains separate follow-up scope.

@fuller-stack-dev
fuller-stack-dev merged commit 141a16f into openclaw:main Aug 5, 2026
131 of 138 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

@fuller-stack-dev
fuller-stack-dev deleted the codex/fix-sqlite-archive-writer-lane-20260805 branch August 5, 2026 05:14
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 5, 2026
Kimiyu-186 pushed a commit that referenced this pull request Aug 25, 2026
Kimiyu-186 added a commit that referenced this pull request Aug 25, 2026
…ion generations (#128980)

* fix(sessions): keep gateway responsive while large transcript archives 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)

* fix(sessions): release writer lane during transcript archival (#119460)

(cherry picked from commit 141a16f)

* fix(gateway): fence background titles during session archival

Backport the session-title admission fix from upstream commit 530b33e (#123608) without its unrelated gateway changes. Keep asynchronous disk-budget scans out of the transcript stat regression fixture.

* test(ui): settle custodian mobile layout assertions (#116613)

(cherry picked from commit 871abad)

---------

Co-authored-by: Heming Zeng <[email protected]>
Co-authored-by: Josh Lehman <[email protected]>
Co-authored-by: Jason (Json) <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants