Skip to content

fix: keep a chat's client capabilities when queued messages resume after a restart - #204787

Merged
jalehman merged 3 commits into
mainfrom
openclaw/briny-shrimp-96f795
Nov 24, 2026
Merged

jalehman merged 3 commits into
mainfrom
openclaw/briny-shrimp-96f795

Conversation

@jalehman

@jalehman jalehman commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

When the Gateway restarts while someone's chat turn is running, and a follow-up message is queued behind it, OpenClaw resumes the running turn and then replays the queued message. That replay erased the chat's record of what the person's client supports, for example Control UI approvals. After a restart, the session could lose tools that need those client features. Work on the session that had already read the earlier record could also see the session as changed and fail.

User Impact

User impact: after a Gateway restart, a chat keeps the client features it had, and both the interrupted turn and the queued message continue as before.

Why This Change Was Made

Restart replay sends the queued message through an internal Gateway caller. That caller declared an empty list of client features, and the session treated it like a real client and saved the empty list. Internal callers now declare no client features, so the session keeps the list from the last real client. Live clients still update it, including a live client that declares no features. Running a tool that needs a client feature still requires a connected client with that feature, so nothing gains new authority.

Details
  • resolveChatSendCallerContext declares GatewayClientCaps as undefined for synthetic callers, where it used to declare [].
  • prepareSessionMetaPatch skips the clientCapabilities patch when the turn comes in through the Gateway chat provider and no client capabilities are declared. Channel inbound turns are unchanged.
  • The Talk consult authority and the agent RPC path now handle the optional value. Downstream execution already treated undefined and [] the same way.
  • Test support: the chat fixture can declare client capabilities. Its restart() now runs the same in-process restart reset as the Gateway run loop (prepareGatewayRestartIteration), which starts a new lifecycle generation. Without that reset, queued input is never treated as left over from the previous process.

Evidence

The change was checked as follows:

  • Restart regression test (src/gateway/session-restart-resume.queued-input.product.test.ts). A real Gateway with a scripted model provider and a Control UI client that declares approvals. The owner's first turn is running, a follow-up is queued behind it, and the Gateway restarts in-process. The test checks that the interrupted turn resumes, the queued message runs and lands in the chat history, and the recorded client capabilities match what they were before the restart.
    • On main it fails: expected [ 'webchat-prompt-reactions' ] to deeply equal [ 'approvals', 'webchat-prompt-reactions' ].
    • With the fix it passes.
    • On main the resumed turn and the queued message both still completed in this run. The lost capability record is what failed.
  • Unit test (gateway-client-identity.test.ts). It checks that only a live client updates the recorded capabilities and a synthetic caller leaves them unchanged. It fails on main and passes with the fix.
  • Stored-data compatibility. The change adds no field and doesn't change how session entries are stored: SessionEntry, the SQLite entry JSON and its canonical projection (store-entry-shape.ts) are untouched, and clientCapabilities keeps its type. A focused test (gateway-client-identity.test.ts, "replays stored sessions written before this change") loads entry JSON in the shape earlier releases persisted through the real SQLite row parser (parseCanonicalSqliteSessionEntry), applies the restart-replay caller's metadata patch, and resolves the tool-listing capabilities the replayed turn uses:
    • A session with a recorded catalog (approvals, webchat-prompt-reactions) loads unchanged, replay keeps it, and tool listing uses it.
    • A session without a recorded catalog loads unchanged, replay leaves it without one, and tool listing falls back to the turn's own capabilities, as it did before the catalog existed. On main, replay instead writes ['webchat-prompt-reactions'] into both sessions.
    • The restart product test above covers the same path end to end with a real Gateway and stored session.
  • Other users of the restart fixture still pass. These are the visible-chat restart test and the prompt-cache restart test.
  • Suites:
    • Operator-run recovery and session restart-resume: 19 files, 200 tests, all pass.
    • Cron, full src/cron run: stopped at its 60-minute local limit on a busy machine. 1,318 tests across 35 files had run by then, and none failed.
    • Cron, Gateway-facing session-run tests: these cover the session-run and chat.send paths and passed in a separate run (4 files, 43 tests).
    • Prompt-prefix stability, prompt-reaction, origin-channel, Talk relay and agent-run owner tests: all pass.
  • Inherited CI failures (run 45458845013 on 01c1a943, merged with main at 986ad151). All three failed jobs also fail without this PR:
    • checks-node-changed-4: src/agents/bash-tools.exec-gateway-approval.e2e.test.ts › "withholds the active hook token source from exec children at startup and across reload" (expected [] to deeply equal [ 'OPENCLAW_E2E_HOOK_SOURCE_OLD' ]). It fails the same way on the PR's base 04d96995 under Bun, and with the identical assertion in the changed-test shards of unrelated PRs (runs 45407381496, 45415821154, 45447385916).
    • checks-node-changed-7: test/e2e/qa-lab/runtime/gateway-plugin-turn-handover.e2e.test.ts, 4 of 5 cases (JSON Parse error: Unable to parse JSON string, unhandled gateway client stopped). It fails identically, 4 failed and 1 passed, under Bun on the PR's base 04d96995 and on this head.
    • checks-node-compact-small-8: test/scripts/ci-node-test-plan.test.ts › "prices serial Gateway server measurements at two workers and preserves parallel samples (github)" (expected length 4, got 5). It fails identically on main at 986ad151 without this PR and passes on this head over 04d96995.
    • The changed-test shards selected the two e2e files because this PR touches src/gateway/test-helpers.e2e.ts. That change only forwards an optional caps, which is undefined for these tests, and connectGatewayClient already forwarded it that way. openclaw/ci-gate is red only because of these three jobs. security-fast and every other job passed.
  • Static checks: pnpm tsgo:core and pnpm tsgo:test:src pass. oxlint and the formatter are clean on the changed files.
  • Test cost:
    • The new product test takes about 24–32 seconds when run on its own locally. Most of that is starting the Gateway twice, which this restart contract needs. No cheaper test covers it.
    • The new and changed tests add about 130 lines, which is under the 400-line budget.

