Skip to content

feat(ai): scope transport hosts per runtime - #158901

Merged
RomneyDa merged 8 commits into
mainfrom
openclaw/pr-154390-native-worker-runtime
Oct 1, 2026
Merged

RomneyDa merged 8 commits into
mainfrom
openclaw/pr-154390-native-worker-runtime

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #154388

What Problem This Solves

Independent model runtimes need transport policy that cannot replace or inherit another runtime’s provider, authentication, routing, fallback state, or cached connection.

User Impact

Remote and native harnesses can run concurrently without leaking transport authority or connection state. Ordinary runtimes and browser imports keep their current defaults.

Why This Change Was Made

This adds a runtime-owned @openclaw/ai transport host. Explicit Node runtimes use createNodeLlmRuntime; ordinary runtimes keep the process default. Provider factories remain synchronous, while runtime scope is retained across lazy stream operations.

ChatGPT WebSocket reuse and SSE fallback are scoped by runtime host, endpoint, and authority-bearing headers. Managed-transport policy disables direct WebSocket paths, and process-default state remains reachable across host reconfiguration. Fallback history retains eight recent authorities per session, bounding credential retention while avoiding repeat upgrades during normal token/header rotation.

This is the transport-contract slice of the original native worker inference change, based on work by @sallyom and @roboclaw-bot, with contributions from @steipete.

Maintainer Decision

The public createNodeLlmRuntime contract and its inert omitted/partial-host defaults are accepted. Embeddings must supply the managed fetch and credential policy they require; an explicit runtime must not silently inherit process transport authority. This is the intended foundation for the later worker-lifecycle and native-inference slices.

Evidence

  • Focused runtime/authority tests: 95/95 passed in 3.12s wall with one worker.
  • Real loopback WebSocket I/O proves that replacing the process default during first-use payload construction still leaves the old authenticated socket reachable for session cleanup.
  • Real loopback cleanup proof verifies that cleaning one runtime preserves a sibling runtime, while global cleanup closes every registered owner.
  • Boundary proof verifies that credentials and managed fetch policy remain bound to the same captured host when payload construction replaces the process default.
  • Lazy-stream and browser-bundle proof verifies that replacing the process default after stream creation cannot move later result() or iterator work to a different transport host, drop completion metadata, or make a completed native stream unreadable.
  • Completed browser iteration now drains native and delegated terminal events after host replacement while pending provider work still blocks replacement. The regression failed before the repair with Scoped AI transport hosts require Node.js async context support; the named browser/host-scope suite passes 13/13 in 2.56s wall.
  • Custom browser streams without native completion metadata now have one host-bound source pump and replay-only consumers. Provider results settle independently, post-terminal cleanup runs to actual iterator completion, multiple replay readers remain independent, and cancelling one pending reader does not stop the source pump.
  • Native Responses WebSocket final effects and HTTP continuation caches are owner-scoped; session cleanup cannot cross runtime owners, and degraded WebSocket cooldowns expire independently.
  • Public-runtime final-effect proof uses real loopback HTTP/SSE and the real OpenAI SDK WebSocket client. For both matching-session and omitted-session cleanup, runtime B continues on its retained continuation/socket while runtime A starts fresh. The 2-test boundary passes in 3.00s wall; both cases fail for the intended cross-owner reason when applied to pre-fix 202ace18b2d.
  • auto transport falls back to SSE when a relative endpoint cannot form a WebSocket URL.
  • Real loopback I/O also covers managed-transport gating, cross-runtime isolation, fallback stickiness, recent-authority retention, and deterministic eviction after the bound.
  • Loopback WebSocket frames are capped at 64 KiB; the affected cache tests pass.
  • The original CI failure is repaired at its owner: the automatic-compaction fixture now returns a synchronous provider stream and passes 28/28 in 236.69s wall with one worker after a local worker-cache rebuild. This existing boundary suite is the cheapest coverage for compaction-in-flight admission state.
  • Exact-head changed-file checks pass, including core production/test types, lint, dead exports, import cycles, and repository guards.
  • AutoReview found no actionable P0–P2 issues in the ownership repair (patch is correct, 0.79 confidence), the real-client proof (patch is correct, 0.88 confidence), the completed native/delegated browser-stream repair (patch is correct, 0.72 confidence), or the final custom-stream lifetime/replay repair (patch is correct, 0.83 confidence).
  • Exact-head CI's two core-lint jobs reproduce unchanged on both its pristine base (34a0d304a8d) and current main (558d38a3db5): unresolved database types and .sort() diagnostics in untouched src/** files. The PR does not modify those files; this is inherited red-main evidence.
  • The unrelated Windows partition failure was fixed on main by test(ci): include infra in shared Windows partitions #162310; this head is rebased over that fix.
  • Sally, roboclaw-bot, and steipete trailers are parser-verified.

@clawsweeper

clawsweeper Bot commented Sep 26, 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 app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts commands Command implementations agents Agent runtime and tooling size: XL labels Sep 26, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 6:30 AM ET / 10:30 UTC (Revision 44).

ClawSweeper review

What this changes

The branch isolates each model runtime’s transport policy, credentials, cached connections, fallback history, and cleanup while preserving process-default runtimes.

Merge readiness

✅ Ready for maintainer review

Keep open: current main still lacks runtime-local transport ownership, the previous custom-browser-stream finding is repaired, and no remaining blocking defect was identified.

Priority: P2
Reviewed head: 87d1394b3d34142f692ec4803333c6b9d3b4a670

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, well-supported runtime isolation with the prior blocker repaired and no remaining actionable correctness finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Reported real loopback HTTP/SSE and WebSocket runs exercise the public runtime, retained caches, credential rotation, and sibling-preserving cleanup with observed request bodies and connection IDs. Inspected harnesses retain production transport clients; browser regressions supplement this proof. All changed caches are process-local, so no stored-data migration applies.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Reported real loopback HTTP/SSE and WebSocket runs exercise the public runtime, retained caches, credential rotation, and sibling-preserving cleanup with observed request bodies and connection IDs. Inspected harnesses retain production transport clients; browser regressions supplement this proof. All changed caches are process-local, so no stored-data migration applies.
Evidence reviewed 11 items Pinned introduction: Reviewed the merge-base-to-head production changes separately from base-branch drift. The supplied test merge is stale, so it was not used to claim removal of current-main behavior.
Previous finding repaired: The custom browser fallback now pumps its source under the captured host, waits for both result and source settlement, and exposes independent replay readers. The expanded browser-bundle regression covers completed replay, pending cleanup, reader cancellation, shared iterators, and iterator failure.
Re-review comparison recovered: Local comparison against the previous reviewed head encountered HTTP 403 fetching a missing blob. Reading that exact revision through GitHub confirmed the old bound-iterator fallback; the exact current commit patch confirms its replacement. No tests or builds were executed during this read-only review.
Findings None None.
Security None None.

How this fits together

OpenClaw’s AI transport library converts model requests into provider HTTP or WebSocket traffic and streams replies back to agents. Runtime-owned hosts supply transport and credential policy and delimit retained connection resources.

flowchart TD
  A[Model request] --> B[Runtime selects host]
  B --> C[Credential and transport policy]
  C --> D[HTTP or WebSocket provider]
  D --> E[Host-bound reply stream]
  B --> F[Owner-scoped connection cache]
  F --> D
  G[Runtime cleanup] --> F
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +742, Tests +1812, Docs +3, Other 0. Total +2557 across 26 files.

View PR surface stats
Area Files Added Removed Net
Source 15 987 245 +742
Tests 9 1819 7 +1812
Docs 1 4 1 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 26 2811 254 +2557

Review metrics

Metric Value Why it matters
Production versus regression growth production net +742 lines; tests net +1,812 lines Production growth supplies runtime ownership and browser stream lifetime handling; regression growth exercises transport isolation and cleanup boundaries.

Root-cause cluster

Relationship: partial_overlap
Canonical: #154388
Summary: This is the transport foundation of the broader native-worker request; skills provenance and worker lifecycle remain separate stacked responsibilities.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Retain one captured transport owner throughout provider work, connection reuse, and cleanup, with ordinary runtimes continuing to select the process default.

Do we have a high-confidence way to reproduce the issue?

Not applicable to the feature itself. The prior custom-browser defect has a focused bundled-runtime regression, and the current source repairs its identified mechanism; this reviewer did not execute tests.

Is this the best way to solve the issue?

Yes: extending the existing runtime and transport-resource owners avoids a competing manager, and the explicit-host defaults match the recorded maintainer decision.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against a8652880e3c3.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Reported real loopback HTTP/SSE and WebSocket runs exercise the public runtime, retained caches, credential rotation, and sibling-preserving cleanup with observed request bodies and connection IDs. Inspected harnesses retain production transport clients; browser regressions supplement this proof. All changed caches are process-local, so no stored-data migration applies.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded transport capability for concurrent runtimes, with no reported urgent production incident.
  • merge-risk: 🚨 compatibility: The public explicit-runtime API uses inert defaults instead of inherited process policy; the maintainer explicitly accepted this contract and its embedding responsibilities.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Reported real loopback HTTP/SSE and WebSocket runs exercise the public runtime, retained caches, credential rotation, and sibling-preserving cleanup with observed request bodies and connection IDs. Inspected harnesses retain production transport clients; browser regressions supplement this proof. All changed caches are process-local, so no stored-data migration applies.
  • proof: sufficient: Contributor real behavior proof is sufficient. Reported real loopback HTTP/SSE and WebSocket runs exercise the public runtime, retained caches, credential rotation, and sibling-preserving cleanup with observed request bodies and connection IDs. Inspected harnesses retain production transport clients; browser regressions supplement this proof. All changed caches are process-local, so no stored-data migration applies.

Evidence

What I checked:

  • Pinned introduction: Reviewed the merge-base-to-head production changes separately from base-branch drift. The supplied test merge is stale, so it was not used to claim removal of current-main behavior. (packages/ai/src/stream.ts:195, 87d1394b3d34)
  • Previous finding repaired: The custom browser fallback now pumps its source under the captured host, waits for both result and source settlement, and exposes independent replay readers. The expanded browser-bundle regression covers completed replay, pending cleanup, reader cancellation, shared iterators, and iterator failure. (packages/ai/src/stream.ts:73, 87d1394b3d34)
  • Re-review comparison recovered: Local comparison against the previous reviewed head encountered HTTP 403 fetching a missing blob. Reading that exact revision through GitHub confirmed the old bound-iterator fallback; the exact current commit patch confirms its replacement. No tests or builds were executed during this read-only review. (packages/ai/src/stream.ts, 99cf494032bf)
  • Accepted public contract: The supplied MEMBER comment explicitly accepts createNodeLlmRuntime and inert omitted/partial-host defaults: embeddings provide their required managed fetch and credential policy, rather than inheriting process authority. This acceptance still matches the current implementation. feat(ai): scope transport hosts per runtime #158901 (comment). (packages/ai/src/stream.ts:346, 87d1394b3d34)
  • Real final-effect cleanup proof: The captured body reports two passing public-runtime boundary cases in 3.00 seconds, with intended pre-fix failures. Inspected harnesses use real HTTP/SSE and the real OpenAI SDK WebSocket client, rerouting only its endpoint to loopback. Recorded request bodies and connection IDs verify that runtime B retains its continuation/socket after matching-session and all-session cleanup of runtime A. (packages/ai/src/transports/openai-responses-runtime-cleanup.integration.test.ts:262, 87d1394b3d34)
  • Credential and fallback isolation: Real loopback ChatGPT WebSocket cases observe distinct authorization headers and connection IDs across runtime owners. The fallback case exercises credential/header rotation, sibling isolation, eight-authority retention, and eviction; its noServer WebSocket fixture now caps frames at 64 KiB, addressing the scanner comment. (packages/ai/src/providers/openai-chatgpt-responses.cache.test.ts:383, 87d1394b3d34)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • stevenlee-oai: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • RomneyDa: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (43 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-30T06:30:24.959Z sha 1b6b5ee :: needs maintainer review before merge. :: none
  • reviewed 2026-10-01T02:11:07.274Z sha 95bf55657ef4da2a73f14918d1d8d55f938a1954 :: needs real behavior proof before merge. :: [P2] Classify default-host generations before awaited payload work
  • reviewed 2026-10-01T02:37:58.098Z sha 184bddca68e1f3c3876341f90a5ea9a4d86dc423 :: needs real behavior proof before merge. :: [P2] Classify default-host generations before awaited payload work
  • reviewed 2026-10-01T03:57:46.037Z sha c7f665a :: needs real behavior proof before merge. :: [P2] Scope every cleanup hook before exposing runtime cleanup
  • reviewed 2026-10-01T04:34:11.399Z sha 202ace1 :: needs real behavior proof before merge. :: [P2] Scope every cleanup hook before exposing runtime cleanup
  • reviewed 2026-10-01T06:12:22.175Z sha 0f2be3b :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-01T06:40:05.856Z sha 4699395 :: needs changes before merge. :: [P2] [P2] Preserve completed browser stream iteration after host replacement
  • reviewed 2026-10-01T07:06:49.889Z sha 99cf494 :: needs changes before merge. :: [P2] [P2] Preserve completed custom browser stream iteration

@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Security-sensitive guard cleared

Current revision: 87d1394b3d34142f692ec4803333c6b9d3b4a670

This PR no longer changes files in the maintainer security-review tier.

Separate CODEOWNERS requirements still apply to security policy and enforcement files.

@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 26, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 30, 2026
@RomneyDa
RomneyDa force-pushed the openclaw/pr-154390-native-worker-runtime branch from 1271f20 to ebc19a2 Compare September 30, 2026 01:58
@RomneyDa

Copy link
Copy Markdown
Member

@clawsweeper re-review

The rebased head is 1b6b5eea5bfaa42b7aec1bebad985fb20e6d79f2. The PR body now records the maintainer decision accepting the public createNodeLlmRuntime contract and its inert omitted/partial-host defaults: explicit runtimes must not inherit process transport authority. Focused tests, the full changed-file gate, and AutoReview are green on this head.

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling feature: ✨ showcase ClawSweeper spotlight: unusually compelling feature idea for maintainer attention. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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.

3 participants