openclaw - 💡(How to fix) Fix tokenjuice tool-result middleware discards `message` tool results on codex runtime, breaking Signal/channel replies

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

The bundled tokenjuice plugin's tool_result middleware produces output that fails OpenClaw's isValidMiddlewareToolResult check for the message tool when the codex harness is active. The gateway then substitutes the result with "Tool output unavailable due to post-processing error.", so any agent running on the codex runtime that calls message(...) to reply on a channel (Signal in our case) effectively can't deliver messages back to the user — the model sees the failure result and the user sees silence.

Error Message

The bundled tokenjuice plugin's tool_result middleware produces output that fails OpenClaw's isValidMiddlewareToolResult check for the message tool when the codex harness is active. The gateway then substitutes the result with "Tool output unavailable due to post-processing error.", so any agent running on the codex runtime that calls message(...) to reply on a channel (Signal in our case) effectively can't deliver messages back to the user — the model sees the failure result and the user sees silence.

  • The model receives "Tool output unavailable due to post-processing error." as the message tool result instead of the actual delivery ack.
  1. tool-result-middleware-ecm3p4oK.js:312–344createAgentToolResultMiddlewareRunner runs each registered handler, then validates with isValidMiddlewareToolResult. On failure it logs discarded invalid tool result middleware output for <toolName> and returns buildMiddlewareFailureResult() (the "post-processing error" stub).

Root Cause

Code path:

  1. tool-result-middleware-ecm3p4oK.js:312–344createAgentToolResultMiddlewareRunner runs each registered handler, then validates with isValidMiddlewareToolResult. On failure it logs discarded invalid tool result middleware output for <toolName> and returns buildMiddlewareFailureResult() (the "post-processing error" stub).
  2. tool-result-middleware-ecm3p4oK.js:295–298 — validator requires value to be a record, value.content to be an array, ≤ MAX_MIDDLEWARE_CONTENT_BLOCKS, every block valid, details valid.
  3. tool-result-middleware-DVoORBab.js:15–30 — tokenjuice middleware iterates tool_result handlers registered via createTokenjuiceOpenClawEmbeddedExtension, merging {content, details} returned by each handler. One of those handlers is producing a shape for the message tool that fails the validator (content not an array, exceeds the block cap, or invalid block/details shape).
  4. agent-tool-result-middleware-loader-Cal8O2Qc.js:20–53 — codex runtime loads tokenjuice's middleware via listMiddlewareOwnerPluginIds, so this fires on every codex-runtime tool call.

The claude-cli runtime does not load tokenjuice middleware, so this only affects agents currently routed through the codex harness.

Fix Action

Workaround

Disable the tokenjuice plugin in openclaw.json:

"tokenjuice": { "enabled": false, "config": {} }

After hot-reload + restart, loadAgentToolResultMiddlewaresForRuntime("codex") returns an empty handler list, the message tool result passes through unmodified, and channel replies resume immediately. The cost is losing token compaction across all other tool results too.

Code Example

[agents/harness] [codex] discarded invalid tool result middleware output for message

---

"tokenjuice": { "enabled": false, "config": {} }
RAW_BUFFERClick to expand / collapse

Summary

The bundled tokenjuice plugin's tool_result middleware produces output that fails OpenClaw's isValidMiddlewareToolResult check for the message tool when the codex harness is active. The gateway then substitutes the result with "Tool output unavailable due to post-processing error.", so any agent running on the codex runtime that calls message(...) to reply on a channel (Signal in our case) effectively can't deliver messages back to the user — the model sees the failure result and the user sees silence.

Symptoms

  • Main agent on a channel (Signal) appears unresponsive — turns complete on the backend but no reply arrives on the channel.
  • Gateway log shows this line every time the agent tries to reply:
    [agents/harness] [codex] discarded invalid tool result middleware output for message
  • The model receives "Tool output unavailable due to post-processing error." as the message tool result instead of the actual delivery ack.
  • The cli-backend turn itself completes normally (claude live session turn ... durationMs=...), so this is not an LLM/runtime hang — it's a post-processing failure.

Root cause

Code path:

  1. tool-result-middleware-ecm3p4oK.js:312–344createAgentToolResultMiddlewareRunner runs each registered handler, then validates with isValidMiddlewareToolResult. On failure it logs discarded invalid tool result middleware output for <toolName> and returns buildMiddlewareFailureResult() (the "post-processing error" stub).
  2. tool-result-middleware-ecm3p4oK.js:295–298 — validator requires value to be a record, value.content to be an array, ≤ MAX_MIDDLEWARE_CONTENT_BLOCKS, every block valid, details valid.
  3. tool-result-middleware-DVoORBab.js:15–30 — tokenjuice middleware iterates tool_result handlers registered via createTokenjuiceOpenClawEmbeddedExtension, merging {content, details} returned by each handler. One of those handlers is producing a shape for the message tool that fails the validator (content not an array, exceeds the block cap, or invalid block/details shape).
  4. agent-tool-result-middleware-loader-Cal8O2Qc.js:20–53 — codex runtime loads tokenjuice's middleware via listMiddlewareOwnerPluginIds, so this fires on every codex-runtime tool call.

The claude-cli runtime does not load tokenjuice middleware, so this only affects agents currently routed through the codex harness.

Reproduction

  1. Have a main agent configured to run on the codex harness with tokenjuice enabled.
  2. Send a message to the agent on Signal (or any channel that exits via the message tool).
  3. Watch the agent compose a reply, call message(...), then observe the gateway log emit [agents/harness] [codex] discarded invalid tool result middleware output for message.
  4. Verify no reply lands on the channel.

Workaround

Disable the tokenjuice plugin in openclaw.json:

"tokenjuice": { "enabled": false, "config": {} }

After hot-reload + restart, loadAgentToolResultMiddlewaresForRuntime("codex") returns an empty handler list, the message tool result passes through unmodified, and channel replies resume immediately. The cost is losing token compaction across all other tool results too.

Suggested fix

  • Identify which tokenjuice tool_result handler returns the invalid shape for message — most likely a content-block transform that returns a string/object instead of an array of content blocks, or one that exceeds MAX_MIDDLEWARE_CONTENT_BLOCKS.
  • Either (a) scope the offending handler to only tools where compaction is meaningful (the message tool's result is a small delivery ack — there is nothing to compress), or (b) ensure the handler always returns a shape that satisfies isValidMiddlewareToolResult.
  • Optional hardening: when middleware validation fails, log the actual shape produced (truncated) rather than just the tool name, so this kind of bug is debuggable from logs alone instead of requiring a code dive.

Environment

  • OpenClaw 2026.5.12 (gateway commit f066dd2)
  • Codex CLI 0.130.0
  • Affected harness: codex (agent_runtime: codex (source=model))
  • Channel observed: Signal (agent:main:signal:direct:...)

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING