Skip to content

fix: avoid duplicate deferred tool results - #169537

Merged
obviyus merged 2 commits into
openclaw:mainfrom
TUARAN:fix/tool-search-result-projection
Oct 14, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
TUARAN:fix/tool-search-result-projection

Conversation

@TUARAN

@TUARAN TUARAN commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #169492. Deferred tool execution used to serialize a target's structured payload twice: once in its text content and again in result.details. Keep the model-facing result's content and status fields, but retain the complete result only in the control tool's structured details for runtime/UI consumers. Images and termination/error handling remain intact.

Original fix by @TUARAN; reported in #169492.

Evidence

Built CLI, isolated state, recording OpenAI-compatible scripted provider. The scripted turn searches for sessions_list, dispatches it, then records the next provider request. State was created through the shipped agent command, not database writes.

Captured, redacted output:

                         structured count payload occurrences   nested result.details
base deferred                           2                              present
candidate deferred                      1                              absent
base direct                             1                              absent
candidate direct                        1                              absent

The direct-call control retains the same result fields (count, sessions, hasMore, limitApplied). Session identifiers and timestamps naturally differ between isolated runs. Current main renamed the deferred dispatcher from tool_call to dispatch_action; the integrated candidate uses that shipped name.

Exact-head checks: 60 Tool Search tests passed; changed-file formatting and lint passed. Simplification retained the existing result-projection owner and extended the existing regression rather than adding scaffolding. Production delta: +4/-7; tests: +2/-1.

Live gate on openai/gpt-5.4-mini, explicitly using the OpenClaw runtime:

tool_search -> sessions_list discovered
dispatch_action -> sessions_list(limit=1) returned one session
final: Success — I found `sessions_list` and listed one session.
exit=0

The persisted live transcript confirms both tool execution and the final reply.

No overlap with Pash/Sarah changes.

Risk

Two-way door: reverting restores the previous context projection without changing persisted state or configuration. Blast radius is model context for deferred Tool Search calls; direct tool calls are unchanged. Runtime/UI consumers still receive the complete structured result.

@clawsweeper

clawsweeper Bot commented Oct 12, 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 triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. docs Improvements or additions to documentation agents Agent runtime and tooling size: XS and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR removes nested structured details from model-facing deferred tool results while retaining the complete result for runtime consumers.

Example: An agent discovers sessions_list and invokes dispatch_action with limit=1.

  • Before: The next provider request contains the session payload twice, inside content text and nested result.details.
  • After: The provider receives one payload copy; runtime consumers retain the complete structured result.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, useful repair with supplied CLI boundary evidence, preserved runtime contracts, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The updated body records the changed Tool Search projection through a built CLI with isolated state and a recording OpenAI-compatible provider: deferred payload copies fall from two to one, nested details disappears, and direct controls retain their fields; a live OpenClaw turn completes discovery and dispatch, resolving the earlier shipped-entry-point proof gap.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Deferred JSON tool results unnecessarily consume model context twice and reduce the space available for useful output.
Reason: The narrow repair restores the content-versus-runtime-details boundary and addresses the linked report without adding configuration or changing tool execution.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current deferred-result duplication bug with a focused projection change; no actionable correctness or security findings remain.

Priority: P2
Reviewed head: 94ecf23ffa3700cd2639d0f768b779afba8ef91f

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: A before-fix execution of the focused regression is not supplied, although the CLI capture demonstrates the failing and repaired provider-bound behavior.
Agent review details

How this fits together

OpenClaw Tool Search dispatches authorized catalog tools and projects their returned content into provider-bound text and images while retaining structured details for runtime consumers.

flowchart LR
  A[Model tool request] --> B[Tool Search dispatcher]
  B --> C[Catalog execution owner]
  C --> D[Target tool result]
  D --> E[Model content projection]
  D --> F[Complete runtime details]
  E --> G[Provider request]
Loading

Technical review

Best possible solution:

Land the focused projection repair while preserving complete runtime details, existing image handling, and error semantics.

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

Current-main source establishes the duplicate serialization path, and the supplied CLI capture demonstrates it before the fix; this review ran no target code.

Is this the best way to solve the issue?

Removing details at the existing model-projection boundary restores direct-call parity without a new setting, competing owner, or change to execution and runtime consumers.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 2c130c7039f2.

Provenance checked

  • Deferred model-result projection changes intended behavior with a stated reason (b3dcb2d: Compact results retained exact identity and useful output without repeating discovery metadata.)
  • Deferred image forwarding keeps the original intent (3ff615b: Images must reach the model as image blocks while the full target result remains available in runtime details.)
  • Documented structured-call contract keeps the original intent (4b9c922: Preserve target arguments, validate trusted tool execution, and retain deferred external-tool contracts.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source -3, Tests +1, Docs +2. Total 0 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 4 7 -3
Tests 1 2 1 +1
Docs 1 10 8 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 16 16 0

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Duplicate deferred output wastes provider context and truncation budget without evidence of an urgent outage.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 (2 earlier review cycles)
  • reviewed 2026-10-12T02:23:18.432Z sha 8e2eb32 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-12T02:35:26.023Z sha 8e2eb32 :: needs real behavior proof before merge. :: none

Reviewed October 13, 2026, 11:18 PM ET / October 14, 2026, 03:18 UTC (Revision 3).

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 12, 2026
# Conflicts:
#	docs/tools/tool-search.md
@obviyus

obviyus commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Oct 14, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 14, 2026
@obviyus
obviyus merged commit 23e106f into openclaw:main Oct 14, 2026
139 of 141 checks passed
@obviyus

obviyus commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Landed in 23e106f. Thanks @TUARAN! Verified with a recording provider: deferred tool results now reach the model once.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
fix(tool-search): send deferred tool results to the model once

When the model called a deferred tool through Tool Search, the tool's structured result was serialized twice into the model context. This wasted tokens and the truncation budget. Deferred results now include the payload once, like direct tool calls.

Proof: built CLI with a recording provider. The deferred call's result payload appeared twice on main and once with this change; the direct-call control is once on both. A live openai/gpt-5.4-mini turn searched for and called sessions_list successfully.

Fixes openclaw#169492. Thanks @TUARAN.

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 P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS 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.

tool_call results render both content and details to the model — duplicate JSON doubles tool-result tokens and eats truncation budget

2 participants