Skip to content

fix(agents): preserve CLI continuity for queued cold turns - #136644

Merged
steipete merged 4 commits into
mainfrom
fix/cli-binding-settlement
Sep 2, 2026
Merged

steipete merged 4 commits into
mainfrom
fix/cli-binding-settlement

Conversation

@steipete

@steipete steipete commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Related: #136423 (busy-parent subagent completion admission), #134186, #135192.

What Problem This Solves

Fixes an issue where users queueing another turn on a CLI-backed session could lose native conversation continuity when the next turn started in a fresh CLI process. It also prevents a retired or rejected run from overwriting the continuation that a later turn should use.

Why This Change Was Made

Native continuation now settles before the same-session admission lane releases, with the exact live placement/turn assertion carried to the existing synchronous store commit. Command, reply, and cron share that ownership rule; duplicate late writers and clear helpers are removed. Local OpenClaw session IDs remain distinct from native CLI IDs, and only the explicit native binding result is persisted.

Accepted fallback candidates may publish continuity. Explicit invalid-binding cleanup still works after abort while that exact owner remains live; closed/replaced owners cannot publish or clear. Cron stages the result until its guarded base commit succeeds so later finalization cannot resurrect a rejected write. Keeping all post-run accounting under the lane would instead risk deadlocking compaction, which can itself enter that lane. This changes no config, environment, database schema, stored representation, protocol, or dependency.

User Impact

Queued CLI turns resume the preceding accepted native conversation even without a warm CLI process. Aborted, replaced, or rejected candidates cannot silently poison later continuation. Embedded session rollover, provenance-preserved turns, explicit native invalidation, and compaction remain covered.

This is the separately scoped follow-up to #136423; it does not claim to repair the unrelated bootstrap migration, Telegram ingress, or Discord display-size allegations from the original reports. Thanks to Sean van der Walt (@svdwalt007), @Isitjustmefromparis, and @Tony-Clawbot for the reports that led to the admission and continuity investigation.

Evidence

Validated head: c4102b45bdc5f43704e4af8987503f7e46550b6c. Exact-head CI is green; changed checks, types, lint, three dead-code scans, runtime/UI build, and the refreshed before/after Gateway fallback proof passed. Branch review completed with no accepted findings after direct source validation. The proposed storeless-publication gap was rejected: the old writer also returned without a store path, and normal reply sessions supply the canonical path.

  • The new real outer-fallback regression failed on 3893ade22c24d6c4c6964a4ff524ffb101b4ff20: the queued cold command received no native binding. The real Gateway/Control UI direct agent RPC probe on that same immutable build also visibly returned FALLBACK_COLD_RESUME_MISSING.
  • The correction passed 259 wrapper-driven tests (CLI 141, session store 99, reply result handling 19). After two typed fixture corrections, all six cold-turn cases, core-test types, type-aware lint, and scoped review through P2 passed. The six cases include accepted fallback, heartbeat preservation, and explicit session-state preservation.
  • Earlier grouped owner regression suites passed 487 tests on rebased implementation 0a0f0cc96b6d0221be7c3d264223cd00ec99eea8; later typed-fixture and mechanical changes were checked separately. The existing live transcript below is explicitly the previous 3893ade22c24 reply-path proof; the new head's direct-command fallback proof is linked above.

Review correction and CI follow-up

ClawSweeper's accepted-fallback finding and both rank-up moves are addressed in c4102b45bdc5f43704e4af8987503f7e46550b6c: native continuation no longer inherits provider/model display-preservation conditions, and the regression traverses the real runEmbeddedAgentAttempt fallback owner before queueing the next cold command. Heartbeat and explicitly preserved turns still retain the original binding. This coupling also existed in the base commit's late writer; the change repairs it without attributing introduction to this PR or a contributor.

