Skip to content

fix(sessions): reject deletion after caller authority closes - #137672

Merged
steipete merged 2 commits into
mainfrom
codex/stable-audit-session-guard-20260903
Sep 4, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/stable-audit-session-guard-20260903

Conversation

@steipete

@steipete steipete commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A session deletion could commit after its admitted Gateway or caller retired during asynchronous reclamation. The Worker payload discarded the live caller guard. The request could report an expired Gateway binding after already removing a historical generation.

Found during the regression audit from stable 2026.9.1; introduced by #126035 (789513231d7d6ee412c1304677f17a2525d82bc6).

Root Cause and Repair

The reclamation owner now separates its serializable plan from one parent-owned assertCommitAllowed callback. Large guarded deletions remain in the existing Worker. After doing the expensive SQL work, the Worker requests a final parent checkpoint before committing. Only the parent evaluates the live closure. Its atomic approval cannot be revived after rejection or expiry.

After approving, the parent synchronously waits for transaction settlement so its JavaScript authority cannot retire before commit. A short-lived SQLite connection joins the existing writer lock without bootstrapping schemas or registry state. The Worker also records settlement only after its actual transaction ends or its connection closes. This handles a failed barrier connection and abrupt Worker exits without treating a queued JavaScript exit callback as native completion.

The actual Worker result and exit still determine success. Recovered settlement errors remain bounded diagnostics, allowing a confirmed deletion to finish archive publication and identity/placement notifications. Authority rejection retains its original error. The Gateway guard uses the existing read-only session lookup, avoiding a writable bootstrap while the Worker holds the agent database lock.

This replaces closure stripping and duplicate guard placement with one assertion owner. There are no schema, stored representation, migration, configuration, dependency, or public protocol changes. The transaction-coordination design was explicitly approved by the maintainer.

Behavior and Scope

A retired caller fails visibly and keeps the current and historical data intact. A current caller can delete a large transcript while the expensive reclamation runs off the Gateway thread. Native rollback/initialization and incognito databases retain their existing in-process execution.

That native exception matters: a registered Codex harness can prepare an absence fence even for an ordinary session with no native binding. The production registered-harness live probe verified successful deletion, both archives, and unrelated-session isolation, but observed a 4,104.8 ms main-thread gap over a 26,975.6 ms request. This in-process behavior was already shipped in stable 2026.9.1; the worker responsiveness result below does not cover it. Follow-up: preserve the native absence/rollback fence while designing responsive native deletion. This PR does not weaken that fence.

The five-second checkpoint decision deadline does not cap the final native settlement wait. If both the lock barrier and Worker settlement evidence become irrecoverably unavailable during native I/O, the parent must retain the safety join. It cannot safely resume on a timer and permit a late unauthorized commit.

Verification

  • Baseline real authenticated compiled Gateway request: retire the exact captured Gateway context when its reclamation Worker starts. The RPC reports a binding error, but a historical generation is already deleted and its archive exists. Candidate: the same retirement preserves 200,000 current events and the historical event, with no archive created.
  • Large-deletion responsiveness: real compiled Gateway over authenticated WebSocket, 200,000 canonical transcript/active/FTS rows before deletion, 200.1 ms maximum main-thread timer gap against the existing 500 ms bound; request completed in 10.2 seconds. Current and historical rows were removed, both archives were published, and all six unrelated rows plus their session node remained. The earlier in-process draft reproduced a 2,641.1 ms gap. The final probe exited 0 and cleanup reported no errors.
  • Actual Worker/SQLite fault scenarios cover rejection, expired approval, commit and rollback, abrupt exit before/after commit, competing writers, permanently unusable or closed barrier connections, and close errors. A separate red/green lifecycle regression proves a recovered barrier error must not hide committed deletion or suppress its published archive and identity event.
  • Owner/sibling verification: 71 passing tests across checkpoint coordination, current/historical admission races, native deletion rollback/retirement, archive workers, and incognito storage. The final repeat passed 27 owner/handle cases and the existing 200,000-row Gateway and 100,000-row cleanup checks (122.6 ms and 99.5 ms maximum gaps). All changed-file checks passed across the final run and the prior full dead-code scans, reused after test-only lint corrections.
  • Registered production Codex harness live probe: canonical current transcript, active, and FTS projections each contained 200,000 rows before deletion; native binding rows stayed zero. All six current/historical tables were emptied, two hashed archives were published, and the unrelated session and all six of its rows remained. No model/provider request was made.
  • Direct dependency/source inspection included Node Worker and SQLite transaction behavior, the canonical native absence fence, and sibling Codex codex-rs/app-server/src/request_processors/thread_delete.rs plus unsubscribe/archive ownership in thread_processor.rs. No external Codex API behavior is claimed.
  • Independent Codex review is clean through P2. Hosted CI remains required before landing.

Review disposition: the prior P1 and Rank-up move requested guarded 200,000-row deletion below the existing 500 ms heartbeat bound while preserving final authority rejection. The coordinated Worker design addresses that finding; final observed measurements are recorded above. The original forced in-process approach has been removed.

Production/test accounting: production +209/−24, net +185 across seven files; tests/support +384/−0 across three files. Production growth implements the approved cross-thread authority and transaction-settlement boundary, including real failure outcomes; it is not a new storage or compatibility layer.

Latest review disposition: retain the fail-closed settlement join and the approved parent/Worker coordination boundary. The exceptional native-stall availability tradeoff and the net +185 production lines are intentional, with their rationale and observed normal-path timing above. Neither calls for weakening authority or adding a timeout that could permit a late commit. The stable baseline for this audit is 2026.9.1 at 74be8c0d44623711fde78c70bc40f5a633dc4f56.

Main refresh: the candidate is now 4416c4746dd495b915987da4cb64d4e4b7422524, based on the landed canonical advisory-availability policy #137881 (e5d413f7e54a). Nine candidate files remain byte-identical to the reviewed live-tested repair. The lifecycle owner additionally incorporates main's six-line empty-cleanup fast path: both idle/orphan/archive-retry cases passed, and a fresh independent review of the full composed ten-file candidate found no actionable P0–P2 findings. The large live measurements above predate this small composition; they are not new measurements of the refreshed base. Exact-head CI completed successfully with 113 executed jobs, including Windows coverage; all required PR checks are green.

@clawsweeper

clawsweeper Bot commented Sep 3, 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 size: S maintainer Maintainer-authored PR labels Sep 3, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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 Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 2:02 AM ET / 06:02 UTC.

ClawSweeper review

What this changes

The PR keeps live Gateway caller authority in the parent process while a Worker reclaims SQLite session data, requiring a final parent authorization before commit.

Regression provenance

