Skip to content

fix: report session changes during deletion - #125188

Merged
steipete merged 3 commits into
mainfrom
steipete/session-deletion-mismatch-signal-3a2f80
Aug 17, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/session-deletion-mismatch-signal-3a2f80

Conversation

@steipete

@steipete steipete commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where a concurrent session replacement after delete validation could silently return ok: true with deleted: false while the session survived. That false success was indistinguishable from the intentional missing-session no-op and gave operators and clients no signal to retry.

Why This Change Was Made

The SQLite session lifecycle now records an expected-entry mismatch at every guarded deletion phase, including target-snapshot changes after transcript materialization, preserves any historical archives already committed before a later mismatch, and keeps only the authoritative-entry-absent case benign. The producerless file-era deletedSessionFile result field and gateway consumer were removed.

During landing, mainline maintenance PR #125185 independently restored the OPENCLAW_* shrink-only ratchet to the actual 501-name production surface. This branch is rebased onto that maintenance; it is not part of the product behavior change.

User Impact

Operators and clients now receive the retryable session-changed error when a session is replaced during deletion instead of receiving false success.

Evidence

Before the initial fix, the gateway boundary regression expected ok: false but received ok: true after replacing the exact row once cleanup had captured the expected entry. The added post-materialization owner and Gateway regressions then failed on the intermediate patch with SqliteSessionMutationConflictError, proving the late snapshot conflict identified by ClawSweeper; both pass after translating that conflict at the lifecycle owner.

  • node scripts/run-vitest.mjs src/gateway/server.sessions.delete-lifecycle.test.ts src/gateway/server.sessions.delete-worktree-lifecycle.test.ts src/config/sessions/session-accessor.sqlite-cleanup-race.test.ts — 44 tests passed across two shards (28 gateway, 16 runtime-config).
  • node scripts/check-changed.mjs --dry-run -- <eight changed files> — selected core and coreTests lanes.
  • node scripts/check-changed.mjs -- <eight changed files> — exit 0; the environment ratchet reports OPENCLAW_* count 501/501, with format, type, lint, max-lines, dead-code, database-first, import-cycle, and boundary guards green.
  • git diff --check origin/main...HEAD — passed.
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted — clean after the ClawSweeper repair, no accepted/actionable findings.

Production LOC: +69/-46 (net +23). Tests: +302/-118 (net +184, including the existing worktree deletion test move). PR tooling LOC: +0/-0. The positive production delta adds one reusable snapshot predicate in the mainline equality owner and complete mismatch propagation at the three late lifecycle checkpoints; placing it there also preserves the 700-line entry-store ceiling after #125057. The absorbed mainline ratchet maintenance in #125185 was tooling-only +2/-2 and is verified here by the green 501/501 gate.

Regression provenance: PR #113075 / commit c440ae3 removed the legacy producer on 2026-07-23; PR #113233 / commit 4273ca9 carried the stale file-era deletedSessionFile residue forward.

No live proof was run: this is a deterministic internal lifecycle ownership race covered at both the direct SQLite owner boundary and the Gateway RPC boundary.

AI Assistance

AI-assisted. I reviewed and understand the change. No transcript or session logs are included.

@clawsweeper

clawsweeper Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Aug 17, 2026
@clawsweeper clawsweeper Bot added 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 6:14 AM ET / 10:14 UTC.

ClawSweeper review

What this changes

The PR reports a retryable session-changed result when SQLite session deletion detects a concurrent replacement during archival or final deletion, rather than returning a successful no-op.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this fresh maintainer-owned PR open for normal merge review. The new lifecycle-owner result converts each guarded deletion race into the existing Gateway retry signal, and focused owner plus Gateway regressions cover the late materialization path; exact-head checks are still running.

Priority: P1
Reviewed head: 648f019eea31ae6e82030292f24b13bb08bfef21
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with meaningful regression coverage; exact-head CI completion is the remaining merge gate.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal lifecycle race repair has focused direct-owner and Gateway-boundary regression evidence; external-contributor real-setup proof is not required.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal lifecycle race repair has focused direct-owner and Gateway-boundary regression evidence; external-contributor real-setup proof is not required.
Evidence reviewed 5 items Current-main gap: Current main still returns a benign deletion result when a late guarded check fails after materialization, so the proposed behavior is not already implemented.
Owner-boundary repair: The PR compares the complete target snapshot at every late checkpoint and returns the typed mismatch result while retaining archives already committed before a later conflict.
Gateway projection: The Gateway handler maps the lifecycle mismatch result to its established session-changed error before emitting deletion side effects.
Findings None None.
Security None None.

How this fits together

A Gateway sessions.delete request enters the SQLite session lifecycle, which snapshots the target, archives generations outside short transactions, then deletes the authoritative row. The result controls client retry behavior and subsequent session cleanup events.

flowchart LR
  A[Gateway delete request] --> B[Session lifecycle admission]
  B --> C[SQLite target snapshot]
  C --> D[Archive historical generations]
  D --> E{Snapshot and transcript still match?}
  E -->|yes| F[Delete session state]
  E -->|no| G[Retryable session-changed response]
  F --> H[Gateway session events]
Loading

Decision needed

Question Recommendation
Should this maintainer-owned session-state repair merge once all exact-head checks finish green? Wait for exact-head CI: Merge only after the pending checks complete successfully for commit 648f019.

Why: The patch is a focused owner-boundary fix with no remaining code finding, but the protected maintainer label and pending exact-head validation require a human merge decision.

Before merge

  • Resolve merge risk (P1) - The bug fix adds net 23 production lines to session-state deletion; the added result propagation is justified by three distinct guarded checkpoints, but merge should retain the focused exact-head validation.
  • Resolve merge risk (P1) - Required exact-head CI is still in progress, so the branch is not ready to merge yet.
Agent review details

Security

None.

PR surface

Source +23, Tests +184. Total +207 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 5 69 46 +23
Tests 3 302 118 +184
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 371 164 +207

Review metrics

Metric Value Why it matters
Production versus test LOC production +69/-46 (net +23); tests +302/-118 (net +184) Production growth carries the typed mismatch outcome through three lifecycle checkpoints; the test increase covers direct SQLite and Gateway race behavior.

Stored data model

Persistent data-model change detected: serialized state: src/config/sessions/session-accessor.lifecycle-types.ts, serialized state: src/config/sessions/session-accessor.sqlite-cleanup-race.test.ts, serialized state: src/config/sessions/session-accessor.sqlite-entry-equality.ts, serialized state: src/config/sessions/session-accessor.sqlite-lifecycle.ts, serialized state: src/gateway/server-methods/sessions-delete.ts, serialized state: src/gateway/server.sessions.delete-worktree-lifecycle.test.ts, and 2 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Await exact-head validation (recommended)
    Keep the resolved lifecycle-owner implementation and merge after all checks for the current head succeed.
  2. Pause if validation exposes a new race
    Hold the PR only if exact-head validation reveals an unhandled guarded deletion checkpoint or archive-state regression.

Technical review

Best possible solution:

Retain the lifecycle owner as the single translator of late snapshot conflicts, then merge after exact-head checks confirm the focused race coverage and changed gate remain green.

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

Yes, from source and focused regression tests: replace the guarded entry or transcript after archive materialization and invoke sessions.delete; current main can return deleted false as a successful response, while this branch produces session-changed.

Is this the best way to solve the issue?

Yes. Translating conflicts at the SQLite lifecycle owner covers every late deletion checkpoint and lets the existing Gateway error projection remain the only client-facing translation.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: A concurrent replacement can otherwise produce a false successful delete outcome for Gateway clients and operators.
  • merge-risk: 🚨 session-state: The PR changes compare-and-delete, archive, and retry behavior for persisted SQLite session state.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool 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 maintainer-authored internal lifecycle race repair has focused direct-owner and Gateway-boundary regression evidence; external-contributor real-setup proof is not required.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the current PR head and the recent merged session-ownership change that established the relevant SQLite snapshot semantics. (role: recent session lifecycle contributor; confidence: high; commits: 55ce95fac803, 824a68a570d1, 731503b33256; files: src/config/sessions/session-accessor.sqlite-lifecycle.ts, src/config/sessions/session-accessor.sqlite-entry-equality.ts, src/gateway/server-methods/sessions-delete.ts)

