Skip to content

fix: prevent provider catalog failures during concurrent SDK imports - #196448

Merged
RomneyDa merged 1 commit into
openclaw:mainfrom
1052326311:fix/provider-sdk-import-race
Nov 10, 2026
Merged

RomneyDa merged 1 commit into
openclaw:mainfrom
1052326311:fix/provider-sdk-import-race

Conversation

@1052326311

@1052326311 1052326311 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #195477

What Problem This Solves

Provider catalogs can fail to load with ERR_REQUIRE_ESM_RACE_CONDITION when a host chunk starts importing the SDK while a plugin requires the same module.

User Impact

Catalog discovery can finish for both consumers without serializing providers. Host async imports, query URL identity, and plugin alias restrictions remain intact.

Why This Change Was Made

Prepare an already exported SDK target before an adjacent host chunk starts its ESM evaluation, using the existing resolver and SDK contexts. Host chunks gain no plugin alias grant. Host-only top-level-await graphs retain native async loading; other errors still propagate.

Evidence

  • Node 26.8.2: the new host regression fails on base e27557203a5279ca4d56c21a531a291c0d5c794a with ERR_REQUIRE_ESM_RACE_CONDITION; existing alias/relative cases pass. The final loader suite passes all 24 tests with OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs src/plugins/loader.lazy-alias.test.ts --maxWorkers=1.

  • A local probe through the real runProviderCatalog and native resolver reproduces a failed plugin catalog on the base and three successful catalogs on the fix, including an independent healthy sibling. Generated module fixtures also verify host TLA, query URLs, unexported imports, unrelated parents, and preserved plugin/error rejection behavior. This uses synthetic SDK/hooks; full implicit discovery, live OpenAI/xAI calls, an installed Gateway, and a stable-to-candidate upgrade were not exercised.

  • Focused plugin-test typecheck, lint, format, plugin import-boundary inventory and staged diff/secret/size checks pass. Independent read-only Codex review found a host TLA compatibility regression and an incorrect fixture preference; both were corrected, with no remaining actionable findings. Local autoreview/ClawSweeper was not run.

  • The test-line ratchet still fails by 12 inherited lines: exact base 6,615,496 / ceiling 6,615,484; candidate 6,615,518 / ceiling 6,615,506. A separate allocation grants exactly the 22 net regression lines needed for host concurrency and native async boundary coverage; the shared scalar is unchanged. This is a disclosed failed check, not a pass or CI exemption.

  • pnpm build completed with exit 0, covering runtime bundles, declarations, SDK exports and Control UI. Its UI-size report lists three over-budget measurements; no UI-size qualification is claimed.

  • Built OpenAI and xAI cold imports both complete successfully with the repository profiler, concurrency 1, in an isolated home. The final report qualifies clean source/build/entry identity. The full build ran over the exact committed source bytes before committing; generated build info was refreshed through its canonical script afterward. These are cold-import results, not a claim about activation, live catalog requests, or performance improvement.

Follow-up verification (November 10)

The reviewed source head is unchanged: 2b4d3809aec6ea3ec6d4687576f6e032ca933630.

  • Ran the built shipped launcher, node openclaw.mjs models list --all --refresh --json, with isolated home/config/state, OpenAI and xAI enabled, and no provider credentials. It entered local catalog refresh and exited 0 with 16 OpenAI model rows; no xAI rows were returned without credentials.
  • Started a separate isolated built Gateway on loopback, then ran that same CLI refresh through its real models.list RPC. The Gateway reached ready, the CLI returned 16 model rows and exit 0, and the Gateway shut down cleanly with exit 0. The local Gateway token was synthetic. These checks exercised empty-auth catalog loading and projection, not live vendor discovery or inference.
  • The standalone CLI module-hook trace shows OpenAI's .setup catalog and xAI's plugin entry resolving the shared SDK. The Gateway refresh trace shows the OpenAI .setup catalog. They do not show the adjacent root host chunk executing its catalog import. Consequently these successful product-entry smoke checks do not yet fulfill ClawSweeper's requested concurrent host/plugin discovery proof. That evidence request remains open; no re-review or merge-readiness claim is made here.

Current failed CI

Run 42758257852 completed with failures. pnpm test:ci-failed 196448 reports the ratchet as new (matching scheduled main job passed, scope not compared) and the Baseten shard as unknown (no matching main job).

  • The hosted test-line result is 6,615,861 / 6,615,850, over 11, with test delta +22. This differs from the original-base local debt of 12 reported above. An independently executed alternate-index check of the exact CI base 568d89f3a4e82d13ecca4ed602c46a04bda322f0 now reports 6,615,839 / 6,615,828, over 11, net delta 0. I retrieved only the six missing public test blobs (111,204 bytes total), verified each Git object ID, and ran the staged ratchet with lazy fetching disabled. The candidate adds 22 test lines and 22 allocated lines, so the observed 11-line residual is already present on that exact CI base. This is additional baseline evidence; it does not change the classifier output above, make the hosted check pass, or claim a maintainer waiver. The check remains failed.
  • The Baseten job reports deadline settlement before DNS preparation under Bun 1.4.4 (phase=evaluation, elapsed 7013 ms). The prescribed pnpm test:ci-failed 196448 --run subsequently passed the selected test locally on macOS at the unchanged source head: 1 passed, 4 skipped, exit 0. A preceding local attempt exhausted disk while compiling test subprocesses and executed no tests. A passing local replay does not establish a fix or explain the hosted failure; its attribution remains unresolved. No CI rerun or unrelated source change was made.

Shipped catalog integration: observed host/plugin overlap

On the unchanged head above, an isolated native-Node process loaded the built OpenAI and xAI plugins with the shipped full loader. It obtained each provider's preparation through the shipped prepareImplicitProviderStaticCatalog, checked that both results retained the same registry/load-context provenance and the registered catalog callbacks, then passed their combined preparation to the unchanged shipped resolveImplicitProviders scheduler. No catalog callback or SDK module was replaced, no artificial delay was injected, and no vendor credentials were supplied.

Sanitized terminal/native-resolver observations (times are process-relative milliseconds):

2008.84 catalog.start openai, active=[openai]
2009.22 native.resolve.start ./plugin-sdk/provider-auth-runtime.js
        parent=dist/openai-provider-catalog-DCKR5exy.mjs
2009.62 native.resolve.start dist/plugin-sdk/provider-auth-runtime.js
        conditions=[require,node,node-addons,module-sync]
2013.49 catalog.start xai, active=[openai,xai]
2013.87 native.resolve.start ../../plugin-sdk/provider-auth-runtime.js
        parent=dist/extensions/xai/index.js
2030.46 catalog.settled openai
2032.43 catalog.settled xai
2032.73 owner.settled providers=[openai,xai], outcomes=[]
        maxActive=2, starts=2, settlements=2, remainingActive=[]
exit=0

Both imports resolve to the same shipped SDK facade; the host request is the first SDK request in the trace. The production resolver SHA256 remains 66e994409d35907734d8c0d7755f1fae1d6064735b0f5af8c8dd55ea7c94a38e, and the tracked tree is clean. Node inspector breakpoints observed invocation and post-await settlement, so the timings are not performance evidence.

Proof boundary: this is real built loader/catalog integration with harness-combined, genuine per-provider preparation. It is not ordinary top-level CLI/Gateway end-to-end proof, a baseline-red run of this new harness, or successful live-vendor inference. The earlier CLI/Gateway refresh traces still select OpenAI's lightweight .setup catalog and do not establish this host import. Source inspection explains that bulk planning queries full runtime providers for [xai], retaining the OpenAI lightweight descriptor, even when the full registry contains both providers. This trace adds the missing real host/plugin overlap without claiming that the ordinary refresh path exercises it.

@clawsweeper

clawsweeper Bot commented Nov 10, 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.

@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. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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 10, 2026
@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

The PR prepares shared SDK modules before adjacent host imports can race with synchronous plugin loads.

Example: OpenAI and xAI concurrently import dist/plugin-sdk/provider-auth-runtime.js.

  • Before: The host import can begin asynchronous linking before the plugin requires the same module, causing ERR_REQUIRE_ESM_RACE_CONDITION.
  • After: The resolver prepares the shared SDK graph before host linking begins, allowing both consumers to finish.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, useful repair with meaningful production-owner integration evidence, but the required shipped-path demonstration remains incomplete.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Provider discovery can skip a catalog when concurrent host and plugin consumers load the same SDK module.
Reason: The change restores an established loading invariant without adding options, public APIs, or provider-specific scheduling policy.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: it addresses a concrete provider-loading failure still present on current main, and no introduced correctness defect was found.

Priority: P2
Reviewed head: 2b4d3809aec6ea3ec6d4687576f6e032ca933630

Before merge

  • Add real behavior proof - The new unchanged-head trace materially improves the previous evidence: genuine built OpenAI and xAI catalog callbacks overlap through the real loader and scheduler and both settle, but harness-combined preparation selects that scenario. The successful shipped CLI/Gateway refreshes explicitly do not execute the affected root host import, so the external-PR shipped-entry-point gate remains open. Supply redacted terminal output or logs showing that overlap and successful settlement through an ordinary product entry point, removing IPs, keys, phone numbers, and non-public endpoints; live vendor inference is not required for this loader claim. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.

Findings

None.