Possible regression — probable (reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this PR open for normal maintainer review: current main still contains the Worker-mode caller-authority gap, and no introduced P0–P2 defect was found in the proposed parent-authorized commit boundary.

Priority: P1
Reviewed head: 4416c4746dd495b915987da4cb64d4e4b7422524

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has a coherent owner-boundary repair and targeted Worker/SQLite regression coverage, with the documented fail-closed availability tradeoff remaining intentional.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER PR is exempt from the external-contributor proof gate; its reviewed body nevertheless records a real authenticated compiled-Gateway before/after scenario for the changed session-deletion path.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER PR is exempt from the external-contributor proof gate; its reviewed body nevertheless records a real authenticated compiled-Gateway before/after scenario for the changed session-deletion path.
Evidence reviewed 6 items Current-main defect: Current main invokes the caller guard only on the in-process branch; its Worker request receives the serialized plan without a commit callback, leaving Worker reclamation outside the live caller check.
Introduced authority boundary: The candidate creates a per-operation shared checkpoint only when a live assertion exists and handles the Worker request in the parent before it can return a reclamation result.
Commit and rollback ordering: The Worker reaches the checkpoint while its transaction is open, and the parent asserts current authority immediately before approval, then joins transaction settlement before releasing its JavaScript authority.
Findings None None.
Security None None.

How this fits together

An authenticated Gateway session-delete request prepares lifecycle cleanup, then a Worker performs expensive SQLite reclamation and archive work. The new checkpoint keeps final commit permission in the parent so revoked session authority can reject the deletion before durable mutation.

flowchart LR
  A[Gateway session delete request] --> B[Session lifecycle preparation]
  B --> C[SQLite reclamation Worker]
  C --> D[Parent commit checkpoint]
  D --> E[SQLite commit or rollback]
  E --> F[Archive publication and session events]
Loading

Before merge

  • Resolve merge risk (P1) - After approval, an irrecoverable Worker or SQLite settlement failure can deliberately block Gateway responsiveness until native transaction settlement rather than permit a late unauthorized commit.
  • Resolve merge risk (P1) - The cross-thread authority protocol adds net 185 production lines, increasing the amount of transaction-ordering behavior that must remain coherent.
Agent review details

Security

None.

PR surface

Source +185, Tests +384. Total +569 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 7 209 24 +185
Tests 3 384 0 +384
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 593 24 +569

Review metrics

Metric Value Why it matters
Production versus test LOC production +209/-24 (net +185); tests/support +384/-0 The production growth implements the parent/Worker authorization and settlement boundary; test growth exercises its real SQLite and Worker failure outcomes.

Merge-risk options

Maintainer options:

  1. Accept the fail-closed availability tradeoff (recommended)
    Keep the settlement join so uncertain native completion cannot turn a revoked caller into a late committed deletion.

Technical review

Best possible solution:

Retain the parent-owned final authorization and fail-closed settlement join; do not restore an in-process-only guard or add a timeout that could permit a late Worker commit.

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

Yes: current main visibly sends Worker reclamation without the live guard, while the candidate’s focused regressions exercise authority closure before commit. This read-only review did not execute the supplied authenticated Gateway scenario.

Is this the best way to solve the issue?

Yes: placing the final assertion in the parent immediately before Worker commit repairs the owner boundary without returning large SQLite reclamation to the Gateway event loop.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: This repairs a source-proven authority race in the authenticated Gateway session-deletion path.
  • merge-risk: 🚨 availability: The intended safety join can delay Gateway work when native Worker or SQLite settlement becomes unavailable.
  • 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 MEMBER PR is exempt from the external-contributor proof gate; its reviewed body nevertheless records a real authenticated compiled-Gateway before/after scenario for the changed session-deletion path.

Evidence

What I checked:

Likely related people:

  • HermanZeng: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (4 earlier review cycles)
  • reviewed 2026-09-04T00:17:54.637Z sha 847d53b :: blocked before merge. :: [P1] Keep guarded large deletions off the Gateway event loop
  • reviewed 2026-09-04T00:39:27.022Z sha 847d53b :: blocked before merge. :: [P1] Keep guarded large deletions off the Gateway event loop
  • reviewed 2026-09-04T03:04:43.822Z sha be1fbb182123eae8d84f726f428e2085570a1ac0 :: blocked before merge. :: none
  • reviewed 2026-09-04T03:41:30.715Z sha 32c031a :: blocked before merge. :: none

@steipete
steipete marked this pull request as draft September 4, 2026 00:21
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: L and removed size: S labels Sep 4, 2026
@steipete
steipete marked this pull request as ready for review September 4, 2026 02:57
@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 Sep 4, 2026
@steipete
steipete force-pushed the codex/stable-audit-session-guard-20260903 branch from be1fbb1 to 32c031a Compare September 4, 2026 03:22
Keep live deletion guards on the synchronous transaction owner. Unguarded background reclamation still uses workers; guarded current and historical session deletion revalidates authority immediately before mutation.

Release notes: prevent a retired Gateway or delegated caller from deleting a session after asynchronous cleanup preparation. Verified real Gateway owner retirement, failing/passing current and historical regressions, background responsiveness, and check:changed.
Keep caller and lifecycle assertions in the parent while the existing Worker
performs expensive SQLite deletion. Authorize the pending commit through an
operation-specific checkpoint and join native transaction settlement before
parent authority can retire. Keep confirmed Worker outcomes authoritative
after recovered barrier errors so archives and lifecycle effects still publish.

Retain native rollback and incognito ownership. The compiled Gateway proof
preserves current and historical data after authority retirement, then deletes
200,000 transcript rows with a measured 200ms maximum Gateway pause while
verifying archives and unrelated session state.
@steipete
steipete force-pushed the codex/stable-audit-session-guard-20260903 branch from 32c031a to 4416c47 Compare September 4, 2026 05:54
@steipete
steipete merged commit 3df4930 into main Sep 4, 2026
184 checks passed
@steipete
steipete deleted the codex/stable-audit-session-guard-20260903 branch September 4, 2026 06:13
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 4, 2026
Keep read-only archive materialization and publication from loading session reclamation and plugin ownership code. Reuse the existing file helpers from a leaf module and load reclamation only for the reclaim operation.

Preserve the guarded commit authorization and settlement protocol introduced by #137672 by moving its complete current Worker implementation into the lazy runtime. Keep the parent queue, commit-request handling, error precedence, generation fences and cleanup outcomes unchanged.

The original controlled Linux pair reduced warm deletion median from 895ms to 398ms on d84. That timing is historical; this integration does not claim a new latency measurement.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…w#137672)

* fix(sessions): preserve authority through reclamation

Keep live deletion guards on the synchronous transaction owner. Unguarded background reclamation still uses workers; guarded current and historical session deletion revalidates authority immediately before mutation.

Release notes: prevent a retired Gateway or delegated caller from deleting a session after asynchronous cleanup preparation. Verified real Gateway owner retirement, failing/passing current and historical regressions, background responsiveness, and check:changed.

* fix(sessions): coordinate guarded reclamation commits

Keep caller and lifecycle assertions in the parent while the existing Worker
performs expensive SQLite deletion. Authorize the pending commit through an
operation-specific checkpoint and join native transaction settlement before
parent authority can retire. Keep confirmed Worker outcomes authoritative
after recovered barrier errors so archives and lifecycle effects still publish.

Retain native rollback and incognito ownership. The compiled Gateway proof
preserves current and historical data after authority retirement, then deletes
200,000 transcript rows with a measured 200ms maximum Gateway pause while
verifying archives and unrelated session state.
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: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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