Skip to content

fix: apply output reducers in headless and Code Mode calls - #199424

Closed
roboclaw-bot wants to merge 2 commits into
mainfrom
openclaw/briny-shell-2
Closed

roboclaw-bot wants to merge 2 commits into
mainfrom
openclaw/briny-shell-2

Conversation

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes enabled tool-output reducers silently being skipped in headless runs and nested Code Mode tool calls.

User Impact

Enabled middleware such as Tokenjuice can transform actual OpenClaw tool results before they reach the agent, including nested Code Mode shell calls. Exact file/schema results and the surrounding JavaScript envelope retain their existing contracts. Bounded-command guidance now recommends the existing terminal-result collection path instead of avoidable short-yield/poll cycles.

No new configuration, dependencies, permission changes, or migrations. Native Codex shell results remain outside this replacement path. This PR does not claim a whole-task token-savings percentage.

Why This Change Was Made

Headless runs prepare a scoped plugin generation, but middleware discovery consulted the process-global registry and could select no callback or a different same-ID root plugin. Discovery now follows the current context and its prepared lazy-load inputs. Native catalog calls also apply the existing middleware once before guest serialization, using the arguments actually executed after policy adjustment.

The exec runtime already supports awaitResults; the prompt and documentation now explain when to use it. Tokenjuice guidance distinguishes real output replacement from plugin inventory status and separates native replacement, explicit wrapping, failure preservation, and complete-task measurements.

Evidence

  • Scoped-only, empty-root, and same-ID lazy-owner regressions fail on the unchanged base and pass with the fix.
  • The Code Mode regression uses a real worker and shell: once-only transformation, policy-adjusted command/cwd, exit/error metadata, unchanged exact file/schema bytes, and intact outer envelope.
  • Combined candidate: 43 tests pass across six focused files/four shards. Supporting lane checks cover the affected Code Mode, Tool Search, MCP, headless, native-hook, and prefix-stability consumers.
  • Existing terminal-wait subprocess proof preserves exit 7, explicit background behavior, and timeout cleanup without changing runtime defaults.
  • Scoped types/lint and ten-file formatting pass; the changed MDX pages pass validation.
  • Local autoreview of the complete candidate at P0–P2: no actionable findings; supplied source review, not test execution. Local ClawSweeper was unavailable from a clean built runner.
  • Full pnpm build passes (it emits UI size-budget advisory warnings; this change does not touch UI source). Built real-model headless runs pass with direct tools and Code Mode: automatic inventory compaction is 5,647 → 470 characters including the notice; exit 7/sentinel, exact file bytes, and the returned schema object are preserved. No manual CLI wrapper or global-root activation workaround.

Requested by @vincentkoc.

Work sessions

Linked for team reference; these sessions aren’t public.

Worked on by

roboclaw-bot and others added 2 commits November 15, 2026 04:16
Use the prepared plugin registry for middleware discovery and apply result middleware at the native catalog boundary. Recommend terminal collection for bounded commands and clarify Tokenjuice verification.

Co-authored-by: vincentkoc <[email protected]>
Worked on by:
- @vincentkoc

Co-authored-by: vincentkoc <[email protected]>
OpenClaw-Publication: c09834cf-a11f-89ad-b92c-4f9b61b6725a
@clawsweeper

clawsweeper Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M labels Nov 15, 2026
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 size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant