Repository navigation
fix(sessions): reject deletion after caller authority closes - #137672
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: blocked before merge. Reviewed September 4, 2026, 2:02 AM ET / 06:02 UTC. ClawSweeper reviewWhat this changesThe 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 provenancePossible 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 Review scores
Verification
How this fits togetherAn 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]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +185, Tests +384. Total +569 across 10 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest 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. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
be1fbb1 to
32c031a
Compare
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.
32c031a to
4416c47
Compare
|
Merged via squash.
|
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.
…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.
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
assertCommitAllowedcallback. 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
codex-rs/app-server/src/request_processors/thread_delete.rsplus unsubscribe/archive ownership inthread_processor.rs. No external Codex API behavior is claimed.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.1at74be8c0d44623711fde78c70bc40f5a633dc4f56.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.