The old CI head exposed three reply fixtures that bypassed candidate execution and therefore had no recorded classification; those fixtures now execute the candidate and pass without adding production reclassification. One unrelated Copilot cleanup test also failed: its real 5 ms deadline can expire before createSession starts. Named follow-up: make that late-session cleanup fixture trigger its deadline after session creation starts using a controlled clock, not a larger timeout. This is a source-backed timing-flake inference, not a locally reproduced defect; the new-head CI run is now green.

The original cold-process regression queued the second command before the first returned with no warm session registry; the second command received no native binding before the fix. That initial terminal output was captured, but no complete raw tee log was retained. Later full-log regressions cover cold invalidation, rejected fallback candidates, queue reset, exact-owner clear/fork writes, cron rejected-commit followed by finalization, and local/native ID separation. The real-builder scalar-ID test is a before/after correction of the proposed canonical owner, not an unchanged-main run. Introduction provenance is unknown; this PR does not attribute the defect to a particular contributor.

Final-head live fallback transcript (c4102b45bdc5)

The same real Gateway and Control UI flow that failed before the fallback correction now passes. An explicitly synthetic one-shot CLI backend uses existing plugin/auth contracts; two direct agent RPC requests from the connected Control UI client each encounter primary capacity failure and complete through the fallback. No warm process, provider credentials, operator state, or product-source fixture changes were used.

22:44:41.138Z first cold fallback starts, pid=5538
22:44:57.385Z second same-session request accepted while first fallback is alive
22:45:11.925Z first fallback exits
22:45:12.136Z Control UI receives FIRST_FALLBACK_FINISHED assistant final
22:45:12.575Z second cold fallback starts, pid=14988, exact native handle resumed
22:45:12.759Z Control UI receives FALLBACK_COLD_RESUME_OK assistant final
ActiveTurnClaimError: 0

The verifier requires matching commit/build metadata and actual Control UI/Gateway handshake build IDs, correlated accepted and final RPC payloads, same-session assistant-final events, four one-shot processes, and exact native reuse. Queue acceptance alone is not delivery. Inspected synthetic-only before/after screenshots and full proof summary. The owned Gateway and browser exited cleanly, isolated state was removed, and the port was verified free. Latest ClawSweeper rank-up moves (exact-head CI and refreshed fallback trace) are complete.

Previous-head isolated live transcript (3893ade22c24)

Real Gateway, canonical session store, and Control UI; explicitly synthetic one-shot CLI dependency using the existing plugin backend and local synthetic-auth discovery contracts. No warm CLI session registry, credentials, operator state, or product source changes were used for the fixture. The first request used the normal composer; the second used the connected Control UI client's normal chat.send API with queueMode: followup so it reached the Gateway while the first process was busy.

21:41:43.177Z first cold CLI starts, pid=50468, no prior native handle
21:41:56.140Z second same-session chat.send accepted while first CLI is alive
21:42:04.833Z fixture releases first CLI
21:42:04.840Z first CLI exits
21:42:04.883Z Control UI receives FIRST_COLD_CLI_FINISHED assistant final
21:42:05.072Z second cold CLI starts, pid=53275, --resume=<exact first native handle>
21:42:05.076Z second CLI exits
21:42:05.113Z Control UI receives COLD_RESUME_OK assistant final
ActiveTurnClaimError: 0

Queued admission and execution have distinct run IDs; the Gateway's recorded chat.send_timing.agentRunId mapping connects the accepted second request to its actual assistant final. Queue acceptance alone is not counted as delivery. This live run verifies the user flow after the fix; the deterministic original-order regressions establish the pre-fix race. The parent PR separately contains the real Claude busy-parent completion/abort roundtrip.

Production LOC: +479/-323 (net +156); tests/support: +989/-306 (net +683). Growth supplies the previously missing exact-owner synchronous commit contract and one recorded candidate-classification decision; removed late publication paths and consolidated clearing offset it. Existing continuity behavior is documented at https://docs.openclaw.ai/gateway/cli-backends.

