Repository navigation
fix(agents): strip empty tools/tool_choice from embedded runner payloads - #70790
kiranvk-2011 wants to merge 3 commits into
Conversation
Greptile SummaryThis PR adds
Confidence Score: 4/5Safe to merge with the understanding that the session-http-fallback path remains unprotected — a one-line fix covers the gap. The core fix is sound and well-targeted. One code path (shouldUseWebSocketTransport=true with no wsApiKey) escapes the wrapper and still exposes tools: [] to strict providers, which is an incomplete fix for the stated goal. src/agents/pi-embedded-runner/stream-resolution.ts — the session-http-fallback branch at line 113 needs wrapStreamFnStripEmptyTools.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e2f4ceeb52
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| */ | ||
| function wrapStreamFnStripEmptyTools(base: StreamFn): StreamFn { | ||
| return (model, context, options) => { | ||
| return base(model, context, { |
There was a problem hiding this comment.
Preserve receiver when invoking wrapped custom stream functions
This wrapper changes custom currentStreamFn execution from a direct return to an unbound call (base(model, ...)), which drops call-site this. Any session-provided stream function implemented as an object method (reading instance state via this) will now fail or read undefined state in embedded runs, whereas it worked before when the function was returned unchanged. Call the wrapped function with the original receiver (for example via .call) or avoid wrapping arbitrary custom stream functions.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The StreamFn type (from @mariozechner/pi-agent-core) is defined as a standalone function type: type StreamFn = (...args: Parameters<typeof streamSimple>) => ReturnType<typeof streamSimple>. All streamFn assignments in the codebase use standalone functions (createOpenAIWebSocketStreamFn, createBoundaryAwareStreamFnForModel, streamSimple, etc.), never methods with a receiver. The existing wrapper in this same file (resolveEmbeddedAgentStreamFn, lines 89-100) already uses the same unbound call pattern for inner(), establishing this as the accepted convention. This wrapper follows the same pattern.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 59fd1a49d3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| */ | ||
| function wrapStreamFnStripEmptyTools(base: StreamFn): StreamFn { | ||
| return (model, context, options) => { | ||
| return base(model, context, { |
There was a problem hiding this comment.
Bind wrapped stream calls to preserve custom receiver
wrapStreamFnStripEmptyTools calls base(model, context, ...) as an unbound function, so wrapped custom stream functions lose their call-site this. Fresh evidence: this commit now routes both the websocket HTTP fallback branch and the final custom-stream return path through this wrapper, so session stream methods that read instance state via this can now throw or behave incorrectly where they previously worked when returned directly.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
See my reply above — StreamFn is a standalone function type, not a method. The existing wrapper pattern in this file already calls inner() unbound. This is the established convention and the type system enforces standalone functions. No custom receiver is used anywhere in the codebase for StreamFn implementations.
|
Would be good to get this merged. This issue is causing active memory to break. Edit: while this is I believe one issue causing active memory to break, it’s not the sole one |
|
Codex review: needs real behavior proof before merge. Latest ClawSweeper review: 2026-05-20 17:49 UTC / May 20, 2026, 1:49 PM ET. Workflow note: Future ClawSweeper reviews update this same comment in place. How this review workflow works
Summary Reproducibility: yes. at source level: Active Memory passes PR rating Rank-up moves:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. Real behavior proof Mantis proof suggestion Risk before merge
Maintainer options:
Next step before merge Security Review findings
Review detailsBest possible solution: Land a rebased embedded-runner payload sanitizer that covers provider-owned, PI-native, boundary-aware, and custom stream paths, runs at the final payload boundary, and includes focused payload assertions plus redacted strict-provider proof. Do we have a high-confidence way to reproduce the issue? Yes, at source level: Active Memory passes Is this the best way to solve the issue? No, not yet. A payload-level sanitizer is the right shape, but this branch is stale/conflicted, misses current-main stream branches, and lacks inspectable after-fix strict-provider proof. Label justifications:
Full review comments:
Overall correctness: patch is incorrect Acceptance criteria:
What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against a13468320c63. |
fe1cc32 to
17a6cb8
Compare
When active-memory plugin invokes sub-agents with toolsAllow, the tools get filtered to [] in the embedded runner context. Strict OpenAI-compatible providers (DashScope/GLM, Kimi, vLLM) reject tools: [] with HTTP 400. Adds wrapStreamFnStripEmptyTools() as a payload interceptor that: - Strips tools entirely when array is empty - Strips tool_choice when tools is absent Consolidates openclaw#59898, openclaw#66710, openclaw#47947 into a single guard. Fixes openclaw#53174.
…guard The test previously expected custom currentStreamFn to pass through unchanged (same reference). Now that wrapStreamFnStripEmptyTools wraps all stream functions, update the assertion to expect a different reference.
Greptile review finding: when shouldUseWebSocketTransport=true but wsApiKey is absent, currentStreamFn was returned unwrapped, bypassing the empty-tools interceptor. Wrap it consistently.
17a6cb8 to
28cae76
Compare
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
… endpoints Strict OpenAI-compatible servers (vLLM, LocalAI, llama.cpp, LM Studio) and current OpenAI itself reject requests containing tools: []. Strip the empty tools array (and the orphan tool_choice) from outbound chat-completions payloads when usesExplicitProxyLikeEndpoint is true. Native OpenAI/Azure/ OpenRouter routes are byte-identical. Supersedes openclaw#70790 at the canonical payload builder seam so the gateway, embedded runner, and public plugin-SDK consumers (zai/xiaomi/deepseek) all benefit.
… endpoints Strict OpenAI-compatible servers (vLLM, LocalAI, llama.cpp, LM Studio) and current OpenAI itself reject requests containing tools: []. Strip the empty tools array (and the orphan tool_choice) from outbound chat-completions payloads when usesExplicitProxyLikeEndpoint is true. Native OpenAI/Azure/ OpenRouter routes are byte-identical. Supersedes #70790 at the canonical payload builder seam so the gateway, embedded runner, and public plugin-SDK consumers (zai/xiaomi/deepseek) all benefit.
|
Thanks for digging into this. I landed the fix via #85835 instead because it patches the canonical Landed on |
… endpoints Strict OpenAI-compatible servers (vLLM, LocalAI, llama.cpp, LM Studio) and current OpenAI itself reject requests containing tools: []. Strip the empty tools array (and the orphan tool_choice) from outbound chat-completions payloads when usesExplicitProxyLikeEndpoint is true. Native OpenAI/Azure/ OpenRouter routes are byte-identical. Supersedes #70790 at the canonical payload builder seam so the gateway, embedded runner, and public plugin-SDK consumers (zai/xiaomi/deepseek) all benefit.
… endpoints Strict OpenAI-compatible servers (vLLM, LocalAI, llama.cpp, LM Studio) and current OpenAI itself reject requests containing tools: []. Strip the empty tools array (and the orphan tool_choice) from outbound chat-completions payloads when usesExplicitProxyLikeEndpoint is true. Native OpenAI/Azure/ OpenRouter routes are byte-identical. Supersedes openclaw#70790 at the canonical payload builder seam so the gateway, embedded runner, and public plugin-SDK consumers (zai/xiaomi/deepseek) all benefit.
… endpoints Strict OpenAI-compatible servers (vLLM, LocalAI, llama.cpp, LM Studio) and current OpenAI itself reject requests containing tools: []. Strip the empty tools array (and the orphan tool_choice) from outbound chat-completions payloads when usesExplicitProxyLikeEndpoint is true. Native OpenAI/Azure/ OpenRouter routes are byte-identical. Supersedes openclaw#70790 at the canonical payload builder seam so the gateway, embedded runner, and public plugin-SDK consumers (zai/xiaomi/deepseek) all benefit.
… endpoints Strict OpenAI-compatible servers (vLLM, LocalAI, llama.cpp, LM Studio) and current OpenAI itself reject requests containing tools: []. Strip the empty tools array (and the orphan tool_choice) from outbound chat-completions payloads when usesExplicitProxyLikeEndpoint is true. Native OpenAI/Azure/ OpenRouter routes are byte-identical. Supersedes openclaw#70790 at the canonical payload builder seam so the gateway, embedded runner, and public plugin-SDK consumers (zai/xiaomi/deepseek) all benefit.
… endpoints Strict OpenAI-compatible servers (vLLM, LocalAI, llama.cpp, LM Studio) and current OpenAI itself reject requests containing tools: []. Strip the empty tools array (and the orphan tool_choice) from outbound chat-completions payloads when usesExplicitProxyLikeEndpoint is true. Native OpenAI/Azure/ OpenRouter routes are byte-identical. Supersedes openclaw#70790 at the canonical payload builder seam so the gateway, embedded runner, and public plugin-SDK consumers (zai/xiaomi/deepseek) all benefit.
Problem
When the
active-memoryplugin invokes sub-agents withtoolsAllow: ["memory_search", "memory_get"], these tools are unavailable in the embedded runner context and get filtered down to an empty arraytools: []. Strict OpenAI-compatible providers (DashScope/GLM, Kimi, vLLM) reject this with:This affects any sub-agent flow (active-memory, cron, etc.) using DashScope/GLM or similar providers through the embedded runner.
Root Cause Chain
This bug has been tracked across multiple issues and partial-fix PRs:
/btwcommand fails with ModelStudio provider:400 [] is too short - 'tools'toolsAllowthrough the embedded runner call chaintool_choicewhen tools array is emptytoolsAllowparameter not forwarded torunEmbeddedAttemptWithBackendtoolsAllowfilter (toolsAllownot forwarded inrunEmbeddedPiAgent)Solution
Consolidates all three open PRs (#59898, #66710, #47947) into a single, minimal payload interceptor at the stream-resolution layer —
src/agents/pi-embedded-runner/stream-resolution.ts.Adds
wrapStreamFnStripEmptyTools()which:toolsentirely when the array is empty (length === 0) — correct behavior for tool-less requests per the OpenAI API spectool_choicesimultaneously whentoolsis absent — some providers rejecttool_choicewithout a correspondingtoolsarray (fix: strip tool_choice from payload when tools array is empty #47947)Why This Approach
toolsAllowforwarding; it is a defensive guard at the egress boundarybailian/glm-5via Telegram — active-memory queries succeed without the 400 errorChange
Verification
ghcr.io/kiranvk-2011/openclaw:0.0.0-emptytools-fix)bailian/glm-5(DashScope provider) — no more 400 rejectionactive-memory)🤖 AI-assisted PR — lightly tested. Built and validated via CI + test container deployment.