Skip to content

fix: stop delayed chat commands crossing gateway reconnects - #118019

Merged
shakkernerd merged 39 commits into
mainfrom
fix/chat-session-command-lifecycle
Aug 3, 2026
Merged

shakkernerd merged 39 commits into
mainfrom
fix/chat-session-command-lifecycle

Conversation

@shakkernerd

Copy link
Copy Markdown
Contributor

Related: #117786

What Problem This Solves

Fixes an issue where Control UI chat session commands could outlive the Gateway connection, session selection, or authorization context in which the operator started them.

Commands delayed by session-state loading, reset confirmation, an active run, or durable queue delivery could otherwise continue after a reconnect. In particular, a queued /reset could be applied to a replacement Gateway, and the first send after /clear could retain a stale branch precondition from the destroyed conversation.

Why This Change Was Made

Chat slash commands now check the connected Gateway's advertised methods and current operator scopes before mutation, then retain the originating client, connection epoch, session key, and agent across asynchronous work. /reset requires operator.admin, matching the Gateway lifecycle it triggers, and its captured target is carried through durable queue delivery so a reconnect cannot redirect it.

The reset and clear paths also distinguish confirmed, rejected, and ambiguous outcomes. Ambiguous reset sends are not replayed, while /clear removes an obsolete active-leaf precondition only after the original connection returns authoritative empty history for the same visible session.

This is the chat-command lifecycle portion split from #117920. The first PR owns the shared session authorization policy and general Control UI controls; this PR owns slash-command dispatch, queued delivery, reset confirmation, reconnect handling, and post-clear history state.

User Impact

Operators can continue using /model, /think, /compact, /clear, and /reset without a delayed command mutating a replacement Gateway or a different selected session.

Queued resets remain reviewable after interruption instead of being replayed, permission changes are rechecked immediately before mutation, and the first message after a successful clear starts a fresh branch without carrying stale conversation state.

No Gateway protocol, storage schema, or configuration surface changes are introduced.

Evidence

  • Blacksmith Testbox run 30752889490 passed the exact-head changed gate, including production, test, and Control UI types; lint; formatting; dead exports; runtime import cycles; and architecture guards.
  • Focused chat command, delivery, and send suites passed 345 tests on exact head 65bd4d99ca7.
  • A release-shaped OCM package runtime built from exact head and ran in Chrome against a disposable Gateway environment.
  • Live direct /reset completed with Session reset. through the packaged Control UI.
  • Live queued /reset was held during an active run, the Gateway was restarted, and the interrupted run recovered without executing the reset on the replacement connection.
  • Live /clear proof on the behavior-equivalent pre-extraction head accepted the first post-clear message without the stale active-leaf precondition.
  • Fresh independent review of the exact final patch reported no blocking findings.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui size: L maintainer Maintainer-authored PR labels Aug 2, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 3, 2026, 1:41 AM ET / 05:41 UTC.

ClawSweeper review

What this changes

The PR captures the originating Gateway connection, session, agent, and authorization for delayed Control UI slash commands and queued resets, preventing reconnects from redirecting a mutation or retaining stale post-clear state.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep this maintainer-authored PR open. Current main still leaves /reset outside the connection/session ownership fence applied to other slash commands, and the branch addresses that real lifecycle gap; the remaining blocker is explicit maintainer acceptance of the stricter admin-gated reset behavior and final-head verification after the branch’s latest commits.

