Skip to content

fix(agents): keep tool catalogs stable across completion wake turns - #182191

Merged
steipete merged 6 commits into
mainfrom
steipete/session-owned-client-caps
Oct 24, 2026
Merged

steipete merged 6 commits into
mainfrom
steipete/session-owned-client-caps

Conversation

@steipete

@steipete steipete commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

In a session with subagents, the requester's internal completion wake turns listed fewer tools than its operator turns. The Code Mode catalog changed mid-session ("43 additional tools omitted" became "42") and the request instructions were rewritten in place, breaking the provider prompt prefix on every switch between operator and wake turns. On some builds it showed up as an appended "System prompt update" replacing the whole ## Tooling section, about 5 KB per flip. The AGENTS.md contract is that within a session, tool definitions depend only on session and config facts, and per-turn authority gates calls.

User Impact

Tool definitions and the Code Mode catalog remain stable across operator and internal completion wake turns in the same session. Current-turn execution authority remains enforced; this does not grant completion turns additional tool authority. No configuration changes or migration steps are required.

Why This Change Was Made

Root cause

Three per-turn facts leaked into tool listing:

  1. Client capabilities. screen requires ui-commands, and filterToolsByClientCaps filtered on the current turn's client. Internal completion dispatch uses a synthetic client with no capability list (subagent-announce-completion-delivery.ts, forceSyntheticClient).
  2. Caller authority. sessions_create's constructor returned null when the current Gateway caller lacked session-write authority (sessions-create-tool.ts).
  3. Replayed child deny. Completion handoffs replay the child's inherited tool deny (for example intent, screen, gateway, nodes …) into the requester's tool construction (requester-tool-policy.ts). agent-tools.ts passed it into plugin construction, and src/plugins/tools.ts skipped denied registrations before their factories ran. This was the flip observed live: memory-core's intent was built on operator turns and never on wakes.

Fix

  • The client-capability declaration is a session fact (session metadata): operator turns replace it, empty declarations clear it, wakes and recovery keep it, and reset or delete discard it. Listing uses it. Execution keeps the existing gate and the live-browser check in ui-command.ts, with an actionable Control UI refusal.
  • sessions_create is always defined. Unauthorized calls are refused by the existing execution gate, and creation-owner checks are unchanged.
  • Completion turns list the requester session's own tools and catalog (its own inherited ceiling, sessionInheritedToolPolicy). The replayed child policy gates execution instead: a denied call reports that the tool "is not available during a child-completion turn because it is outside the authority carried from its requester", through resolveTurnToolSurface / gateAgentToolExecution. A subagent requester's own inherited restrictions still remove tools from its listing, and spawn/descendant ceilings are unchanged. This follows docs/tools/subagents/tool-policy.md, which keeps captured restrictions at execution; the doc is updated.

Security notes

This change separates session-stable tool discovery from per-turn authorization. Current client capability checks, the live-browser recipient check, session creation-owner checks, completion execution restrictions, and spawn/descendant ceilings remain enforced. It touches tool policy and authority and retains the repository's applicable security review gates.

Evidence

  • Regressions, red on base and green twice: agent-tools.prefix-stability.test.ts (operator vs internal wake in WebChat sessions, browser and CLI clients: identical tool definitions and catalog; base lost screen, then sessions_create) and the new openclaw-plugin-tools.wake.test.ts (base: the wake listing lacks intent; fixed: stable listing, refused execution on the completion turn, and a subagent requester's own deny still applied). Also green: agent-tools.turn-authority, requester-tool-policy, scheduled-message-invocation, tools.optional, tools.inspection, agent-tools.plugin-policy and sessions-create-tool — 161 tests across the focused suites.
  • Live on a Crabbox AWS host with real OpenAI models. WebChat fleet parents were started via Gateway chat.send on dashboard keys, with a debug probe in the built catalog formatter (not committed):
    • main: parent catalog 64 (with intent) on the operator turn and 63 (without) on the first wake; the instructions changed 43 → 42 mid-session.
    • this branch: every parent prompt build is 64+intent; both parents' instructions carry a constant "43 additional tools omitted" across all requests (10 and 9); fleets 2/2 at 35/35.
  • Follow-up, not changed here: github_publish listing still depends on current authority when githubPublicationAvailable === false (openclaw-tools.ts); it wasn't the observed flip. Separately, a profile change restarting the prompt series (route key includes the bootstrap profile, a79e29e) rewrites instructions instead of appending a delta.

CI follow-up

Initial CI found two existing session-creation tests that still expected unauthorized tools to be absent. The follow-up test-only commit preserves their security contract with assertions for stable listing, gated execution, no creation-handler dispatch, and an unchanged session key set. Both focused files pass on the provided Crabbox host (28 tests), and the repair passed independent review plus formatting, lint, and whitespace checks.

CI also exposed a swarm fixture that assumed the first structured model calls finish in startup order. Its three collectors start concurrently below the group’s maxConcurrent; only excess children queue FIFO (docs/tools/swarm.md). The test now sorts those calls before requiring exactly [1, 3], still excluding worker 2, and all completion-order assertions remain unchanged. This is a test-only contract correction. The focused swarm-tools.integration.test.ts run passes on the supplied AWS Crabbox host (1/1 test; Vitest 33.07s, wrapper wall time 71.05s, mostly existing transform/setup work). Independent review found no actionable P0/P1 issues; formatting, lint, and whitespace checks pass.

The separate stop-followup failure reproduces on clean main 3bcc91708d8 at the same line with the same missing killReconciliation error (10 tests passed, 1 failed). It is unrelated to this change and remains eligible for the authorized inherited-failure route; failed CI is not claimed as green.

The next CI attempt required an explicit numeric comparator for toSorted under typescript/require-array-sort-compare. That one-line test-only repair passes typed lint (0 warnings/errors), the focused swarm test, and independent review. The expected worker set and completion-order assertions are unchanged.

CI run 40063420932 also reported session-accessor.recovery.test.ts / preserves recovery success after committed owner retirement (unexpected database-execution captures). The full file passed on the PR source and on the exact clean CI base 4188c9e09cb; the failing case then passed three targeted Bun runs on that base. Its cause remains unresolved; no inherited-failure exception is claimed for it and passing replays are not a repair.

On final head 236b246e49e, CI run 40064355273 reports the same stop-followup failure in checks-node-changed-compact-small-19. Scheduled main run 40062828625 reports the same test and missing killReconciliation error. The test and persistence-owner files are unchanged by this PR. All jobs finished with this sole root failure; the PR landed through the authorized native inherited-failure route as e4d101a4916281a5b0f2be4ae633db7a750fdb55. CI remains recorded as failed. The prior recovery assertion did not recur on the final head.

Record operator client capabilities in session metadata and reuse that fact
for tool definitions and the Code Mode catalog across wakes and recovery.
Keep current-client execution gates and live browser recipient checks, with
actionable guidance when a wake cannot invoke a client-bound tool.

Document declaration replacement and reset lifecycle. Add regressions for
stable WebChat catalogs and refused unbound screen calls.
Keep sessions_create in the offered tool surface when a WebChat operator
turn becomes a senderless wake or recovery turn. Gate unauthorized execution
with the existing tool refusal helper and retain live creation-owner checks.
This prevents the deferred Code Mode catalog count from changing with the
current turn's session-write authority, including CLI chat.send sessions.

Extend the prefix-stability regression for browser and CLI clients carrying
real admitted operator authority, and verify that a denied constructor
cannot gain authority from a later caller context. Keep the existing
session-owned client capability and screen enforcement fix.

Validation: the new operator/wake cases fail on 34f94e4 with exactly
sessions_create missing. Focused prefix and session-create suites pass.
Use the requester session ceiling for plugin listing and keep the child-completion policy in execution and descendant authority. Preserve a subagent requester own inherited restrictions and give denied completion calls an explicit refusal.

Prove stable plugin definitions and Code Mode catalog, denied execution, and nested requester listing. The exact regression fails on ca48d43 and passes with this change; focused policy/plugin suites, repeated touched tests, lint, agent typecheck, and independent review pass.
@clawsweeper

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

@steipete
steipete marked this pull request as ready for review October 24, 2026 04:14
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T04:33:17.153415Z bd9da29 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: L labels Oct 24, 2026
@github-actions

github-actions Bot commented Oct 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: 236b246e49e97a7d5e4158690887cb44674a3ba1
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/agent-tools.turn-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/requester-tool-policy.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

Carefully review these changes before merging.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 199c2a0484

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +251 to +252
const inlineWidgetClientAvailable =
(options?.listingClientCaps ?? options?.clientCaps)?.includes("inline-widgets") === true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve pinned widget authoring during restart recovery

When a Control UI session with recorded inline-widgets capabilities resumes after a restart, resolveAgentRestartRecoveryContext explicitly enables pinnedWidgetAuthoring without a current inline client. Using the recorded capabilities here makes inlineWidgetClientAvailable true, which disables pinnedWidgetOnly below. Consequently, show_widget acquires an inline-widgets requirement and filterToolsByClientCaps refuses every call, including pin=true dashboard updates that recovery previously supported. Keep recorded capabilities for catalog stability without removing the recovery path's client-independent pinned authoring capability.

AGENTS.md reference: src/agents/AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

@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. labels Oct 24, 2026
Update existing session-creation integration assertions for the stable catalog contract. Require unauthorized calls to return the execution gate refusal, never dispatch to the creation handler, and preserve the session key set. Keep explicit policy-deny coverage.
Assert the exact schema-bearing worker set while retaining all collector completion-order checks. Initial calls below maxConcurrent may race; only overflow children queue FIFO.
@steipete
steipete enabled auto-merge (squash) October 24, 2026 04:49
@steipete
steipete disabled auto-merge October 24, 2026 04:52
Satisfy typed sort-comparator lint while preserving the exact schema-bearing worker set and all completion-order assertions.
@steipete
steipete merged commit e4d101a into main Oct 24, 2026
148 of 153 checks passed
@steipete
steipete deleted the steipete/session-owned-client-caps branch October 24, 2026 05:24
@steipete

Copy link
Copy Markdown
Contributor Author

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

steipete added a commit that referenced this pull request Oct 25, 2026
Since #182191 the tool catalog follows the session's recorded client
capabilities so wake and recovery turns keep a stable prefix. A recovered
Control UI turn with no inline-widgets client therefore received the full
inline show_widget schema, and the current-caps execution gate refused every
call, including pin=true. The dashboard update was silently dropped while
the run still finished ok (test/gateway-widget-restart.e2e.test.ts failed
deterministically on main).

Keep the recorded schema, but when pinned authoring is admitted and the
current turn lacks an inline client, execute pinned calls and refuse inline
ones with an actionable message instead of the generic client gate.

Proof: new openclaw-tools.scheduled-widget regression fails on the base
(board.widget.put never called) and passes with the fix; the widget restart
e2e failed 2/2 on main and passes 5/5 with the fix under the pinned Bun
runtime.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
…penclaw#182191)

* fix(agents): retain session client capabilities across wake turns

Record operator client capabilities in session metadata and reuse that fact
for tool definitions and the Code Mode catalog across wakes and recovery.
Keep current-client execution gates and live browser recipient checks, with
actionable guidance when a wake cannot invoke a client-bound tool.

Document declaration replacement and reset lifecycle. Add regressions for
stable WebChat catalogs and refused unbound screen calls.

* fix(agents): keep session creation catalogs stable across wakes

Keep sessions_create in the offered tool surface when a WebChat operator
turn becomes a senderless wake or recovery turn. Gate unauthorized execution
with the existing tool refusal helper and retain live creation-owner checks.
This prevents the deferred Code Mode catalog count from changing with the
current turn's session-write authority, including CLI chat.send sessions.

Extend the prefix-stability regression for browser and CLI clients carrying
real admitted operator authority, and verify that a denied constructor
cannot gain authority from a later caller context. Keep the existing
session-owned client capability and screen enforcement fix.

Validation: the new operator/wake cases fail on 34f94e4 with exactly
sessions_create missing. Focused prefix and session-create suites pass.

* fix(agents): gate completion tool denies without changing catalogs

Use the requester session ceiling for plugin listing and keep the child-completion policy in execution and descendant authority. Preserve a subagent requester own inherited restrictions and give denied completion calls an explicit refusal.

Prove stable plugin definitions and Code Mode catalog, denied execution, and nested requester listing. The exact regression fails on ca48d43 and passes with this change; focused policy/plugin suites, repeated touched tests, lint, agent typecheck, and independent review pass.

* test(agents): assert creation authority at execution

Update existing session-creation integration assertions for the stable catalog contract. Require unauthorized calls to return the execution gate refusal, never dispatch to the creation handler, and preserve the session key set. Keep explicit policy-deny coverage.

* test(agents): allow concurrent swarm startup calls

Assert the exact schema-bearing worker set while retaining all collector completion-order checks. Initial calls below maxConcurrent may race; only overflow children queue FIFO.

* test(agents): use explicit swarm call comparator

Satisfy typed sort-comparator lint while preserving the exact schema-bearing worker set and all completion-order assertions.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
Since openclaw#182191 the tool catalog follows the session's recorded client
capabilities so wake and recovery turns keep a stable prefix. A recovered
Control UI turn with no inline-widgets client therefore received the full
inline show_widget schema, and the current-caps execution gate refused every
call, including pin=true. The dashboard update was silently dropped while
the run still finished ok (test/gateway-widget-restart.e2e.test.ts failed
deterministically on main).

Keep the recorded schema, but when pinned authoring is admitted and the
current turn lacks an inline client, execute pinned calls and refuse inline
ones with an actionable message instead of the generic client gate.

Proof: new openclaw-tools.scheduled-widget regression fails on the base
(board.widget.put never called) and passes with the fix; the widget restart
e2e failed 2/2 on main and passes 5/5 with the fix under the pinned Bun
runtime.
steipete added a commit that referenced this pull request Oct 25, 2026
…183286)