Two actual Control UI assistant finals from distinct cold CLI processes using the same native handle

@clawsweeper

clawsweeper Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Sep 2, 2026
@steipete
steipete marked this pull request as ready for review September 2, 2026 21:45
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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 2, 2026
@clawsweeper

clawsweeper Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 2, 2026, 6:32 PM ET / 22:32 UTC.

ClawSweeper review

What this changes

Preserves the accepted CLI session binding when a queued cold turn falls through to a successful fallback, while fencing persistence to the live session lifecycle and turn settlement.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep open: the exact-head implementation addresses the prior accepted-fallback continuity concern, but it is not on current main and exact-head CI plus a refreshed runtime probe remain pending.

Priority: P1
Reviewed head: c4102b45bdc5f43704e4af8987503f7e46550b6c

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The owner-boundary repair and focused coverage are solid, while exact-head runtime proof and CI are still incomplete.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Evidence reviewed 7 items Guarded persistence owner: The new persistence helper requires the matching session ID, lifecycle revision, and active writer run before changing a CLI binding, and supplies an abort/settlement assertion for the write.
Command and reply callers: Both command and reply paths classify the accepted candidate and persist or clear the binding under the local placement settlement boundary; the command path reloads its admission snapshot after queueing.
Commit-edge validation: The SQLite session accessor re-reads the authoritative snapshot and invokes the supplied commit assertion inside the write transaction before persisting the binding.
Findings None None.
Security None None.

How this fits together

Queued agent turns use a stored CLI session binding to resume continuity after admission. This change classifies the accepted CLI result and commits its binding only while the admitted session and writer still own settlement.

flowchart TD
  Result[CLI candidate result] --> Classify[Classify accepted result]
  Session[Admitted session lifecycle] --> Guard[Settlement commit guard]
  Classify --> Guard
  Guard --> Binding[Stored CLI session binding]
  Binding --> NextTurn[Next queued cold turn]
  Lifecycle[Abort or replacement] --> Guard
Loading

Before merge

  • Resolve merge risk (P1) - The bug fix adds 156 net production lines; its shared guarded persistence owner consolidates late command, reply, and cron writers, but exact-head validation should confirm that it does not duplicate lifecycle policy.
  • Resolve merge risk (P1) - Persisted CLI session binding and clearing now occur at settlement boundaries, so an unexercised exact-head ordering error could preserve stale session state across queued turns.
  • Complete next step (P2) - Wait for exact-head CI and a refreshed isolated fallback-continuity probe before merge.
Agent review details

Security

None.

PR surface

Source +156, Tests +683. Total +839 across 39 files.

View PR surface stats
Area Files Added Removed Net
Source 23 479 323 +156
Tests 16 989 306 +683
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 39 1468 629 +839

Review metrics

Metric Value Why it matters
Production versus test delta production +479/-323 (net +156); tests/support +989/-306 (net +683) The production growth implements the shared lifecycle-fenced persistence boundary; the larger test change covers fallback, clearing, replacement, and queue ordering.

Root-cause cluster

Relationship: canonical
Canonical: #136644
Summary: This PR is the active implementation for queued cold-turn CLI continuity; the merged busy-parent completion repair is adjacent but distinct.

Members:

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

Merge-risk options

Maintainer options:

  1. Validate the exact head (recommended)
    Complete exact-head CI and demonstrate an accepted fallback preserving the binding into the next queued cold CLI turn before merge.

Technical review

Best possible solution:

Retain one guarded persistence owner with cached accepted-candidate classification, then complete exact-head CI and an isolated queued-fallback continuity probe.

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

No high-confidence current-main runtime reproduction was run in this read-only review; the affected fallback path and its regression scenarios are directly defined by source and focused tests.

Is this the best way to solve the issue?