Priority: P2
Reviewed head: b48afe893a693688e6229ca905c137dd0b4059ca
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The proposed repair follows the current connection-ownership and Gateway-scope model, but final-head source blobs were unavailable locally and the permission contract requires maintainer judgment.
Proof confidence 🌊 off-meta tidepool Not applicable: The PR author is a repository MEMBER, so the external-contributor proof gate does not apply; the body nevertheless reports packaged Control UI and reconnect proof, but the final proof artifact could not be independently retrieved in this network-restricted review.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The PR author is a repository MEMBER, so the external-contributor proof gate does not apply; the body nevertheless reports packaged Control UI and reconnect proof, but the final proof artifact could not be independently retrieved in this network-restricted review.
Evidence reviewed 5 items Current-main lifecycle gap: Current main confirms /reset only against the visible session and then calls the reset sender without capturing the Gateway client or connection epoch; the non-reset command path below it does capture and validate client, epoch, session, and agent. This supports the reported reconnect-redirection defect.
Gateway authorization contract: The shared Control UI access helper rejects disconnected or explicitly unavailable methods, checks advertised scopes, and preserves behavior for older Gateways that omit scope metadata. Its chat action mapping defines sessions.reset as an operator.admin action, supporting the PR’s intended authorization boundary.
Existing reconnect regression coverage: Current main already has a focused regression that abandons stale reconnect history after the connection epoch changes, confirming connection epochs are the established ownership primitive for this chat lifecycle.
Findings None None.
Security None None.

How this fits together

Control UI chat converts slash commands and queued sends into Gateway session mutations. The changed path spans command confirmation, durable outbox delivery, reconnect handling, and chat-history refresh, so delayed work must remain bound to the Gateway and session that initiated it.

flowchart LR
  Operator[Control UI operator] --> Command[Slash command]
  Command --> Confirm[Confirmation and access check]
  Confirm --> Target[Capture Gateway and session target]
  Target --> Queue[Delayed or queued delivery]
  Queue --> Recheck[Connection and scope recheck]
  Recheck --> Mutation[Gateway session mutation]
  Mutation --> History[Refresh visible chat history]
Loading

Decision needed

Question Recommendation
Should Control UI /reset require operator.admin, matching the Gateway sessions.reset lifecycle action, even for operators who previously could submit the chat command without that UI-side gate? Adopt the admin-aligned reset boundary: Approve the PR’s stricter /reset gate so delayed resets share the Gateway’s lifecycle authorization and reconnect fence.

Why: The source confirms that direct session reset is an admin-scoped Gateway action, while the current slash-command reset path does not apply that access check. Aligning them improves authorization consistency but deliberately changes what write-scoped operators can initiate from chat.

Before merge

  • Resolve merge risk (P1) - The PR changes an existing Control UI /reset path from an ungated chat-command flow to an explicitly admin-gated session lifecycle action; maintainers should confirm that this intentional restriction is the desired operator-facing contract.
  • Resolve merge risk (P1) - The latest PR head’s changed blobs could not be read from the partial local clone because its required promisor fetch failed without network access, so this review cannot independently verify all final formatting and the last post-proof edits.
  • Resolve merge risk (P1) - The latest-head CI still has multiple in-progress checks in the supplied context; this is not a correctness finding, but landing should wait for the normal exact-head checks to settle.
Agent review details

Security

None.

PR surface

Source +532, Tests +1258, Docs +1. Total +1791 across 31 files.

View PR surface stats
Area Files Added Removed Net
Source 21 696 164 +532
Tests 9 1280 22 +1258
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 31 1977 186 +1791

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: ui/src/lib/sessions/index.test.ts, serialized state: ui/src/lib/sessions/index.ts, serialized state: ui/src/lib/sessions/list-options.test.ts, serialized state: ui/src/lib/sessions/patch.ts, serialized state: ui/src/lib/sessions/session-capability.ts, serialized state: ui/src/lib/sessions/session-key.test.ts, and 5 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: canonical
Canonical: #118019
Summary: This PR is the canonical remaining implementation for the delayed slash-command and queued-reset lifecycle work intentionally split from the already-merged shared authorization change.

Members:

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

Mantis proof suggestion

A redacted Control UI chat proof can directly demonstrate that a queued /reset does not execute after a Gateway reconnect, complementing the source and automated coverage. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis web UI chat proof: reproduce a queued /reset across a Gateway reconnect and capture redacted evidence that it does not mutate the replacement connection.