Rank-up moves

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

  • Wait for all checks on commit 648f019 to finish green.

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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-08-17T09:27:03.455Z sha 6ff472502ff781fffb13cb77233a6e1a4816f06e :: found issues before merge. :: [P1] Translate snapshot conflicts into the deletion mismatch result
  • reviewed 2026-08-17T09:37:56.775Z sha 38dcdc6 :: needs changes before merge. :: [P1] Translate late snapshot conflicts into the deletion mismatch result
  • reviewed 2026-08-17T09:58:43.289Z sha 11120ae :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the steipete/session-deletion-mismatch-signal-3a2f80 branch from 6ff4725 to 38dcdc6 Compare August 17, 2026 09:31
@steipete
steipete marked this pull request as ready for review August 17, 2026 09:31
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 17, 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 17, 2026
@steipete
steipete force-pushed the steipete/session-deletion-mismatch-signal-3a2f80 branch from 11120ae to 648f019 Compare August 17, 2026 10:07
@steipete

steipete commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Land-ready proof

Exact head: 648f019eea31ae6e82030292f24b13bb08bfef21

  • node scripts/run-vitest.mjs src/gateway/server.sessions.delete-lifecycle.test.ts src/gateway/server.sessions.delete-worktree-lifecycle.test.ts src/config/sessions/session-accessor.sqlite-cleanup-race.test.ts — 44 tests passed across two shards (28 Gateway, 16 runtime-config).
  • node scripts/check-changed.mjs --dry-run -- <eight changed files> — selected core and coreTests lanes.
  • node scripts/check-changed.mjs -- <eight changed files> — exit 0, including OPENCLAW_* count 501/501, format, type, lint, max-lines, dead-code, database-first, import-cycle, and boundary guards.
  • git diff --check origin/main...HEAD — passed.
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted — clean after the lifecycle repair and clean after the equality-module relocation; no accepted/actionable findings.
  • Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/32018638169 — green via node scripts/watch-pr-ci.mjs 125188 648f019eea31ae6e82030292f24b13bb08bfef21.
  • ClawSweeper: 🐚 platinum hermit 4/6, no actionable findings. The only rank-up move was to wait for this exact-head CI, now satisfied: fix: report session changes during deletion #125188 (comment)

Pre-fix proof: the original Gateway regression returned false success; the added post-materialization owner and Gateway regressions failed on the intermediate head with SqliteSessionMutationConflictError at the late snapshot assertion, then passed after translation at the lifecycle owner.

LOC: production +69/-46 (net +23); tests +302/-118 (net +184); PR tooling +0/-0. Mainline ratchet maintenance #125185 is tooling-only and is reflected by the green 501/501 gate.

Known gap: no live proof was run. This is a deterministic internal SQLite lifecycle race covered at the direct owner and Gateway RPC boundaries; ClawSweeper also marked external real-setup proof not applicable.

Native landing evidence:

  • scripts/pr review-init 125188 — initialized managed review worktree and exact PR head.
  • scripts/pr review-artifacts-init 125188 + scripts/pr review-validate-artifacts 125188 — validated READY FOR /prepare-pr, zero findings, valid issue evidence, behavioral sweep pass, and production/test LOC evidence.
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 125188 — passed at 2026-08-17T10:25:46Z for the exact head with gate mode hosted_exact_or_recent_parent; remote PR and local prep trees matched. The prepare flow reused green exact-head hosted CI, so no separate Testbox lease/run ID was allocated.

@steipete
steipete merged commit 353b497 into main Aug 17, 2026
219 checks passed
@steipete
steipete deleted the steipete/session-deletion-mismatch-signal-3a2f80 branch August 17, 2026 10:27
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 18, 2026
* fix(sessions): report deletion lifecycle mismatches

* fix(sessions): translate late deletion conflicts

* refactor(sessions): move lifecycle snapshot equality
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR 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.

1 participant