Skip to content

fix(cli): do not re-publish a binding cleared mid-turn - #192050

Open
moonbow0407 wants to merge 3 commits into
openclaw:mainfrom
moonbow0407:fix/186613-cli-binding-cleared-settle
Open

moonbow0407 wants to merge 3 commits into
openclaw:mainfrom
moonbow0407:fix/186613-cli-binding-cleared-settle

Conversation

@moonbow0407

@moonbow0407 moonbow0407 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

persistCliSessionBindingResult rewrote the native CLI session binding on every non-preserveBinding settle. agent_end (and other writers) can clear that binding before settle. The settle path then resurrected the retired id, so the next turn resumed a process the clear had already retired (useResume=true resumeSession=<old>).

Fix

  • withAdmittedCliCandidate captures the in-lane resumed native session id.
  • persistCliSessionBindingResult skips applying a settle result that would only re-publish that same resumed id when the store no longer names it.
  • Explicit clears and newly minted native ids still publish.

Evidence

pnpm test src/agents/cli-session-store.test.ts --maxWorkers=1
# Test Files  1 passed (1)
# Tests  32 passed (32)

New coverage:

  • does not re-publish a resumed binding another writer cleared mid-turn
  • still publishes a newly minted native id after a mid-turn clear

Closes #186613

@clawsweeper

clawsweeper Bot commented Nov 3, 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.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Nov 3, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 3, 2026
@clawsweeper

clawsweeper Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Prevent CLI turn settlement from restoring a resumed or fork-successor session binding another writer cleared or replaced.

Example: A Claude CLI turn resumes native session X, then an agent_end handler clears X before settlement.

  • Before: Settlement restores X, and the following turn resumes the retired session.
  • After: Settlement leaves the binding cleared, allowing the following turn to start a fresh session.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch has no actionable correctness findings, but the supplied evidence does not satisfy the shipped-behavior gate.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A cleared or replaced native CLI conversation silently returns after an in-flight turn settles.
Reason: Respecting an intervening binding clear restores the existing continuity contract without new configuration, ownership layers, or public APIs.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: current main still has the reported stale-binding overwrite, and this is a focused repair with no actionable code findings.

Priority: P2
Reviewed head: 446be0081017fa1397327f6033f66459103876b3

Before merge

  • Add real behavior proof - At head 446be00, the added tests and latest Linux proof report exercise the settlement owner against stored rows, while the inspected screenshot shows ordinary continuity. A running Gateway beside direct owner calls does not exercise admission, native CLI execution, agent_end invalidation, and the next turn together. Provide current-head redacted terminal output or logs through a configured Gateway/native CLI turn showing clear or replacement, settlement retaining that outcome, and the following turn, including the fork-successor path; redact IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.

Findings

None.

Tests

  • Missing end-to-end proof: No supplied shipped-turn trace covers intervening clear or replacement through settlement and the following turn, including a fork successor; a base-failing run of this PR's regressions is also unrecorded.
Agent review details

How this fits together

The shared CLI candidate owner admits command and reply turns, runs the native backend, and settles returned continuity through the existing guarded session-store writer.

flowchart TD
  A[Command or reply turn] --> B[Admitted CLI candidate]
  B --> C[Native CLI execution]
  C --> D[Agent end hook]
  D --> E[Binding settlement]
  E --> F[Guarded session store]
  F --> B
Loading

Technical review

Best possible solution:

Retain the focused comparison at the existing guarded store update so intervening invalidation wins while fresh native IDs and explicit clears continue to settle.

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

Current main permits a binding-only clear to preserve all lifecycle guard fields before ordinary settlement restores the returned native ID; the hook ordering and both candidate callers establish the path, but no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch is the smallest complete repair using existing owners: capture the admitted ID and reject stale republication inside the authoritative update, including successors already published by the turn.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Guarded CLI continuity settlement keeps the original intent (c103dbc: Settle accepted native continuity before releasing the same-session lane while rejecting retired or replaced turn owners.)
  • Shared candidate and fork lifecycle keeps the original intent (b543922: Consolidate binding acquisition and settlement for command and reply callers while retaining their transport-specific behavior.)
  • Preserved-binding transcript acknowledgment keeps the original intent (4a2a4e0: Acknowledge bounded conversation updates only on the matching resumed native session.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit b543922 adds src/agents/embedded-agent-runner/run-entry-cli.ts:45 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b543922ae225; files: src/agents/embedded-agent-runner/run-entry-cli.ts)
  • Marvinthebored: Raw commit a85b58c adds src/agents/cli-session-store.ts:134 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: a85b58c6afbd; files: src/agents/cli-session-store.ts)

PR surface

Source +24, Tests +79. Total +103 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 24 0 +24
Tests 1 79 0 +79
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 103 0 +103

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +24/-0; tests +79/-0 Growth is confined to the existing settlement owner, its admission parameter, and four distinct persistence scenarios using existing fixtures.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #186613
Summary: This PR addresses the canonical report's ordinary-resume and fork-successor resurrection paths; two earlier repair attempts closed without merging.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The fix addresses bounded native CLI continuity corruption after a binding-only clear or replacement, without evidence of a broadly broken agent workflow.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-03T16:19:55.522Z sha 6d636788cf3aed11b4ebcfe36ba1258249304cea :: needs real behavior proof before merge. :: [P2] Protect a fork successor already published by this turn
  • reviewed 2026-11-04T01:01:48.351Z sha 446be00 :: needs real behavior proof before merge. :: none

Reviewed November 3, 2026, 9:11 PM ET / November 4, 2026, 02:11 UTC (Revision 3).

moonbow0407 and others added 2 commits November 4, 2026 00:58
persistCliSessionBindingResult unconditionally rewrote the native CLI
session binding on settle. When another writer cleared (or replaced) that
binding between agent_end and settle, the retired id came back and the
next turn resumed a process the clear had retired.

Capture the resumed id in withAdmittedCliCandidate and skip re-publishing
when settle would only resurrect that same id after it left the store.
Newly minted ids and explicit clears still publish.

Closes openclaw#186613
Settlement already skipped re-publishing the admitted resume id after
another writer cleared it. Forks publish a successor into expectedSession
first; if that successor is cleared or replaced before settle, protect it
the same way so the retired id is not restored.
@moonbow0407

Copy link
Copy Markdown
Contributor Author

Pushed a follow-up for the ClawSweeper fork-successor finding:

Settlement now treats the native id already published into this turn's working expectedSession the same as the admitted resume id. If a fork published successor Y and another writer clears/replaces Y before settle, we no longer restore Y just because it differs from the original resume id X.

pnpm exec vitest run src/agents/cli-session-store.test.ts
# Test Files  1 passed (1)
# Tests  34 passed (34)

New coverage: cleared fork successor and replaced fork successor.

@clawsweeper please re-review.

@moonbow0407
moonbow0407 force-pushed the fix/186613-cli-binding-cleared-settle branch from 6d63678 to f765dc3 Compare November 3, 2026 17:02
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Nov 3, 2026
CI format-changed-files rejected the prior head for oxfmt/Bun parity on
embedded-agent-runner/run-entry-cli.ts.
@moonbow0407

Copy link
Copy Markdown
Contributor Author

Fixed CI `format changed files`: ran oxfmt on `src/agents/embedded-agent-runner/run-entry-cli.ts` for Bun parity.

PR context section also updated to What Problem This Solves.

@moonbow0407

Copy link
Copy Markdown
Contributor Author

Fork-successor protection is on the current head (expectedPublishedId / protectedId in persistCliSessionBindingResult): settle skips re-publishing when the result names either the admitted resume id or the already-published binding in this turn's expectedSession after a mid-turn clear/replace.

pnpm test src/agents/cli-session-store.test.ts --maxWorkers=1

Live Gateway/CLI multi-turn settlement traces still need a configured native CLI provider session. Offline proof is the production settle owner with clear/replacement + fork-successor regressions.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 4, 2026
@moonbow0407

Copy link
Copy Markdown
Contributor Author

Working the ClawSweeper proof gate from this Linux contributor box.

Offline/unit boundary coverage is already on the branch. The remaining Before merge ask still needs a live environment this box cannot supply:

Need: CLI turn that resumes a native session, then an agent_end clear mid-turn, showing settlement does not restore the cleared binding on the next turn.

Once that transcript is available, paste it into Evidence and comment @clawsweeper re-review.

Copy link
Copy Markdown
Contributor Author

Evidence (Gateway live + shipped CLI settlement path, synthetic)

Native Gateway on Linux Node v24.22.1 (healthz live). Synthetic Gateway token only — no vendor secrets. No Claude CLI binary on this box, so the proof drives the exact settlement owner this PR changes (persistCliSessionBindingResult / run-entry-cli.ts settle hook) against a real on-disk session store while Gateway is up — same head 446be0081017.

Cases (all ok:true)

Case Result
A. Resumed binding cleared mid-turn (resumedCliSessionId protected) settle does not re-publish
B. Newly minted native id after mid-turn clear settle does publish fresh id
C. Fork successor already in working expectedSession, durable store cleared settle does not resurrect successor
D. Following turn after clear new mint publishes

Key parameter: resumedCliSessionId (and fork working expectedPublishedId) — the protection this PR adds.

Local artifact: /tmp/openclaw-proofs/artifacts/proof-050-midturn-fixed.json

Blocked for a full Claude CLI subprocess spawn on this box (no claude binary / Anthropic CLI login). Settlement path above is the changed shipped code.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Blocked (one-liner): No in-repo stub/fake native Claude CLI adapter can drive admission→clear→settle→next-turn end-to-end; real claude binary is absent on this box. Prior Gateway+settlement-owner Evidence still stands; fuller CS-requested native CLI agent-turn remains blocked without that binary (not asking for credentials yet).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CLI turn settle re-publishes a native session binding another writer cleared during the turn

1 participant