Merge-risk options

Maintainer options:

  1. Approve the admin-aligned reset contract (recommended)
    Accept the stricter Control UI /reset permission after confirming that write-scoped operators should no longer initiate this reset path.
  2. Separate permission policy from reconnect repair
    Retain the connection/session fencing but remove or redesign the reset permission change if maintainers intend to preserve the existing operator workflow.
  3. Pause for a narrower policy decision
    Do not merge the large lifecycle bundle until the permanent Control UI reset authorization contract is explicitly settled.

Technical review

Best possible solution:

Keep one canonical connection-ownership fence for delayed chat commands and queued resets, use the existing Gateway scope contract for mutations, and land after maintainers explicitly accept the /reset admin boundary and current-head validation is green.

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

Yes, from current source: /reset confirms only visible-session identity and then sends without retaining the initiating client or connection epoch, whereas other slash commands capture both before asynchronous work. A focused regression should hold reset confirmation or queued delivery, replace the Gateway client/epoch, and assert that no reset reaches the replacement connection.

Is this the best way to solve the issue?

Unclear pending the permission decision: binding delayed work to its initiating Gateway/session is the correct owner-boundary repair, but whether /reset must also become admin-only is an intentional operator-policy choice rather than a mechanical bug fix.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR author is a repository MEMBER, so the external-contributor proof gate does not apply; the body nevertheless reports packaged Control UI and reconnect proof, but the final proof artifact could not be independently retrieved in this network-restricted review.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This fixes a bounded but meaningful Control UI session-mutation lifecycle defect rather than an emergency availability or data-loss incident.
  • merge-risk: 🚨 compatibility: The branch introduces an explicit admin requirement for an existing Control UI /reset workflow.
  • merge-risk: 🚨 session-state: The patch changes how delayed commands, reset delivery, history, and model state remain associated with a session through reconnects.
  • merge-risk: 🚨 security-boundary: The branch uses Gateway-advertised methods and operator scopes before session mutation and rechecks them after asynchronous work.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR author is a repository MEMBER, so the external-contributor proof gate does not apply; the body nevertheless reports packaged Control UI and reconnect proof, but the final proof artifact could not be independently retrieved in this network-restricted review.

Evidence

What I checked:

  • Current-main lifecycle gap: Current main confirms /reset only against the visible session and then calls the reset sender without capturing the Gateway client or connection epoch; the non-reset command path below it does capture and validate client, epoch, session, and agent. This supports the reported reconnect-redirection defect. (ui/src/pages/chat/chat-commands.ts:238, a6e0002ecac0)
  • Gateway authorization contract: The shared Control UI access helper rejects disconnected or explicitly unavailable methods, checks advertised scopes, and preserves behavior for older Gateways that omit scope metadata. Its chat action mapping defines sessions.reset as an operator.admin action, supporting the PR’s intended authorization boundary. (ui/src/lib/session-method-access.ts:50, a6e0002ecac0)
  • Existing reconnect regression coverage: Current main already has a focused regression that abandons stale reconnect history after the connection epoch changes, confirming connection epochs are the established ownership primitive for this chat lifecycle. (ui/src/pages/chat/chat-send.test.ts:6271, f6341f2fbacd)
  • Feature-history provenance: Git blame attributes the current shared session-method access and slash-command dispatch lines to Peter Steinberger’s current-main commit; the adjacent merged authorization PR is represented locally by commit 603321a315…, authored by Shakker. (ui/src/pages/chat/chat-commands.ts:192, a6e0002ecac0)
  • Final-head inspection limitation: The PR head commit object is present locally and identifies b48afe893a… at 2026-08-03T06:36:03+01:00, but the partial clone lacks its changed blobs; Git attempted a promisor fetch and DNS/network access was unavailable. The supplied PR diff/body and current-main source were reviewed, but this prevents a full independent source read of every final-head line. (b48afe893a69)

