Repository navigation
fix(agents): read dispatched tools' repeat exemptions and defer the delegation family together - #207314
Conversation
- WIP: catalog family rule + invariant test
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: passed. What this changesThis PR keeps sessions_spawn directly visible when another admitted delegation-family tool is directly visible. Example: An agent is asked to delegate work with default Tool Search enabled.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses a concrete Tool Search discoverability problem still present on main; source review found no definite introduced bug. Reviewed head: Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Tool Search catalog receives policy-filtered tools and produces the provider's direct tool list and searchable deferred catalog. flowchart LR
A[Admitted tools] --> B[Gateway policy filtering]
B --> C[Catalog selectors]
D[Core family facts] --> E[Family visibility]
C --> E
E --> F[Direct provider tools]
E --> G[Searchable catalog]
Technical reviewBest possible solution: Keep delegation-family visibility in the existing policy-filtered catalog owner while preserving polling exemptions and collision handling. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the split tool surface; the body reports intermittent real-model refusals, which this read-only review did not independently reproduce. Is this the best way to solve the issue? The change repairs presentation at its existing owner, preserves the earlier polling fix, and records the schema-cost tradeoff without adding configuration or a competing execution path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 833e9d0f2f0b. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +29, Tests +44, Docs +4. Total +77 across 4 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 28, 2026, 2:37 AM ET / 07:37 UTC. |
# Conflicts: # packages/gateway-protocol/src/compiled/protocol.generated/predicates.js
…shared facts and the worker wire
|
Landed as 8eb9596. The repeat guard now reads the exemption of the tool a dispatch_action call names, so the polling tools (agents_wait, subagents) stay deferred. The delegation family (sessions_spawn, subagents, agents_wait) now always has one visibility. Proof: tests that fail on main pass here; on gpt-5.4-mini, sessions_spawn was found 10/10 on both routes with a 1.4 KB smaller first request; CI is green. |
…elegation family together (openclaw#207314) ## Problem With Tool Search on (the default), openclaw#206801 made `subagents` and `agents_wait` direct tools. It did that only because the repeat guard read `dispatch_action`'s own `repeatable` declaration, not the declaration of the tool the call names. A model polling its children through `dispatch_action` got a "stop repeating" note at call 3 and `tool_repeat_limit` at call 20. That fix split the delegation family. `subagents` ("Subagent status/cancel") and `agents_wait` were sent with full schemas, while `sessions_spawn` stayed a bare name in the deferred list. gpt-5.4-mini then treated the two visible tools as the whole subagent capability and answered "sessions_spawn isn't available". Behavior-suite history for the subagent-spawn case: 21/21 found the tool before openclaw#206801 and 6/20 after. ## Fix The repeat guard now reads the target's declaration, and the polling tools are deferred again, with no added prompt bytes. - **One dispatcher argument reader.** The reader for selectors and input forms moved from `src/agents/tool-search-request.ts` to `packages/agent-core/src/dispatch-call.ts`: - selectors: `id`, `toolId`, `name`; - input: `args`, `input`, `args.<field>`, flattened arguments, and a selector wrapped inside the input. - `dispatch_action` executes through it with catalog matching. The repeat guard classifies through it with target matching. Both see the same target and the same input for every call form. - **Plain-data dispatcher declaration.** `ToolRepeatable` gets `{ dispatch: { targets, aliases } }`. `applyToolCatalogCompaction` builds it from the registered catalog: each trusted tool's own `repeatable` by catalog id, with its name as an alias when the name is unique. - The guard applies the target's own `true | { actions }`. A dispatched poll is exempt exactly as a direct call would be. - A selector that names anything else counts as a different target. A call with disagreeing selectors stays counted, matching the dispatcher, which refuses it as ambiguous. - The declaration is read once per call, on the path the call takes. - **Polling tools deferred again.** The "repeatable → direct" rule is removed. - **One visibility for the delegation family.** The Tool Search owner (`tool-search-catalog-visibility.ts`) lists `sessions_spawn`, `subagents` and `agents_wait` as one family. - If any member is sent directly (caller-required, or kept outside the catalog by a selector), the whole family is sent directly. - A member shown only because of its family never shadows a tool with the same name. - On the default surface the whole family is deferred. ## Why this and not "send `sessions_spawn` directly" The first version of this PR made the family direct: +12,236 B on every request, +35% on the first request. It was held because: - it undoes most of the prompt savings from openclaw#206537 and openclaw#206801; - reverting it later would change the tool prefix, and so bust deployed caches, twice; - openclaw#206801 is only on main, so no released user is affected. This version costs 0 KB. The first request is 1.4 KB smaller than on main, because the polling schemas leave the tool list. ## Evidence | Check | Tier | main `402dc418` | This PR | |---|---|---|---| | Both Tool Search modes defer the whole family; every non-empty member subset, with and without an include selector, has one visibility; 25 identical polls of `agents_wait` (name and catalog id) and `subagents list` through `dispatch_action` run with no note and no stop | vitest-source | **7 of 9 fail** | 10/10 pass | | A non-polling action (`subagents cancel`) and a non-repeatable tool repeated through `dispatch_action` still stop at call 20 | vitest-source | pass | pass | | Guard unit test: every dispatcher call form is exempt for a polling target; disagreeing selectors, unknown targets and non-polling actions are counted | vitest-source | n/a | pass | | `agent-tools.prefix-stability.test.ts`, Tool Search and runtime suites, `prompt:snapshots:check` | vitest-source / source | | green / current | Real gpt-5.4-mini runs (low thinking) on the subagent-spawn case, 5 trials per cell, against main `402dc418`: | Route | `sessions_spawn` called, main | `sessions_spawn` called, this PR | First request, main → this PR | |---|---|---|---| | Gateway | 9/10 (1 reply: "sessions_spawn isn't available") | **10/10** | 34.6 → 33.2 KB | | `--local` | 4/5 (2/5 and 2/6 in earlier runs) | **10/10** | 33.8 → 32.4 KB | What the user sees: - **Gateway, with a 60 s window for the child's completion:** the child's result reached the user in 5/5 runs on this PR and 4/5 on main. - **How the result arrives:** - With `subagents` deferred, 3 of 5 runs end the turn with `sessions_yield`, and the result arrives in the following completion message. - On main, the model waited inside the turn with the direct `subagents wait`. That pattern only exists since openclaw#206801. - Pre-openclaw#206801 behavior is the same yield pattern. - A yielded turn returns an empty CLI payload. That is an existing `sessions_yield` presentation gap, not caused by this change. - **No over-delegation:** read-file, shell-command and memory-recall, 3 trials each, both routes: 9/9 on main and on this PR, 0 spawn calls, and the same request count (15). - **`--local` caveat:** every variant's spawn then fails at runtime with "published reply runtime missing". That is a separate open gap, so only the call counts on that route. No worker protocol change. Workers compact Tool Search locally from each tool's own `true | { actions }` declaration, so the dispatcher form never crosses the wire. No change reaches the Control UI bundle either: shared `core-tool-facts.ts` is untouched. Co-authored-by: Ayaan Zaidi <[email protected]>
Problem
With Tool Search on (the default), #206801 made
subagentsandagents_waitdirect tools. It did that only because the repeat guard readdispatch_action's ownrepeatabledeclaration, not the declaration of the tool the call names. A model polling its children throughdispatch_actiongot a "stop repeating" note at call 3 andtool_repeat_limitat call 20.That fix split the delegation family.
subagents("Subagent status/cancel") andagents_waitwere sent with full schemas, whilesessions_spawnstayed a bare name in the deferred list. gpt-5.4-mini then treated the two visible tools as the whole subagent capability and answered "sessions_spawn isn't available".Behavior-suite history for the subagent-spawn case: 21/21 found the tool before #206801 and 6/20 after.
Fix
The repeat guard now reads the target's declaration, and the polling tools are deferred again, with no added prompt bytes.
src/agents/tool-search-request.tstopackages/agent-core/src/dispatch-call.ts:id,toolId,name;args,input,args.<field>, flattened arguments, and a selector wrapped inside the input.dispatch_actionexecutes through it with catalog matching. The repeat guard classifies through it with target matching. Both see the same target and the same input for every call form.ToolRepeatablegets{ dispatch: { targets, aliases } }.applyToolCatalogCompactionbuilds it from the registered catalog: each trusted tool's ownrepeatableby catalog id, with its name as an alias when the name is unique.true | { actions }. A dispatched poll is exempt exactly as a direct call would be.tool-search-catalog-visibility.ts) listssessions_spawn,subagentsandagents_waitas one family.Why this and not "send
sessions_spawndirectly"The first version of this PR made the family direct: +12,236 B on every request, +35% on the first request. It was held because:
This version costs 0 KB. The first request is 1.4 KB smaller than on main, because the polling schemas leave the tool list.
Evidence
6d8e821aagents_wait(name and catalog id) andsubagents listthroughdispatch_actionrun with no note and no stopsubagents cancel) and a non-repeatable tool repeated throughdispatch_actionstill stop at call 20agent-tools.prefix-stability.test.ts, Tool Search and runtime suites,prompt:snapshots:checkReal gpt-5.4-mini runs (low thinking) on the subagent-spawn case, 5 trials per cell, against main
6d8e821a:sessions_spawncalled, mainsessions_spawncalled, this PR--localWhat the user sees:
subagentsdeferred, 3 of 5 runs end the turn withsessions_yield, and the result arrives in the following completion message.subagents wait. That pattern only exists since fix(agents): keep polling tools visible so the repeat guard reads their own exemption #206801.sessions_yieldpresentation gap, not caused by this change.--localcaveat: every variant's spawn then fails at runtime with "published reply runtime missing". That is a separate open gap, so only the call counts on that route.No worker protocol change. Workers compact Tool Search locally from each tool's own
true | { actions }declaration, so the dispatcher form never crosses the wire. No change reaches the Control UI bundle either: sharedcore-tool-facts.tsis untouched.