Narrow slice of #179363. Keep native Codex tool declarations stable across completion turns and enforce current owner authority when tools execute. Preserve the existing four-name fingerprint workaround and the fixes from #182191 and #183059.

Validated with the factory regression red on base and green on this head, 104 targeted tests, and exact-head CI. Live transport proof remains a documented gap.

Co-authored-by: Marvinthebored <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>
RomneyDa pushed a commit that referenced this pull request Oct 26, 2026
…183286)

Narrow slice of #179363. Keep native Codex tool declarations stable across completion turns and enforce current owner authority when tools execute. Preserve the existing four-name fingerprint workaround and the fixes from #182191 and #183059.

Validated with the factory regression red on base and green on this head, 104 targeted tests, and exact-head CI. Live transport proof remains a documented gap.

Co-authored-by: Marvinthebored <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>
(cherry picked from commit 6a62821)

Adapted for 2026.9.x: native-thread-tool.ts resolved by hand against the
9.x execute layout (owner check at execute entry, in the request-options
assertCurrent, and as the binding-clear commit guard; 9.x has no separate
prepared session-entry guard). Tests rewritten onto the 9.x fixtures (sync
createTool, 9.x supervision registration test).
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
…penclaw#183286)

Narrow slice of openclaw#179363. Keep native Codex tool declarations stable across completion turns and enforce current owner authority when tools execute. Preserve the existing four-name fingerprint workaround and the fixes from openclaw#182191 and openclaw#183059.

