Skip to content

fix(agents): fork sessions on every guarded provider transport - #197223

Merged
obviyus merged 2 commits into
mainfrom
openclaw/fork-any-provider
Nov 11, 2026
Merged

obviyus merged 2 commits into
mainfrom
openclaw/fork-any-provider

Conversation

@obviyus

@obviyus obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Session forks (Advisor reviews, /btw with the full session) only ran on four provider APIs. Every other API failed before dispatch:

Session forks do not support provider API google-interactions. Use OpenAI Responses, Chat Completions, or Anthropic Messages.
Session forks do not support provider API ollama. Use OpenAI Responses, Chat Completions, or Anthropic Messages.

The gate was the FORK_TOOL_CHOICE_SHAPES map (added in #170146, folded into the gate by #177651). It mixed two separate requirements:

  1. Live fork authority at send time. feat(plugins): fork a session's live context for background side questions #170146 fails closed on APIs "whose sends the fork cannot fence (for example Bedrock)". Fork authority is checked by the guarded fetch before every physical send (DNS/proxy setup, retries, redirects), and by responsesRequestLifecycle for native Responses WebSockets.
  2. Hosted tools. The fork already denies client tool calls in its own loop. tool_choice: none is 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):

  • Authority: reject only bedrock-converse-stream. Its AWS SDK sends requests and retries through its own NodeHttpHandler, 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 for google-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: the four APIs with a known shape still get 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 Gemini functionDeclarations group), 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: docs/plugins/sdk-runtime.md.

Evidence

Live, isolated Gateway (createOpenClawTestInstance), real provider APIs, Advisor everyToolCalls: 1, parent turn calls session_status 3 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):

Model (API) Fork result
google/gemini-3.5-flash-lite (google-interactions) 3/3 failed: Session forks do not support provider API google-interactions
ollama-cloud/gpt-oss:20b (ollama) 3/3 failed: Session forks do not support provider API ollama

After (this branch):

Model (API) Fork requests Outcome Wire usage per fork request
Gemini (google-interactions) 3 2 reviews answered (no correction, no decision). One fork asked for session_status; the fork denied it (the next request carries Tool execution denied…), and the tool did not run input 3167 / 3498 / 3536, total_cached_tokens 0, output 3 / 17 / 1
Ollama (ollama), 6-call parent 4 3 reviews answered (1 steered the parent, 2 no correction); 0 tool calls in fork responses prompt_eval_count 2746 / 3361 / 5494, prompt_eval_cached_count 2427 / 2996 / 3136, eval_count 586 / 998 / 160
Anthropic claude-haiku-5-5 (regression) 2 2 answered (1 steer); tool_choice: {type: none} input 4 / 4, cacheRead 4063 / 4481, cacheWrite 792 / 817
OpenAI gpt-5.6-luna (openai-responses, regression) 2 2 answered (1 steer); tool_choice: none input 7851 / 8515, cached 0 / 6956
  • Parent turns completed normally on every route. No tool ran inside any fork.
  • The last fork of each 3-call Ollama run, and of the 6-call run, ended with admitted run authority is no longer active because the parent run settled while the fork was in flight. The same error appears on OpenAI runs on main (parent settles first). It is not changed here.
  • Gemini reported no cached tokens on these ~3k-token prompts. This PR claims no cache change on any provider.

Tests (src/agents/embedded-agent-runner/session-fork.test.ts), red on main, 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:changed passed; 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.

obviyus and others added 2 commits November 11, 2026 18:35
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
@clawsweeper

clawsweeper Bot commented Nov 11, 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 docs Improvements or additions to documentation agents Agent runtime and tooling plugin: file-transfer size: S labels Nov 11, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 11, 2026
@clawsweeper

clawsweeper Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: The fork fails before dispatch because google-interactions is outside the API allowlist.
  • After: The fork answers using the session context; requested client tools receive denial results.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, useful repair with concrete live provider results and supporting authorization-boundary coverage.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Supplied isolated-Gateway Advisor results exercise real Gemini and Ollama forks, answers, client-tool denial, and existing-provider regressions; the production-path Google SDK regression checks revoked access before physical fetch, supported by existing Gateway visibility and redirect coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Advisor and other full-context session-fork consumers fail on Gemini and Ollama before making a provider request.
Reason: The feature-history owner supplies the direction and concrete before/after provider results; the focused repair extends the existing capability without adding configuration or another execution owner.

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
Reviewed head: 3e0faa3eb6562f1b9d03e669fdac07c926b5a0b7

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Provider admission changes intended behavior with a stated reason (164bd67: Restrict forks to transports that can enforce live authorization and prevent hosted-tool execution; refactor(agents): reuse canonical model runtime facts #177651 later consolidated the roster.)
  • Known API tool-choice handling keeps the original intent (3ef64ea: Restore tool-choice disabling after live measurements disproved the claimed benefit of retaining the parent's choice.)
  • Request reconstruction and transport authority keeps the original intent (cb00966: Build forks only when requested through existing payload builders while preserving current session authority, credentials, and network policy.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

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

View PR surface stats
Area Files Added Removed Net
Source 1 49 10 +39
Tests 1 47 49 -2
Docs 1 10 7 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 106 66 +40

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: The gap blocks optional full-context background reviews on Gemini and Ollama while ordinary parent turns remain usable.
  • add merge-risk: 🚨 compatibility: The public forkSession operation gains provider coverage and new hosted-tool rejection behavior; the collaborator-authored direction explicitly accepts this additive contract change.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: The gap blocks optional full-context background reviews on Gemini and Ollama while ordinary parent turns remain usable.
  • merge-risk: 🚨 compatibility: The public forkSession operation gains provider coverage and new hosted-tool rejection behavior; the collaborator-authored direction explicitly accepts this additive contract change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • 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.

Reviewed November 11, 2026, 8:22 AM ET / 13:22 UTC.

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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. plugin: file-transfer proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

1 participant