Skip to content

fix(agents): read dispatched tools' repeat exemptions and defer the delegation family together - #207314

Merged
obviyus merged 15 commits into
mainfrom
core/spawn-discovery
Nov 28, 2026
Merged

obviyus merged 15 commits into
mainfrom
core/spawn-discovery

Conversation

@obviyus

@obviyus obviyus commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

With Tool Search on (the default), #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 #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:

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 6d8e821a 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 6d8e821a:

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:
  • 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.

@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Nov 28, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. labels Nov 28, 2026
@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. labels Nov 28, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 28, 2026
@clawsweeper

clawsweeper Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

This 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.

  • Before: agents_wait and subagents are direct tools, while sessions_spawn is deferred and can be mistaken for unavailable.
  • After: sessions_spawn appears directly alongside agents_wait and subagents.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation has no definite source finding, but required runtime evidence is not inspectable and failing CI diagnostics remain incompletely attributed.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An agent can claim delegation is unavailable because it sees subagent status tools directly while the spawning tool is deferred.
Reason: The maintainer-authored direction addresses a reported default-path failure and explicitly accepts the measured schema cost.

Regression provenance

Possible 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: 1abea250f555516156a73096f2814dad06ddffaf

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Polling-tool visibility keeps the original intent (afd8195: Expose repeatable polling tools directly so the repeat guard reads their own exemption rather than dispatch_action's declaration.)
  • Core tool metadata keeps the original intent (6ee2a38: Separate canonical tool identities and policy facts from presentation descriptions to avoid loading the catalog on chat boot.)
  • Catalog selectors and on-demand tools changes intended behavior with a stated reason (feat: choose which tools are deferred behind Tool Search #170071: Allow operators to choose deferred tools while preserving direct capabilities; the family rule deliberately extends direct visibility across related core tools.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit f405852 adds src/agents/tool-search-catalog.ts:294 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f4058528e5db; files: src/agents/tool-search-catalog.ts)
  • Vincent Koc: Raw commit 6ee2a38 adds src/agents/core-tool-facts.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 6ee2a3846eb1; files: src/agents/core-tool-facts.ts)

PR surface

Source +29, Tests +44, Docs +4. Total +77 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 39 10 +29
Tests 1 53 9 +44
Docs 1 6 2 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 98 21 +77

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 rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • 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.

Reviewed November 28, 2026, 2:37 AM ET / 07:37 UTC.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: L and removed size: S labels Nov 28, 2026
@obviyus obviyus changed the title fix(agents): send sessions_spawn with its delegation family under Tool Search fix(agents): read dispatched tools' repeat exemptions and defer the delegation family together Nov 28, 2026
# Conflicts:
#	packages/gateway-protocol/src/compiled/protocol.generated/predicates.js
@openclaw-barnacle openclaw-barnacle Bot added size: L and removed app: web-ui App: web-ui gateway Gateway runtime size: XL labels Nov 28, 2026
@obviyus
obviyus merged commit 8eb9596 into main Nov 28, 2026
134 checks passed
@obviyus
obviyus deleted the core/spawn-discovery branch November 28, 2026 09:50
@obviyus

obviyus commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

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.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 29, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L 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