Validated with the factory regression red on base and green on this head, 104 targeted tests, and exact-head CI. Live transport proof remains a documented gap.

Co-authored-by: Marvinthebored <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>
RomneyDa pushed a commit that referenced this pull request Oct 26, 2026
…183286)

Narrow slice of #179363. Keep native Codex tool declarations stable across completion turns and enforce current owner authority when tools execute. Preserve the existing four-name fingerprint workaround and the fixes from #182191 and #183059.

Validated with the factory regression red on base and green on this head, 104 targeted tests, and exact-head CI. Live transport proof remains a documented gap.

Co-authored-by: Marvinthebored <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>
(cherry picked from commit 6a62821)

Adapted: applied the native-plugin-tool.test.ts owner-denial hunk inside the release describe block.
RomneyDa pushed a commit that referenced this pull request Oct 26, 2026
…183286)

Narrow slice of #179363. Keep native Codex tool declarations stable across completion turns and enforce current owner authority when tools execute. Preserve the existing four-name fingerprint workaround and the fixes from #182191 and #183059.

Validated with the factory regression red on base and green on this head, 104 targeted tests, and exact-head CI. Live transport proof remains a documented gap.

Co-authored-by: Marvinthebored <[email protected]>
Co-authored-by: Dallin Romney <[email protected]>

Release adaptation: stable's thread tool lacks main's session-entry current-check capture; applied only the owner-authority move (declare unconditionally, assert owner at execute/commit). Ported the owner-denial cases into stable's test fixtures.

(cherry picked from commit 6a62821)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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. docs Improvements or additions to documentation gateway Gateway runtime security-sensitive-changed size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant