Skip to content

fix(codex): preserve successor bindings during stale cleanup - #143201

Closed
KirDE wants to merge 10 commits into
openclaw:mainfrom
KirDE:fix/125308-binding-generation
Closed

KirDE wants to merge 10 commits into
openclaw:mainfrom
KirDE:fix/125308-binding-generation

Conversation

@KirDE

@KirDE KirDE commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Closes #143187

What Problem This Solves

Fixes a Codex session losing its native thread binding when a stale attempt cleans up after a newer physical client reuses the same thread ID.

User Impact

The successor client keeps its binding and can resume the same native thread; a rejected stale cleanup also releases the old attempt's route and client lease. No config or storage migration is needed.

Why This Change Was Made

Attempt-owned clears now compare the recorded physical client ID as well as the thread ID in the SQLite binding mutation, and recheck attempt authority at the final effect. Startup teardown still runs when that authority check rejects. This integration retains current main's generation, supervision, lease, and native-subagent owners; obsolete context-engine tests were dropped in favor of current-main coverage plus a focused teardown regression.

Evidence

  • Release v2026.9.7 and upstream main 182f79b both clear by thread ID without a physical-client predicate. Resolved against that current main; the current PR head is 4df36ad and has no changed paths outside extensions/codex relative to that main.
  • Earlier PR-head proof used two distinct app-server clients over the protocol transport and a reopened SQLite store: the stale client could not clear the successor; that successor resumed and started a turn. Current-head regressions retain successor, invalid-image, overflow, authority-rejection, and route/lease cleanup assertions.
  • On this integrated head, scoped oxlint (13 TypeScript files), oxfmt, and Codex diff whitespace checks passed. Independent read-only P0-P2 review found no actionable issue. These are not substitutes for test execution.
  • Validation gap: the local 3.8-GiB host exhausted available swap while precompiling Vitest workers; the run was stopped before tests executed. SDK declaration preparation likewise stalled under memory pressure, so current-head typechecks are unverified locally. Exact-head GitHub CI must establish both before merge; no merge is requested here.
  • The first integrated-head CI exposed outdated test fixtures, repaired at 9687478. CI run 36732143396 then exposed two further regressions: overflow recovery’s mock lacked the physical client ID required for exact-owner retry, and SQLite mutation ran from a Vitest thread where the shared-state broker cannot admit writes. At 4df36ad, the overflow test asserts the exact-client clear; the SQLite reopen and stale/current-client clears run unweakened in a main-thread child host. Focused Vitest: 2 files, 5 tests passed; scoped oxlint, oxfmt, and diff whitespace checks passed. New exact-head CI is required before merge.

@clawsweeper

clawsweeper Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@KirDE
KirDE marked this pull request as ready for review September 9, 2026 14:57
@KirDE
KirDE force-pushed the fix/125308-binding-generation branch from a66d6f6 to c744017 Compare September 9, 2026 15:05
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 9, 2026
@clawsweeper

clawsweeper Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 30, 2026, 12:47 PM ET / 16:47 UTC (Revision 14).

ClawSweeper review

What this changes

The Codex plugin makes attempt-owned binding cleanup check both the native thread and physical app-server client, with regressions for successor bindings and cleanup after lost authority.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

Current main still permits stale cleanup to remove a successor Codex binding. The proposed owner check addresses that defect, and the latest commit repairs the test fixtures behind the prior failed shard. I found no remaining patch defect; exact-head checks were still running in the captured state.

Priority: P2
Reviewed head: 4df36ad996fc4006094a7c00a6fa8ec46a9a32a0

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The owner-level repair has strong boundary proof and focused regressions; exact-head required checks were still running in the captured state.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Earlier-head terminal evidence reported two physical app-server clients exercising the production attempt and SQLite binding path: stale cleanup preserved the successor, which resumed and started a turn. Production files are unchanged since the prior reviewed head; the latest test-fixture repair and exact-head CI are separate validation. The mutation adds a predicate without changing the stored format.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Earlier-head terminal evidence reported two physical app-server clients exercising the production attempt and SQLite binding path: stale cleanup preserved the successor, which resumed and started a turn. Production files are unchanged since the prior reviewed head; the latest test-fixture repair and exact-head CI are separate validation. The mutation adds a predicate without changing the stored format.
Evidence reviewed 8 items Current-main defect: The current main clear mutation checks the native thread ID and generation but has no physical-client predicate.
Introduced owner check: The pinned PR delta checks the physical client in the binding-store clear mutation, after the existing thread and generation checks.
Cleanup authority and settlement: Incognito cleanup passes the client ID and current-authority assertion to the binding mutation; the finally block releases remaining routes and leases.
Findings None None.
Security None None.

How this fits together

OpenClaw stores a Codex native-thread binding so later agent turns can resume the same conversation. Attempt cleanup may clear that binding and release the old client's route and lease.

flowchart LR
  A[Agent turn] --> B[Codex app-server client]
  B --> C[Stored native thread binding]
  D[Attempt cleanup] --> E{Thread and client match?}
  C --> E
  E -->|Yes| F[Clear old binding]
  E -->|No| G[Preserve successor binding]
  D --> H[Release old route and lease]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +118, Tests +518. Total +636 across 14 files.

View PR surface stats
Area Files Added Removed Net
Source 7 173 55 +118
Tests 7 522 4 +518
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 695 59 +636

Review metrics

Metric Value Why it matters
Regression coverage growth production +118 lines, tests and test support +518 lines The added cases cover distinct stale-owner, recovery, and SQLite reopen paths; the production growth includes a shared recovery helper.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #143187
Summary: This PR is the candidate fix for the linked stale-cleanup issue; the broader long-session report includes other distinct problems.

Members:

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

Technical review

Best possible solution:

Keep the exact-client check at the binding-store mutation and land the focused cleanup regressions once the required exact-head gates complete.

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

Yes. The linked issue gives a deterministic same-thread client-replacement sequence, and current-main source lacks the client check; I did not execute target code in this read-only review.

Is this the best way to solve the issue?

Yes. Checking the physical client at the existing binding-store mutation repairs the owner boundary without a new setting or stored format.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 870c5b6b7f97.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The patch repairs a bounded Codex session-continuity defect during physical-client replacement.
  • merge-risk: 🚨 session-state: Binding cleanup controls which native Codex conversation a later turn can resume.
  • 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. Sufficient (terminal): Earlier-head terminal evidence reported two physical app-server clients exercising the production attempt and SQLite binding path: stale cleanup preserved the successor, which resumed and started a turn. Production files are unchanged since the prior reviewed head; the latest test-fixture repair and exact-head CI are separate validation. The mutation adds a predicate without changing the stored format.
  • proof: sufficient: Contributor real behavior proof is sufficient. Earlier-head terminal evidence reported two physical app-server clients exercising the production attempt and SQLite binding path: stale cleanup preserved the successor, which resumed and started a turn. Production files are unchanged since the prior reviewed head; the latest test-fixture repair and exact-head CI are separate validation. The mutation adds a predicate without changing the stored format.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Sarah Fortune: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Jason (Json): 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 (13 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-17T09:50:47.989Z sha 031999a :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T11:00:05.337Z sha 9fb2d57 :: needs changes before merge. :: [P2] [P2] Preserve the full binding type in the recovery guard
  • reviewed 2026-09-17T11:21:03.530Z sha 7b5cfce :: needs maintainer review before merge. :: none
  • reviewed 2026-09-19T16:30:53.314Z sha e53cb7d :: blocked before merge. :: none
  • reviewed September 25, 2026, 6:33 AM ET / 10:33 UTC (Revision 10) sha unknown :: needs maintainer review before merge. :: none
  • reviewed September 25, 2026, 7:38 AM ET / 11:38 UTC (Revision 11) sha unknown :: blocked before merge. :: none
  • reviewed 2026-09-30T14:43:09.591Z sha faab967 :: blocked before merge. :: none
  • reviewed 2026-09-30T14:58:06.025Z sha 9687478 :: blocked before merge. :: none

@KirDE
KirDE force-pushed the fix/125308-binding-generation branch 2 times, most recently from aa83426 to e690652 Compare September 9, 2026 17:13
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Sep 9, 2026
@KirDE
KirDE force-pushed the fix/125308-binding-generation branch from e690652 to 68b6890 Compare September 9, 2026 18:18
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 9, 2026
# Conflicts:
#	extensions/codex/src/app-server/run-attempt-cleanup.ts
#	extensions/codex/src/app-server/run-attempt-turn-start.ts
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Sep 17, 2026
@clawsweeper clawsweeper Bot added 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. and removed 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. labels Sep 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 Sep 17, 2026
…generation

# Conflicts:
#	extensions/codex/src/app-server/run-attempt-turn-start.ts
#	extensions/codex/src/app-server/run-attempt.test.ts
steipete added a commit that referenced this pull request Oct 3, 2026
…164197)

Fence Codex native effects, binding mutations, and subscription cleanup to the initiating session lineage and exact physical client. A replaced session can no longer borrow a peer's process custody or clear a successor binding, including across worker CAS retries and delayed remote-file responses.

Use the existing database workers and authority cohorts, preserve synchronous released SDK contracts and reversible deletion vetoes, and retain main's shared bounded media reader. Regression proof covers physical writes, successor recovery, compaction, cleanup, and API compatibility.

Consolidates #156940 and the independently reimplemented physical-client checks from #143201. Unblocks compound PR2's native-binding authority work; executor settlement remains its required extension.

Co-authored-by: Galin Iliev <[email protected]>
Co-authored-by: KirDE <[email protected]>
@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Consolidated and landed in #164197 (283d5e6). The replacement independently reimplements this PR's physical-client checks inside the current worker-backed binding compare-and-swap flow, including captured absence and retries, so delayed cleanup cannot mutate a successor using the same native thread.

Thank you @KirDE. Your original commit-author credit is retained on the consolidating commit and the landed squash. The physical-client regressions include failing pre-fix controls; focused and broader Testbox proof, released-SDK checks, worker ratchet, zero-cycle Madge, P2 review, and final-head CI passed. Closing this PR as consolidated; its source branch is preserved.

@steipete steipete closed this Oct 3, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
…penclaw#164197)

Fence Codex native effects, binding mutations, and subscription cleanup to the initiating session lineage and exact physical client. A replaced session can no longer borrow a peer's process custody or clear a successor binding, including across worker CAS retries and delayed remote-file responses.

Use the existing database workers and authority cohorts, preserve synchronous released SDK contracts and reversible deletion vetoes, and retain main's shared bounded media reader. Regression proof covers physical writes, successor recovery, compaction, cleanup, and API compatibility.

Consolidates openclaw#156940 and the independently reimplemented physical-client checks from openclaw#143201. Unblocks compound PR2's native-binding authority work; executor settlement remains its required extension.

Co-authored-by: Galin Iliev <[email protected]>
Co-authored-by: KirDE <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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.

[Bug]: Codex stale cleanup can clear a successor physical-client binding

2 participants