Repository navigation
fix(codex): reclaim binding capacity after session deletion - #128366
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 11:21 PM ET / August 27, 2026, 03:21 UTC. ClawSweeper reviewWhat this changesThe PR reclaims Codex thread-binding capacity when an OpenClaw session is deleted, adds conservative Doctor repair for orphaned bindings, and fences native-thread cleanup and resume ownership. Warning SQLite table change This PR modifies persisted SQLite tables in Merge readinessKeep open for maintainer review. The PR addresses a real session-state capacity failure with an owner-boundary design, but it introduces a public Plugin SDK lifecycle contract and durable cross-store cleanup; the required direct Codex runtime-source check cannot be completed because the sibling checkout is absent. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw stores session rows in an agent database while the Codex plugin stores native-thread bindings in shared plugin state. Deletion must update both owners safely, then release only the deleted session's native subscription while preserving shared native history. flowchart LR
A[Session lifecycle request] --> B[Prepare harness deletion]
B --> C[Codex binding lease]
C --> D[Agent database transaction]
D --> E[Binding commit or rollback]
E --> F[Native subscription release]
G[Doctor repair] --> E
Decision needed
Why: This is a compatibility-sensitive public plugin contract and persistent-state behavior change; source inspection establishes the implementation shape but cannot determine the intended long-term SDK contract. Before merge
Agent review detailsSecurityNone. Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Retain the prepared owner-boundary deletion design only after direct Codex contract inspection and explicit maintainer acceptance of the generic SDK lifecycle and cross-store recovery contract. Do we have a high-confidence way to reproduce the issue? No: this read-only review did not execute the failing deletion path. The PR body provides a redacted authenticated run and focused regression claims, but they were not independently rerun here. Is this the best way to solve the issue? Unclear: placing binding cleanup at the session-deletion owner is a plausible canonical fix, but direct Codex runtime-contract verification and acceptance of the new public SDK contract are still required. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 47fe3cc8fc0c. LabelsLabel changes:
Label 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 (11 earlier review cycles; latest 8 shown)
|
|
Holding this PR before merge. Direct source review plus two independent owner-boundary reviews found the post-commit finalizer does not repair the reported producer safely. Blocking findings:
Upstream Codex confirms the ownership distinction: Required rewrite: use the existing exact agent-harness lifecycle owner for a pre-commit prepared deletion. Acquire/revalidate the binding and plugin generation before destructive writes, reject supervision/live claims while both records remain, synchronously compare-delete the exact binding, commit the session deletion, and compensate by compare-restoring the binding if the agent-DB commit fails. Keep doctor as bounded crash recovery for the unavoidable cross-database commit window. Cover the real cron base+run path, failed run, supervision/live claim, alias move, registry replacement, rollback, and incident-scale stable-key distribution. I am taking the branch through that rewrite and will refresh the PR evidence before it is eligible for landing. |
89f45cd to
0dacb6f
Compare
|
Rewritten around the session deletion owner in 0dacb6f18af: prepare and veto before SQLite mutation, exact-row companion compare-delete with compensation, post-commit native cleanup serialized with resume, and bounded conservative Doctor repair. The earlier review checklist and maintainer hold are addressed by owner-boundary regressions, the 50,000-row incident fixture, registry/claim/alias/race coverage, and a fresh Codex review. The authenticated Docker live run is in progress; I will add its actual result before landing. @clawsweeper re-review |
Prepare harness deletion outside the SQLite writer and compare-delete exact companion ownership at the session removal edge, with compensation before commit and native subscription release afterward. Preserve live siblings and upstream native history. Repair proven orphan bindings through the existing Doctor planner under maintenance ownership.
Record pending attachment intent and validate the immutable native tool catalog before applying configuration to the selected thread. Require uninterrupted physical-client ownership through native unsubscribe, resume, and binding commit. Keep the thread intact on unsupported policy, competing work, or failed proof. Reuse canonical retained-owner cleanup and preserve unsafe-client retirement. Cover the real command producer, cold and loaded resumes, competing leases, lazy-store commit fencing, and the Gateway competing-owner path.
d18ac70 to
5a22aff
Compare
|
Merged via squash.
|
…#128366) * fix(codex): reclaim binding ownership when sessions are deleted Prepare harness deletion outside the SQLite writer and compare-delete exact companion ownership at the session removal edge, with compensation before commit and native subscription release afterward. Preserve live siblings and upstream native history. Repair proven orphan bindings through the existing Doctor planner under maintenance ownership. * fix(codex): reuse prepared auth for resumed thread ownership * docs(plugins): clarify shared migration and auth contracts * test(codex): use the canonical config type facade * fix(codex): preserve native threads during manual resume Record pending attachment intent and validate the immutable native tool catalog before applying configuration to the selected thread. Require uninterrupted physical-client ownership through native unsubscribe, resume, and binding commit. Keep the thread intact on unsupported policy, competing work, or failed proof. Reuse canonical retained-owner cleanup and preserve unsafe-client retirement. Cover the real command producer, cold and loaded resumes, competing leases, lazy-store commit fencing, and the Gateway competing-owner path. * test: isolate Codex auth and session completion fixtures
What Problem This Solves
Fixes an issue where deleting or expiring Codex-backed sessions leaves durable binding rows behind, eventually exhausting the shared plugin-state limit and preventing new work. Failed native startup can leave a binding before the session records its harness, and cron base/run aliases can share a physical session ID without sharing their logical ownership.
Why This Change Was Made
This rewrites the original patch around the session deletion owner. Core prepares the existing registered harness outside the SQLite writer, then invokes an exact-generation, synchronous companion compare-delete at the row removal edge. Transaction failures compensate that deletion; errors after commit do not resurrect it. Registry replacement, competing work, supervision, and active native claims are checked before the destructive step. Ordinary physical-ID rollover remains a transfer, preserving compaction adoption.
Codex releases the original connection's subscription after commit, serialized with native resume. Any surviving owner, including a same-key successor or legacy conversation binding, preserves the subscription. Upstream native history is never deleted or archived. Cron now persists the selected harness on both base and run rows before native startup.
Doctor uses its existing migration planner, after canonical session repair. It scans bounded pages, uses physical-ID evidence without inventing a main-session key, and compare-deletes only unchanged, proven orphan rows under maintenance ownership. Current, leased, supervised, malformed, ambiguous, and advisory state survives. No schema/version bump, config option, or capacity increase is introduced. The optional harness lifecycle gains two named SDK types so extracted plugin implementations share one public contract. Session-scoped resume now uses the same canonical model/auth planner and credential fingerprint as agent turns, preventing a second native writer while retaining the existing API-key/subscription billing boundary. Two existing generic helpers are exported through their owning SDK runtime entrypoints; no new auth policy or client registry is introduced. Manual attachment now records pending intent, verifies the immutable native tool catalog, and applies configuration only under uninterrupted sole physical-client ownership. The lease-generation guard reaches unsubscribe and the synchronous binding write; failed or competing adoption preserves the selected thread instead of silently starting another.
User Impact
Session deletion and expiry free binding capacity. Operators with accumulated orphan rows can stop the Gateway and run
openclaw doctor --fix; ordinary Doctor detects the repair. Other sessions continue working, and deleted OpenClaw sessions can explicitly resume their preserved native Codex history.The two existing databases still have a process-crash window between their commits; this change provides synchronous compensation, not a distributed transaction. Doctor repairs proven leftover ownership conservatively and does not invent missing native bindings.
Evidence
8f8b29c72f0cb42e0d9483b1e00bdbecae526720, using Codex 0.149.1 andopenai/gpt-5.6-lunain a local container. The live test passed in 503.26 seconds (one case passed, one optional case skipped). It rejected a competing resume, verified both original bindings unchanged, deleted the selected session and binding, completed a sibling turn on the same native thread, and resumed the deleted session’s original native thread for a real model reply. Prior authenticated failures drove both the canonical-auth and pending-configuration repairs.d18ac70d162f3c011863b051024838d618428080passed CI 33033571018. Superseded CI 33024648388 attempt2 received runner shutdown exit143 with no lint diagnostic, then was cancelled for the production repair.command-rpc.test.tsandserver.agent.subagent-delivery-context.test.ts; production and live-test content are identical. Fresh core/plugin test types, lint, format and SDK test-boundary checks pass; fresh Codex review found no actionable issues at the default P0 threshold.Review follow-through: Doctor migration docs now apply to all plugins. Canonical SDK export sync is idempotent; surface check passes at 4,345 public exports and 2,582 callable exports. The budget values are maintained policy constants, not generated files; the tool has report/check modes only. The generic lifecycle remains optional and closure-bound. The fresh live test passed an actual competing-owner resume denial, followed by allowed deletion, sibling continuation and same-native-thread history resume. The denial comes from the exclusive owner check before the control request; the live test observes the rejection, unchanged bindings and continued sibling work. This is not an instrumented native-I/O trace or an injected stale callback. Separate deterministic owner tests assert no native request for stale/revoked callbacks and competing lease generations. Injecting a retired internal callback through the public Gateway is not a supported operator flow, so that specific rank-up variant remains deterministic proof rather than a live claim.
Redacted observed live result:
Direct upstream inspection uses Codex
rust-v0.149.1(ff29a44391deccde0aba0f8390337d7f3c319ea4).thread_processor.rs:944-990andthread_state.rs:488-579show connection/thread membership without reference counting or generation tokens;thread_lifecycle.rs:7,49-64andthread-store/src/local/writer_lock.rs:25-85explain the retained writer.thread_processor.rs:4006-4054plusthread_status.rs:223-251,336-347establish successful reload notifications, butthread_manager.rs:1804-1820can reuse a concurrently resumed native child. Therefore status notifications alone are insufficient: adoption requires the exact shared-client lease generation through commit.core/src/session/mod.rs:663-668establishes the immutable stored dynamic tool catalog. Goal operations remain unchanged because their pinned implementation supports stored threads without loading a writer.Named follow-ups: the advisory catalog-provenance cache should include the expected thread ID in its key; adoption bypasses that cache and validates the header ID. Separately, Crabbox pristine-workspace GitHub hydration can leak runner registration when fingerprint invalidation fails before sync; owned leaked resources were cleaned up. Current proof is local-container, not remote AWS/Blacksmith proof.
Release-note context: fixes Codex session-deletion/expiry capacity leaks and conservatively repairs accumulated orphan bindings while preserving native history. Original PR and rewrite authored by @steipete.
Latest Review Follow-through
The reported new fork-skip write race is not reachable with supported canonical targets.
runPreparedSqliteSessionWritekeeps the original writer when there are no deletion targets and nobeforeCommit; parent fork selects only noncanonical rows for deletion, but its earlier resolver rejects duplicate rows and a sole noncanonical alias. A final-head executable probe passed both skip branches with an independently queued concurrent update preserved. Duplicate and sole-alias inputs were rejected before deletion preparation, with both rows unchanged. All four cases observed zero deletion preparations. This addresses the review premise without adding unreachable-path guards or changing production behavior.A separate follow-up is recorded for cross-process parent-fork skip patches: the old owner already merged a pre-transaction child snapshot, and its process-local queue does not serialize another process. That pre-existing surface needs a dedicated multi-process reproduction and a coherent fork-owner repair; it is not the new same-process writer-release regression alleged here. Both the pre-rebase and final rebased CI runs are green, including the two previously failing lanes.
The PR was mechanically rebased to
5a22aff71faa2b1e3d9dd295d95c59d62183cc00after another SDK export change landed on main. Combined surface counts validate at 4,345 public and 2,582 callable exports; canonical export sync is clean. Range-diff confirms the reviewed runtime patch is unchanged. All 29 focused session-deletion/parent-fork tests and the four-case fork probe pass after rebasing. Final CI 33035491600 passed on that exact head: 156 passing checks, 43 skips, no pending or failed checks. The earlier live/build proof remains at the stated source head, not the full rebased tree.Maintainer implementation decision after the latest review (03:21 UTC): retain the optional generic
withSessionDeletionlifecycle for this rewrite. Core owns logical session deletion and harness plugins own their companion bindings; a Codex-specific core hook would put policy in the wrong owner. Existing harness implementations gain no required callback or parameter. Retain the existing two stores with compensation and conservative Doctor repair, explicitly without a cross-database crash-atomicity claim. No table or schema-version change is introduced; existing-database repair, protected rows and idempotence are covered by the incident/migration fixtures. The acting maintainer agent directly inspected the exact sibling Codex source cited above; its absence from the automated review checkout is not a dependency-proof gap in this review. Exact-head CI is now complete and green. All latest rank-up items are addressed without requesting another redundant review cycle.