Tests

  • Missing end-to-end proof: A shipped CLI or Gateway flow still needs to exercise the affected host/plugin catalog overlap; the supplied ordinary refresh traces select another catalog path.
Agent review details

How this fits together

The native plugin resolver sits between Node module requests and the existing SDK alias contexts; it resolves module identities and prepares shared SDK graphs consumed by host chunks and plugins.

flowchart TD
  A[Provider discovery scheduler] --> B[Host catalog import]
  A --> C[Plugin catalog import]
  B --> D[Native SDK resolver]
  C --> D
  D --> E[Existing SDK alias contexts]
  D --> F[Shared evaluated SDK module]
Loading

Technical review

Best possible solution:

Extend the existing resolver's preparation invariant to matching host SDK imports while retaining concurrent discovery and native asynchronous loading.

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

Current-main source exposes the host/plugin preparation mismatch, and the contributor reports the added host regression failing on the pinned base with ERR_REQUIRE_ESM_RACE_CONDITION; this review executed no target code.

Is this the best way to solve the issue?

The patch repairs the shared resolver rather than serializing discovery or retrying failed catalogs, and its host-only asynchronous fallback preserves the existing plugin loading contract.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +38, Tests +22, Other +2. Total +62 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 45 7 +38
Tests 1 34 12 +22
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 3 81 19 +62

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.

Review metrics

Metric Value Why it matters
Production and regression growth Production +38 net lines; tests +22 net lines Growth stays within the existing resolver and fixture tables, covering host concurrency, top-level await, query identity, and unexported targets without a new state owner.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #195477
Summary: This PR targets the reported provider SDK race; the earlier merged preparation fix covers plugin callers and does not supersede the host-caller repair.

Members:

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

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: A provider catalog attempt can be skipped by a demonstrated module-loading race; a broad inference outage is not established.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-10T05:04:31.816Z sha 2b4d380 :: needs real behavior proof before merge. :: none

Reviewed November 10, 2026, 3:24 AM ET / 08:24 UTC (Revision 2).

@1052326311

Copy link
Copy Markdown
Contributor Author

Added a sanitized real built host/plugin catalog overlap trace to the PR body on unchanged head 2b4d3809aec6ea3ec6d4687576f6e032ca933630: OpenAI's root host chunk requests the SDK first, synchronous preparation follows, and xAI requests the same target while both real catalogs are pending; both settle successfully (maxActive=2, process exit 0).

The body explicitly identifies the boundary: the shipped scheduler consumes harness-combined genuine per-provider preparation with verified common provenance. Ordinary CLI/Gateway refresh still selects OpenAI's lightweight entry and does not demonstrate the root-host scenario. No end-to-end or live-vendor success is claimed. Please assess this added evidence against the requested proof boundary; if the ordinary command path is essential, that gap remains open.

The exact hosted CI base was also executed independently: it is already 11 test lines over its ceiling, matching the hosted residual. CI remains failed; no waiver or Baseten root-cause attribution is claimed.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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 10, 2026
@RomneyDa

RomneyDa commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Independent isolated-Gateway red/green proof

Verified the reported SDK-loading race through an ordinary Gateway + CLI catalog-refresh flow, rather than only the built-catalog harness.

Revision Result
Baseline e27557203a52 xAI discovery fails with “ES Module … not yet fully loaded” for provider-auth-runtime.js; the CLI reports xAI unavailable.
PR head 2b4d3809aec6ea3ec6d4687576f6e032ca933630 OpenAI and xAI catalogs both complete, without the SDK race warning.

The fixture triggers the normal full-catalog discovery fallback by failing a lightweight discovery entry; the real OpenAI and xAI catalog callbacks are unchanged. Worker-aware tracing confirms OpenAI's root host chunk imports the SDK and xAI starts before OpenAI settles. The CLI refresh and Gateway shutdown exit cleanly. Repeating both revisions without instrumentation gives the same baseline-fails / patch-passes result. Healthy sibling discovery remains present in both.

Environment: secretless remote Linux box, Node 26.12.1, isolated temporary home/config/state and loopback Gateway port. No vendor credentials or live inference; this verifies module loading and catalog discovery. The operator's live Gateway was untouched. All test Gateways stopped and the remote box was released after testing.

Proof run

This closes the missing product-entry-point proof for the loader race.

CI investigation

