Skip to content

fix(agents): keep a native CLI binding cleared by another writer - #186624

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

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

Conversation

@yy19971996

@yy19971996 yy19971996 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #186613

What Problem This Solves

A CLI turn that resumed native session X republishes X when it settles, even if another writer cleared or replaced that binding while the turn ran. The cleared binding comes back and the next turn resumes a native process the other writer retired.

Why This Change Was Made

persistCliSessionBindingResult stored a resumed result binding unconditionally in the non-preserveBinding path. The store guard only compared local sessionId / lifecycleRevision / activeWriterRunId, so a binding-only clear or replacement never fenced the write. Settlement now republishes the admitted native id only while the stored binding still names it; a newly minted native id and explicit clear results keep their current behavior, which is the contract the issue asked for.

User Impact

Clearing a CLI session binding (plugin agent_end, operator clear, or another writer replacing it) now sticks instead of being silently undone by the turn that was already running. No change for brand-new native ids, for clearCliSessionBinding results, or for preserveBinding completions.

Evidence

Runtime proof through the production store boundary (node --import ./scripts/tsx.mjs, real SQLite session store, no mocks), red on origin/main and green on this head 80b89b963:

before (origin/main c7db2804):

$ OPENCLAW_STATE_DIR=... node --import ./scripts/tsx.mjs .proof-186613.mts
cleared by other writer -> binding after settle: native-resumed
replaced by other writer -> binding after settle: native-resumed

after (80b89b963):

$ OPENCLAW_STATE_DIR=... node --import ./scripts/tsx.mjs .proof-186613.mts
cleared by other writer -> binding after settle: undefined
replaced by other writer -> binding after settle: native-other-writer

Regression rows in the store owner's stale-publication table (real temp session store), red on base and green here:

$ node scripts/run-vitest.mjs src/agents/cli-session-store.test.ts --run -t "rejects a stale"   # origin/main
 Tests  2 failed | 8 passed | 25 skipped (35)
   × rejects a stale publish after the durable row is binding-cleared
   × rejects a stale publish after the durable row is binding-replaced

$ node scripts/run-vitest.mjs src/agents/cli-session-store.test.ts --run -t "rejects a stale"   # 80b89b963
 Tests  10 passed | 25 skipped (35)
Case Before After
Another writer clears the binding mid-turn native-resumed resurrected stays cleared
Another writer replaces the binding mid-turn overwritten back to native-resumed keeps the other writer's id
Newly minted native id published published (unchanged)
Explicit clearCliSessionBinding result cleared cleared (unchanged)

Test-line ratchet: the new rows are folded into the existing stale-publication table, +6/-6 lines, so check:test-lines-ratchet reports net delta: 0. On this head checks-fast-baseline-ratchets passes (12m28s) and PR context and evidence passes (25s); the earlier review's test-line finding described commit 38a03e58, before the rows were folded.

Evidence gap: this environment cannot run the CLI-harness turn that this report needs end to end. OpenClaw's CLI runner spawns its backend with kernel-level process-tree ownership; here every spawned child aborts at ~1.8s with stdio startup cleanup did not confirm closure | native owner closed without kernel descendant extinction, reproduced with a three-line stub command as well, so it is not specific to any backend binary. Both the direct store boundary above and the red/green table rows therefore stop one layer below a shipped CLI turn. A real claude CLI turn against a live model was verified standalone outside the runner, but not through the product path.

AI Assistance

This PR is AI-assisted. Used source reading, the repo's vitest store harness, and a throwaway node --import tsx script against a real SQLite session store to reproduce the resurrection on base and confirm the guard. The implementer understands the code: settlement may publish only the native id it resumed while that binding is still present, so a concurrent clear or replacement wins. All evidence above is from local runtime execution.

@clawsweeper

clawsweeper Bot commented Oct 28, 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.

@yy19971996
yy19971996 marked this pull request as ready for review October 28, 2026 07:42
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Oct 28, 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. labels Oct 28, 2026
@clawsweeper clawsweeper Bot added 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. labels Oct 28, 2026
@clawsweeper

clawsweeper Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Prevent CLI settlement from restoring a resumed native session binding that another writer cleared or replaced.

Example: A turn resumes native-resumed, and another writer replaces its binding with native-other-writer.

  • Before: Settlement overwrites the replacement with native-resumed.
  • After: Settlement keeps native-other-writer.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The production guard is focused and source-supported, but required shipped-path proof is absent and duplicate test growth leaves an attributable CI failure.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An intentional CLI conversation reset is silently undone, so the next turn resumes retired native context.
Reason: The reported production failure warrants a narrow repair using the existing continuity owner without new settings or product policy.

Merge readiness

⛔ Blocked before merge - 2 items remain

This PR addresses a current CLI continuity bug with a focused store guard, but its added tests cause a failing CI gate.

Priority: P2
Reviewed head: 38a03e58baae5c2e6be0fbcce89e15a9e0b36475

Before merge

  • Add real behavior proof - The supplied terminal output exercises persistCliSessionBindingResult against real SQLite and demonstrates clear/replacement preservation, but it bypasses shipped candidate admission, native CLI execution, and the following turn. Supply redacted terminal output or logs for that Gateway/CLI scenario, removing 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.
  • Consolidate the added tests to clear the failing test-line gate (P2) - The final diff still adds 18 net test lines, despite the PR body's claim that the table conversion leaves zero growth. Exact-head CI identifies test-lines as the failed baseline ratchet, whose implementation rejects positive growth while the tree exceeds its ceiling. The standalone clear/replacement group repeats the new table rows. Remove that duplication and consolidate the distinct fresh-ID control into existing publication coverage so the regression retains its assertions and the required gate passes.

Findings

  • [P2] Consolidate the added tests to clear the failing test-line gate — src/agents/cli-session-store.test.ts:492-500

Tests

  • Low-value test src/agents/cli-session-store.test.ts: The standalone clear/replacement group at lines 492–502 repeats the two newly added stale-publication table rows with weaker durable-ID-only assertions; remove that duplicate group while retaining the distinct newly minted ID control.
  • Missing end-to-end proof: Provide redacted shipped Gateway/CLI output showing a mid-turn binding clear or replacement surviving settlement and determining the next turn's native session.
Agent review details

How this fits together

Command and channel turns share CLI candidate admission; native execution returns binding metadata that the session-store owner commits before releasing the turn.

flowchart TD
  A[Command or channel turn] --> B[CLI candidate admission]
  B --> C[Native CLI execution]
  C --> D[Binding settlement]
  E[Other writer clears or replaces binding] --> F[SQLite session store]
  D --> F
  F --> G[Next turn continuity]
Loading

Technical review

Best possible solution:

Keep the existing store guard and consolidate its regressions without duplicating clear/replacement coverage or weakening fresh-ID publication.

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

Current-main source exposes unconditional republication after a binding-only clear or replacement, supported by the reporter's observations and contributor's red/green store results; this read-only review executed no target code.

Is this the best way to solve the issue?

Checking binding identity at the existing settlement owner is the smallest production fix and preserves fresh recovery, explicit invalidation, preserved completions, and owned fork successors.

Full review comments:

  • [P2] Consolidate the added tests to clear the failing test-line gate — src/agents/cli-session-store.test.ts:492-500
    The final diff still adds 18 net test lines, despite the PR body's claim that the table conversion leaves zero growth. Exact-head CI identifies test-lines as the failed baseline ratchet, whose implementation rejects positive growth while the tree exceeds its ceiling. The standalone clear/replacement group repeats the new table rows. Remove that duplication and consolidate the distinct fresh-ID control into existing publication coverage so the regression retains its assertions and the required gate passes.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/agents/cli-session-store.test.ts --maxWorkers=1
  • pnpm test src/agents/command/attempt-execution.cli.test.ts --maxWorkers=1
  • pnpm test src/agents/cli-runner/history-boundary.test.ts --maxWorkers=1
  • pnpm check:test-lines-ratchet --base 8ea0a67
  • pnpm check:changed

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 4a2a4e0 adds src/agents/cli-session-store.ts:248 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4a2a4e0eb5da; files: src/agents/cli-session-store.ts)
  • Marvinthebored: Raw commit a85b58c adds src/agents/cli-session-store.ts:139 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a85b58c6afbd; files: src/agents/cli-session-store.ts)

PR surface

Source +12, Tests +18. Total +30 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 12 0 +12
Tests 1 24 6 +18
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 36 6 +30

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #186613
Summary: Two open PRs address the same unconditional binding republication; neither establishes a safely landable replacement for the other.

Members:

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

Labels

Label changes:

  • add P2: A bounded CLI continuity defect silently restores retired conversation state; the proposed repair has a focused test-budget blocker.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: A bounded CLI continuity defect silently restores retired conversation state; the proposed repair has a focused test-budget blocker.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • 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.

Reviewed October 28, 2026, 4:16 AM ET / 08:16 UTC.

@yy19971996

Copy link
Copy Markdown
Contributor Author

Closing: the shipped-CLI evidence this report needs cannot be produced in the environment available to me.

The CLI-harness turn never reaches settlement here. OpenClaw's runner spawns its backend with kernel-level process-tree ownership, and this host cannot become a child subreaper:

$ node --input-type=module -e 'import("@openclaw/proc-safe/reaper").then(m=>{try{m.becomeChildSubreaper();console.log("OK")}catch(e){console.log("BLOCKED:",e.message)}})'
BLOCKED: helper-unavailable  native child reaping is unavailable

so every backend child aborts at ~1.6s with stdio startup cleanup did not confirm closure | native owner closed without kernel descendant extinction. Reproduced from an ordinary shell (not only an agent sandbox), with the built dist entry and the source entry, and with a three-line stub command instead of claude, so it is the host, not the backend. danger-full-access does not change it.

What I could verify, for the record:

  • A real claude CLI turn against a live model works standalone ({"result":"OK","modelUsage":["deepseek-chat"]}) and OpenClaw selects the backend correctly (cli live session start: provider=claude-cli model=deepseek-chat), but the run is killed before persistCliSessionBindingResult.
  • The red/green store regressions and the direct-store before/after output in the body are unchanged and still stand.

The production change on fix/186613-cli-settle-binding (head 80b89b963) is unaffected and remains available if a host with process-tree ownership becomes available; I can reopen or resend it then. The sibling report fix #186625 addresses the same root cause and remains open.

Thanks for the review — the test-line consolidation finding was addressed at 80b89b963 (checks-fast-baseline-ratchets passes on that head).

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: XS 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