Repository navigation
fix(agents): fork sessions on every guarded provider transport - #197223
Conversation
Session forks (Advisor reviews, /btw) rejected every API without a known tool_choice shape, so Gemini and Ollama forks failed before dispatch. The allowlist mixed two requirements: live fork authority at send time, and stopping provider-hosted tools that run before the fork can deny them. Gate each one on its own: - Reject only Bedrock, whose AWS SDK sends and retries through its own HTTP handler and cannot enforce live fork authority. - Require an egress check outside the Responses WebSocket lifecycle, so the Google GenAI SDK also sends through the guarded fetch. - Keep tool_choice none on the four APIs with a known shape. Elsewhere keep the parent's tool choice, rely on the existing client-tool denial loop, and fail the fork if its request carries a provider-hosted tool. Co-authored-by: obviyus <[email protected]>
OpenClaw-Publication: 69c5ec87-3109-42a3-9d31-79254fd22ab9
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR enables session forks on guarded provider transports while retaining send-time authorization and preventing tool execution. Example: Advisor reviews a session using google/gemini-3.5-flash-lite through google-interactions.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses a provider-coverage gap still present on main, with useful live results and no actionable introduced defect identified. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe embedded session-fork runner receives prepared conversation context and current authorization, sends a tool-denied question through the provider transport, and returns text and usage. flowchart TD
A[Plugin fork request] --> B[Gateway session authorization]
B --> C[Prepared conversation context]
C --> D[Session fork runner]
D --> E[Hosted tool policy]
E --> F[Guarded provider transport]
F --> G[Text and usage]
Technical reviewBest possible solution: Use the existing fork runner and guarded transport owners to admit additional providers while preserving authorization and tool-denial boundaries. Do we have a high-confidence way to reproduce the issue? Current-main source deterministically rejects google-interactions and ollama before dispatch, matching the supplied Gateway failures; no target code was executed during this read-only review. Is this the best way to solve the issue? The change separates two previously conflated requirements within the existing owner, preserves established API behavior, and adds the Google SDK egress enforcement needed for safe admission. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 021201c20aaf. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +39, Tests -2, Docs +3. Total +40 across 3 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 11, 2026, 8:22 AM ET / 13:22 UTC. |
…law#197223) Co-authored-by: obviyus <[email protected]>
What Problem This Solves
Session forks (Advisor reviews,
/btwwith the full session) only ran on four provider APIs. Every other API failed before dispatch:The gate was the
FORK_TOOL_CHOICE_SHAPESmap (added in #170146, folded into the gate by #177651). It mixed two separate requirements:responsesRequestLifecyclefor native Responses WebSockets.tool_choice: noneis only needed for provider-hosted tools (for example web search), which run before the fork can deny them.Neither requirement needs an allowlist of four APIs.
Fix
All in
session-fork.ts(one owner, no per-provider branches elsewhere):bedrock-converse-stream. Its AWS SDK sends requests and retries through its ownNodeHttpHandler, so a revoked fork could still send. Outside the Responses WebSocket lifecycle, the fork now also passes its check as a guarded-fetch egress check. This makes SDKs that otherwise choose their own fetch (the Google GenAI SDK forgoogle-generative-ai/google-vertex) send through the guarded fetch. Transports checked: Anthropic, OpenAI Completions/Responses, Azure, Mistral and Google Interactions already use the host fetch. Ollama and Radius plugin streams use the guarded fetch. Bedrock does not.tool_choice: none(unchanged; fix(agents): keep session forks on the parent's cached prompt prefix #197074 tried keeping the parent's Anthropic tool choice and was reverted in Revert "fix(agents): keep session forks on the parent's cached prompt prefix" #197175 because it gave no cache gain). Other APIs keep the parent's tool choice and use the existing denial loop. If their request carries a provider-hosted tool (anything that is not a function/custom declaration, an Anthropic client tool, or a GeminifunctionDeclarationsgroup), the fork fails before the request is sent:Session forks cannot disable provider-hosted tools on provider API <api>. Remove hosted tools from this model's requests to fork it.docs/plugins/sdk-runtime.md.Evidence
Live, isolated Gateway (
createOpenClawTestInstance), real provider APIs, AdvisoreveryToolCalls: 1, parent turn callssession_status3 times (6 for the second Ollama run). Request/response bodies were captured in-process (headers never recorded). Usage is what each provider reported on the wire.Before (origin/main
6d71e65):google/gemini-3.5-flash-lite(google-interactions)Session forks do not support provider API google-interactionsollama-cloud/gpt-oss:20b(ollama)Session forks do not support provider API ollamaAfter (this branch):
google-interactions)no correction,no decision). One fork asked forsession_status; the fork denied it (the next request carriesTool execution denied…), and the tool did not runtotal_cached_tokens0, output 3 / 17 / 1ollama), 6-call parentno correction); 0 tool calls in fork responsesprompt_eval_count2746 / 3361 / 5494,prompt_eval_cached_count2427 / 2996 / 3136,eval_count586 / 998 / 160claude-haiku-5-5(regression)tool_choice: {type: none}gpt-5.6-luna(openai-responses, regression)tool_choice: noneadmitted run authority is no longer activebecause the parent run settled while the fork was in flight. The same error appears on OpenAI runs onmain(parent settles first). It is not changed here.Tests (
src/agents/embedded-agent-runner/session-fork.test.ts), red onmain, green here:blocks the google-generative-ai send when access is withdrawn during guarded DNS preparation: real Google GenAI SDK stream. Without the egress check, the SDK sent the request through its own fetch (Google stream ended before a terminal finish reason).forks ollama requests …: client tools fork with the parent's tool choice unchanged; a hosted tool fails before send; Bedrock is still rejected before dispatch; Anthropic hosted tools still get{type: none}(this case replaces the earlier transport-level Anthropic hosted-search test, whose tools/system retention the full-run fork suite already covers).Checks: test-lines ratchet OK (net −2 lines, no allocation);
OPENCLAW_CHECK_CHANGED_SKIP_DEADCODE=1 pnpm check:changedpassed; oxlint/oxfmt clean on changed files.Not covered live: native ChatGPT (
openai-chatgpt-responses) needs OAuth; its fork path is unchanged (no egress check added, WebSocket lifecycle kept), covered by the existing redirect/lifecycle tests.