Inspected full logs for run 42758257852, attempt 1. Its tested merge commit is af1ba342ebb1734eddbfac2995e09f109ccb7fad, with base 568d89f3a4e82d13ecca4ed602c46a04bda322f0 and PR head 2b4d3809aec6ea3ec6d4687576f6e032ca933630. Comparing the merge tree against its base confirms only the same three PR files changed.

  • Test-line ratchet: inherited residual, not added debt. The hosted log reports 6,615,861 lines / 6,615,850 ceiling, over by 11, net delta +22. The diff adds exactly 22 test lines and a 22-line allocation, leaving the overage unchanged. This independently corroborates the author's exact-CI-base count of 6,615,839 / 6,615,828, also over by 11; I did not repeat that full base count in this investigation.
  • Baseten: separate pre-HTTP deadline failure; the changed Node hook does not run on Bun. The full shard log reports Bun 1.4.4, phase=evaluation, elapsedMs=7013, result { status: 'unavailable', reason: 'deadline' }. The first allowed case fails; the next four cases pass. The test supplies a 5,000 ms budget. Every changed production behavior is inside the resolver's useNodeModuleHooks() branch; that guard explicitly returns false on Bun. No Baseten, Decision, Bun-resolver, or CI scheduling behavior changed in this PR.
  • Likely mechanism, not a proven timing breakdown: cold preparation/lazy runtime loading exhausts the test budget before the HTTP guard. Baseten loads its runtime lazily during evaluation. History already contains a cold-runtime preloading fix (91f4975d99f9), subsequently removed by fix: keep Baseten admission tests within plugin boundaries #190958 to preserve plugin boundaries. First-case-only failure and warm-case success fit that explanation, but the hosted log does not identify which preparation/import consumed the seven seconds. A passing local replay is not proof of the timing cause or a repair.
  • Aggregate CI gate: reflects these failed checks, not an additional independent product failure.

Disposition: neither failure identifies a regression introduced by this Node SDK-loader repair. Baseten is a separate deadline/test-reliability investigation; its detailed timing cause remains unproven. CI remains red: no checks were waived, rerun, or marked successful, and no unrelated test timeout or allocation was changed.

@RomneyDa
RomneyDa merged commit f5180d7 into openclaw:main Nov 10, 2026
181 of 185 checks passed
RomneyDa added a commit that referenced this pull request Nov 11, 2026
Adapt the Coding Plan retained-catalog repair to the stable named
forward-compatibility helper without changing native route or auth guards.
Exercise real plugin model resolution and final request routing for general,
Coding Plan, regional, proxy, and model-level override endpoints.

The separately requested SDK import repair (#196448) is already covered by
baseline ancestor bcd022a; retain it unchanged.

Worked on by:
- @jason-allen-oneal

(cherry picked from commit aed2383)

Co-authored-by: jason-allen-oneal <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 12, 2026
…rs (#196448)

Also resolves issue #195477. Retain exact registered SDK target and adjacent
host checks, native query identity, and the narrow host-only async fallback.

(cherry picked from commit f5180d7)

Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 12, 2026
Adapt upstream source 625945b to the beta3 runtime owners. Keep synchronous SDK compatibility while deferring tool, model, plugin, process and state-handler initialization.

Integrate on 67cc5d9, preserving #195398, #196301, #196386, #196387, #189991 and #196448. Three automatically merged overlaps retain canonical assertion/mock baseline removals and worker-turn input gating; no new behavioral adaptation.

Original source reviews and focused build/test evidence are retained. Fresh integration-only independent review found no actionable issues.

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 16, 2026
Repair required openclaw#195477 on the frozen 2026.11.3 baseline. Adjacent host
chunks prepare only the exact SDK target recognized by a captured alias
context; host chunks do not become plugin alias parents. Retain native ESM
evaluation for ERR_REQUIRE_ASYNC_MODULE only on that host-path case.

Release adaptation: authored from inspection of unmerged PR openclaw#196448,
source 2b4d380. Keep the stable
contexts/sdkRoots owner rather than importing the later sdk.roots cache
refactor. Preserve Windows filename normalization, captured alias grants,
exact URL identity, and the existing Node/Bun hook selection. Adapt tests
to stable fixture helpers and add host-only fallback/identity negatives.

Companions: existing synchronous plugin SDK preparation (05a2844),
canonical cached parent boundaries (ea49097), native Windows targets
(0e92339), and scoped Bun denial coverage (39c0bed) are present.
The source test-line allocation is not applicable: retained allocation
files have no consumer in the stable scripts/package/CI graph. No new
public SDK export or dependency.

Validation: actual native loader host-import/CJS race failed before the
production change with ERR_REQUIRE_ESM_RACE_CONDITION; alias/relative
siblings passed. Final loader/resolver suite: 41/41 tests. Scoped plugin
types, lint, formatting and diff checks pass. Restricted independent
autoreview with full owning context is P0/P1 scoped-clean.

Original implementation by 1052326311, preserved as author.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit f68ddc67ca464482f04142b05769e5961eb0e89d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Provider discovery skipped when SDK module is not fully loaded

2 participants