Yes: the branch records the accepted native binding at the lifecycle owner’s synchronous settlement edge instead of leaving command, reply, and cron paths to retain it independently.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1703bd765298.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: This repairs session continuity for queued CLI turns, where losing the accepted fallback binding disrupts follow-up work.
  • merge-risk: 🚨 session-state: The PR changes when a durable CLI session binding is written or cleared relative to lifecycle replacement and turn settlement.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.

Evidence

Acceptance criteria:

  • [P1] Exact-head CI.
  • [P2] Isolated CLI parent/fallback/queued-cold-turn continuity probe.

What I checked:

Likely related people:

  • unknown: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Complete exact-head CI.
  • Capture an isolated CLI fallback-to-queued-cold-turn trace at the current head.

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 (1 earlier review cycle)
  • reviewed 2026-09-02T21:55:58.413Z sha 3893ade :: blocked before merge. :: [P1] Persist accepted fallback CLI bindings

Separate command native-session preservation from displayed fallback model
preservation. Successful fallback candidates publish their continuation
before the session lane releases, while heartbeat and explicitly preserved
turns retain the prior native binding.

Exercise the real outer fallback path followed by a queued cold command,
and have result-classifier fixtures execute the candidate before reading
its recorded classification.
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 2, 2026
@steipete

steipete commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Exact-head validation is complete for c4102b45bdc5f43704e4af8987503f7e46550b6c.

CI run 33689995303 is green. Changed checks, core/test types, type-aware lint, three dead-code scans, and the matching runtime/UI build passed. Branch review has no accepted findings after direct source validation; the proposed storeless-publication gap was rejected because the old writer also returned without a store path and production reply sessions supply a canonical path.

The refreshed live proof uses a real isolated Gateway and Control UI with an explicitly synthetic one-shot CLI backend. Two direct agent requests from the connected Control UI client exercise the command's real outer fallback path. Each primary attempt reports capacity failure; each fallback runs in a fresh process. The verifier matches the recorded commit to both actual Control UI and Gateway handshake build IDs, correlates accepted requests with their final payloads, and checks process order and exact native reuse.

Before fallback correction, head 3893ade22c24:
second request accepted while first fallback was busy
second cold fallback received no resume handle
Control UI final: FALLBACK_COLD_RESUME_MISSING

After correction, head c4102b45bdc5:
22:44:41.138Z first cold fallback starts, pid=5538
22:44:57.385Z second same-session request accepted while first fallback is alive
22:45:11.925Z first fallback exits
22:45:12.136Z first final payload: FIRST_FALLBACK_FINISHED
22:45:12.575Z second cold fallback starts, pid=14988, exact first native handle resumed
22:45:12.759Z second final payload: FALLBACK_COLD_RESUME_OK
ActiveTurnClaimError: 0

Queue acceptance is not counted as delivery: both correlated assistant finals were received and displayed. Screenshots below are entirely synthetic. The previous reply-path cold-process proof remains in the PR body; this refreshed proof additionally covers the command-side fallback correction. The latest ClawSweeper rank-up moves—exact-head CI and refreshed fallback-to-queued-cold-turn proof—are now complete.

Before the fallback correction at 3893: the queued cold CLI loses native continuity

After the fallback correction at c410: the queued cold CLI resumes the exact native handle

@steipete
steipete merged commit c103dbc into main Sep 2, 2026
242 checks passed
@steipete
steipete deleted the fix/cli-binding-settlement branch September 2, 2026 22:54
@steipete

steipete commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 3, 2026
…136644)

* fix(agents): settle CLI continuity before session lane release

* test(agents): use typed CLI provider in continuity fixture

* style: satisfy CLI settlement lint checks

* fix(agents): retain accepted fallback CLI continuity

Separate command native-session preservation from displayed fallback model
preservation. Successful fallback candidates publish their continuation
before the session lane releases, while heartbeat and explicitly preserved
turns retain the prior native binding.

Exercise the real outer fallback path followed by a queued cold command,
and have result-classifier fixtures execute the candidate before reading
its recorded classification.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL 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.

1 participant