🦞 Made with OpenClaw

…r a restart

Restart replay dispatches queued WebChat input through a synthetic Gateway
client. Its caller context declared an empty client capability list, which
rewrote the session's recorded capability catalog. Synthetic callers now
declare no current capabilities, and session metadata keeps the recorded
catalog when no client declaration is present.
…ter a restart

OpenClaw-Publication: 846525ef-51c7-800c-a53a-e1919c5a49e2
@clawsweeper

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

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 01c1a94390f150bb55b2d5b56b53dd613a27c315
  • Maintainer: @jalehman
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/talk/client-tool-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@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. 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 24, 2026
@clawsweeper

clawsweeper Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves a chat’s recorded client capabilities when queued messages replay after a Gateway restart.

Example: A Control UI chat records approvals support, queues a follow-up, and restarts.

  • Before: Replay replaces ['approvals', 'webchat-prompt-reactions'] with ['webchat-prompt-reactions'].
  • After: Replay preserves both recorded capabilities; a real client can still replace its declaration.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch appears correct and the earlier compatibility concern is resolved; required real-behavior proof remains limited to a scripted-provider test harness.
Proof confidence 🧂 unranked krab (1/6) 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.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: After a restart replays a queued message, a chat can lose recorded client features and change its available tool catalog.
Reason: This focused maintainer-authored repair restores an existing documented contract and preserves live-client replacement behavior.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it fixes a current-main violation of the session capability contract, and the reviewed diff has no actionable code findings.

Priority: P2
Reviewed head: 01c1a94390f150bb55b2d5b56b53dd613a27c315

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Supply a shipped-Gateway run with a real model showing an interrupted turn and queued follow-up completing while the recorded approvals capability survives restart.
Agent review details

How this fits together

Gateway caller context feeds session metadata and agent execution; recorded capabilities determine tool listing while current-client capabilities continue to gate execution.

flowchart TD
  A[Live chat client] --> C[Gateway caller context]
  B[Queued restart replay] --> C
  C --> D[Session metadata owner]
  D --> E[Recorded capability catalog]
  E --> F[Agent tool listing]
  C --> G[Current client execution gate]
Loading

Technical review

Best possible solution:

Keep the existing metadata owner, preserve absent synthetic declarations, and retain current-client execution gates as this patch does.

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

Source inspection establishes the synthetic replay-to-metadata overwrite path, and the PR reports a matching base-failing regression; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch restores the documented distinction between a missing declaration and an empty declaration using existing owners, without adding state, configuration, or a parallel recovery path.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Session-owned capability metadata keeps the original intent (e4d101a: Keep tool catalogs stable across internal completion and recovery turns while enforcing authority at execution.)
  • Gateway caller context keeps the original intent (e8e68e8: Bind command authority to verified live connections while excluding synthetic callers; this patch preserves that authority logic.)
  • Agent execution capability array keeps the original intent (13747e0: Preserve compatible steering and follow-up execution identity; the nullish fallback retains an empty execution capability set for synthetic callers.)
  • Talk consult capability filtering keeps the original intent (99caa18: Keep Talk authority in its existing owner and omit task-suggestion support where no acceptance UI exists; optional filtering retains that behavior.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit e4d101a adds src/config/sessions/metadata.ts:108 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e4d101a49162; files: src/config/sessions/metadata.ts)
  • JamesY023: Raw commit e8e68e8 adds src/gateway/server-methods/gateway-client-identity.ts:101 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: e8e68e84e455; files: src/gateway/server-methods/gateway-client-identity.ts)

PR surface

Source +4, Tests +153. Total +157 across 9 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 5 7 3 +4
Tests 4 153 0 +153
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 160 3 +157

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Queued restart replay can silently replace a session’s capability catalog, with impact limited to this recovery path.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 (1 earlier review cycle)
  • reviewed 2026-11-24T17:21:30.446Z sha b3dc331 :: blocked before merge. :: none

Reviewed November 24, 2026, 1:27 PM ET / 18:27 UTC (Revision 2).

@jalehman

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. label Nov 24, 2026
@jalehman
jalehman merged commit 511df66 into main Nov 24, 2026
160 of 168 checks passed
@jalehman
jalehman deleted the openclaw/briny-shrimp-96f795 branch November 24, 2026 19:28
@jalehman

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

tideclaw-bot pushed a commit that referenced this pull request Nov 25, 2026
…ter a restart (#204787)

* fix: keep a chat's client capabilities when queued input replays after a restart

Restart replay dispatches queued WebChat input through a synthetic Gateway
client. Its caller context declared an empty client capability list, which
rewrote the session's recorded capability catalog. Synthetic callers now
declare no current capabilities, and session metadata keeps the recorded
catalog when no client declaration is present.

* fix: keep a chat's client capabilities when queued messages resume after a restart

OpenClaw-Publication: 846525ef-51c7-800c-a53a-e1919c5a49e2

* test: replay stored sessions with and without a recorded capability catalog

(cherry picked from commit 511df66)
Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 25, 2026
…ter a restart (openclaw#204787)

* fix: keep a chat's client capabilities when queued input replays after a restart

Restart replay dispatches queued WebChat input through a synthetic Gateway
client. Its caller context declared an empty client capability list, which
rewrote the session's recorded capability catalog. Synthetic callers now
declare no current capabilities, and session metadata keeps the recorded
catalog when no client declaration is present.

* fix: keep a chat's client capabilities when queued messages resume after a restart

OpenClaw-Publication: 846525ef-51c7-800c-a53a-e1919c5a49e2

* test: replay stored sessions with and without a recorded capability catalog
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…ter a restart (#204787)

* fix: keep a chat's client capabilities when queued input replays after a restart

Restart replay dispatches queued WebChat input through a synthetic Gateway
client. Its caller context declared an empty client capability list, which
rewrote the session's recorded capability catalog. Synthetic callers now
declare no current capabilities, and session metadata keeps the recorded
catalog when no client declaration is present.

* fix: keep a chat's client capabilities when queued messages resume after a restart

OpenClaw-Publication: 846525ef-51c7-800c-a53a-e1919c5a49e2

* test: replay stored sessions with and without a recorded capability catalog

(cherry picked from commit 511df66)

Release adaptation: Register only the landed restart test and use the stable exact empty-capability contract.

Companions: No later #204787 references; unrelated Gateway fixture and chat policy changes are independent.

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

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. security-sensitive-changed size: S 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