Likely related people:

  • steipete: Current-main blame attributes the shared session-access policy and current slash-command dispatch to Peter Steinberger’s a6e0002… integration commit. (role: current authorization policy introducer; confidence: high; commits: a6e0002ecac0; files: ui/src/lib/session-method-access.ts, ui/src/pages/chat/chat-commands.ts, ui/src/pages/chat/chat-session-action-access.ts)
  • shakkernerd: The PR head and the locally available commit for the merged adjacent authorization work are authored by Shakker, linking this contributor to the same Control UI session-command boundary beyond this proposed branch alone. (role: recent adjacent lifecycle contributor; confidence: medium; commits: 603321a31569, b48afe893a69; files: ui/src/pages/chat/chat-commands.ts, ui/src/pages/chat/chat-outbox-drain.ts, ui/src/pages/chat/chat-command-executor.ts)

Rank-up moves

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

  • Confirm the intended /reset scope for write-scoped operators.
  • Wait for the supplied exact-head checks to complete, then refresh the final-head source review if the head changes.

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 (3 earlier review cycles)
  • reviewed 2026-08-02T15:06:16.817Z sha 65bd4d9 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-02T17:41:41.096Z sha cfaa582 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-03T04:59:43.773Z sha 16dcf4b :: needs maintainer review before merge. :: none

@shakkernerd
shakkernerd force-pushed the fix/control-ui-session-scopes branch from fb394bf to 603321a Compare August 2, 2026 17:32
Base automatically changed from fix/control-ui-session-scopes to main August 2, 2026 17:33
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: XL and removed size: L labels Aug 2, 2026
@shakkernerd
shakkernerd force-pushed the fix/chat-session-command-lifecycle branch from 65bd4d9 to cfaa582 Compare August 2, 2026 17:35
@openclaw-barnacle openclaw-barnacle Bot added size: L and removed docs Improvements or additions to documentation gateway Gateway runtime size: XL labels Aug 2, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 2, 2026
@shakkernerd
shakkernerd force-pushed the fix/chat-session-command-lifecycle branch from cfaa582 to 16dcf4b Compare August 3, 2026 04:54
@clawsweeper clawsweeper Bot removed the rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. label Aug 3, 2026
@shakkernerd
shakkernerd force-pushed the fix/chat-session-command-lifecycle branch from c9155e3 to e4884d9 Compare August 3, 2026 05:49
@shakkernerd
shakkernerd merged commit e4884d9 into main Aug 3, 2026
16 checks passed
@shakkernerd
shakkernerd deleted the fix/chat-session-command-lifecycle branch August 3, 2026 05:50
@shakkernerd

Copy link
Copy Markdown
Contributor Author

Merged.

What changed after review:

  • Fixed restored queued messages losing Steer during initial Gateway startup.
  • Centralized connection ownership checks and corrected lifecycle host typing and formatting.
  • Preserved upstream reconnect transcript restoration while retaining the lifecycle regression coverage.

Verification:

  • Fully green checkpoint at b48afe8; exact signed patch replay fast-forwarded to main.
  • Blacksmith Testbox tbx_01kz30k3paahfp6rtcjcezcxfp / run 30786492997: UI types, test types, full lint, and restored-queue E2E passed.
  • Blacksmith Testbox tbx_01kz3169996dssn7193yy69hps / run 30787003241: post-rebase UI and test types, 28 lifecycle tests, and restored-queue E2E passed.
  • Blacksmith Testbox tbx_01kz31rteyqdvr4hy7a62n4jga / run 30787474074: full format check passed.
  • Auto-review: clean; no accepted or actionable findings.
  • GitHub checks: the green checkpoint passed 76 checks with 19 skipped; the signed replay was patch-equivalent and duplicate SHA-only CI was not awaited.

Landed on main:

Thanks @shakkernerd!

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

Labels

app: web-ui App: web-ui maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. 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