Skip to content

refactor(providers): return prepared dynamic models directly - #126574

Merged
steipete merged 1 commit into
mainfrom
steipete/dynamic-model-return
Aug 21, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/dynamic-model-return

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #126498, #126434, #125781

AI-assisted maintainer-requested refactor.

What Problem This Solves

Asynchronously discovered llama.cpp, LM Studio, and local Ollama models previously had to pass through plugin-global bridging caches before the synchronous resolver could see them. Those caches duplicated request ownership, retained stale discovery results, and made concurrent endpoint, credential-profile, or SecretRef changes harder to keep isolated.

Why This Change Was Made

The asynchronous embedded-model resolution owner now consumes the exact ProviderRuntimeModel returned by ProviderPlugin.prepareDynamicModel and passes it through the existing configured-model overrides, manifest aliases, transport/header precedence, normalization, and runtime-preference decision path. The public hook changes additively to Promise<ProviderRuntimeModel | void>: existing void implementations still retry their synchronous resolveDynamicModel hooks unchanged.

llama.cpp, LM Studio, and local Ollama now return only their requested discovered model directly, deleting their immediate request-bridging maps, scoped snapshots, eviction logic, and Ollama credential-fingerprint bookkeeping. Ollama Cloud/static resolution and existing OpenRouter, ClawRouter, GitHub Copilot, and OpenAI synchronous/void-compatible provider behavior remain unchanged.

User Impact

Operators continue to use the same provider configuration and model-selection commands. Concurrent local-provider model requests now retain their own fresh endpoint and credential-scoped metadata without crossing profiles or relying on stale plugin-global discovery caches. Existing third-party provider plugins that return nothing from prepareDynamicModel remain compatible.

Evidence

Exact diff classification: production +89/-253 (net -164); tests +448/-158 (net +290); test support +12/-10 (net +2); docs +6/-4 (net +2).

Focused provider, embedded-resolution, live-candidate, and legacy-provider compatibility proof: 16 files, 615 tests passed across seven Vitest shards.

node scripts/run-vitest.mjs src/plugins/provider-runtime.test.ts src/agents/embedded-agent-runner/model.test.ts src/agents/embedded-agent-runner/model.generation-scope.test.ts src/agents/embedded-agent-runner/model.skip-agent-discovery-hooks.test.ts src/agents/live-model-dynamic-candidates.test.ts extensions/llama-cpp/index.test.ts extensions/llama-cpp/src/external-server/provider.test.ts extensions/lmstudio/index.test.ts extensions/lmstudio/src/setup.test.ts extensions/lmstudio/src/models.test.ts extensions/ollama/index.test.ts extensions/ollama/src/provider-models.test.ts extensions/openrouter/index.test.ts extensions/clawrouter/index.test.ts extensions/github-copilot/index.test.ts extensions/openai/openai-chatgpt-provider.test.ts

pnpm test:contracts:plugins
# 42 files, 1,033 plugin-contract tests passed

pnpm plugin-sdk:surface:check
# public and local SDK surface passed; 146 public package SDK entrypoints

pnpm plugin-sdk:check-exports
# plugin-sdk exports synced

node scripts/check-changed.mjs
# formatting, core/plugin typechecks, scoped lint, boundary, dead-export, schema/database, and import-cycle guards passed

pnpm check:docs
# formatting and Markdown lint passed; 6,524 internal links and 1,180 config examples verified

pnpm build
# full build passed; 61 external plugins and all 146 public Plugin SDK subpaths verified

git diff --check origin/main...HEAD
# passed

Real exact-head provider proof used session-owned isolated loopback services and existing local models; every service and temporary resource was cleaned up afterward:

OPENCLAW_LIVE_TEST=1 LLAMA_SERVER_LIVE_TEST=1 LLAMA_SERVER_LIVE_URL=<isolated-loopback-endpoint> LLAMA_SERVER_LIVE_MODEL_ID=<local-gemma-model> pnpm test:live -- extensions/llama-cpp/src/external-server/llama-server.live.test.ts
# 3 passed: discovery/concurrent generation, schema-constrained JSON, cancellation
# 1 skipped: the selected Gemma template does not advertise tool-calling support

node openclaw.mjs infer model run --local --model lmstudio/<session-local-gemma-model> --prompt 'Reply with exactly one word: pong' --json
# isolated state/config plus an environment-backed temporary key; ok=true, provider=lmstudio, transport=local, answer=pong

OPENCLAW_LIVE_TEST=1 OPENCLAW_LIVE_OLLAMA=1 OPENCLAW_LIVE_OLLAMA_MODEL=qwen3:0.6b OPENCLAW_LIVE_OLLAMA_EMBEDDINGS=0 OPENCLAW_LIVE_OLLAMA_WEB_SEARCH=0 pnpm test:live -- extensions/ollama/ollama.live.test.ts
# 2 passed: dynamic built-CLI model resolution and native chat
# 2 skipped: embeddings and hosted web search intentionally disabled

.agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main
# fresh Codex-backed autoreview clean; no accepted/actionable findings

@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling extensions: lmstudio extensions: ollama extensions: llama-cpp size: L maintainer Maintainer-authored PR labels Aug 20, 2026
@steipete
steipete marked this pull request as ready for review August 20, 2026 07:19
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for 0a5e9e16f56a407351405a6561482f7ab7814bbb.

The async embedded-model resolution lifecycle now owns the exact model returned by ProviderPlugin.prepareDynamicModel, then reuses the existing configured override, manifest alias, transport/header precedence, normalization, and runtime-preference pipeline. The SDK hook is additive (Promise<ProviderRuntimeModel | void>): legacy void providers still retry synchronous resolution. llama.cpp, LM Studio, and local Ollama no longer retain request-bridging maps; Ollama Cloud/static and existing synchronous providers remain unchanged.

Production +89/-253 (net -164); tests +448/-158 (net +290); test support +12/-10 (net +2); docs +6/-4 (net +2).

Exact-head local verification:

node scripts/run-vitest.mjs src/plugins/provider-runtime.test.ts src/agents/embedded-agent-runner/model.test.ts src/agents/embedded-agent-runner/model.generation-scope.test.ts src/agents/embedded-agent-runner/model.skip-agent-discovery-hooks.test.ts src/agents/live-model-dynamic-candidates.test.ts extensions/llama-cpp/index.test.ts extensions/llama-cpp/src/external-server/provider.test.ts extensions/lmstudio/index.test.ts extensions/lmstudio/src/setup.test.ts extensions/lmstudio/src/models.test.ts extensions/ollama/index.test.ts extensions/ollama/src/provider-models.test.ts extensions/openrouter/index.test.ts extensions/clawrouter/index.test.ts extensions/github-copilot/index.test.ts extensions/openai/openai-chatgpt-provider.test.ts
# 16 files, 615 tests passed

pnpm test:contracts:plugins
# 42 files, 1,033 tests passed

pnpm plugin-sdk:surface:check
pnpm plugin-sdk:check-exports
node scripts/check-changed.mjs
pnpm check:docs
pnpm build
git diff --check origin/main...HEAD
# all passed; docs verified 6,524 links and 1,180 examples; build verified 61 plugins and 146 public SDK subpaths

.agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main
# fresh Codex-backed review clean; no accepted/actionable findings

Real exact-head live verification:

OPENCLAW_LIVE_TEST=1 LLAMA_SERVER_LIVE_TEST=1 LLAMA_SERVER_LIVE_URL=<isolated-loopback-endpoint> LLAMA_SERVER_LIVE_MODEL_ID=<local-gemma-model> pnpm test:live -- extensions/llama-cpp/src/external-server/llama-server.live.test.ts
# 3 passed: discovery/concurrent generation, schema-constrained JSON, cancellation
# 1 skipped: selected Gemma template does not advertise tool calls

node openclaw.mjs infer model run --local --model lmstudio/<session-local-gemma-model> --prompt 'Reply with exactly one word: pong' --json
# dynamically resolved model; ok=true, transport=local, provider=lmstudio, answer=pong

OPENCLAW_LIVE_TEST=1 OPENCLAW_LIVE_OLLAMA=1 OPENCLAW_LIVE_OLLAMA_MODEL=qwen3:0.6b OPENCLAW_LIVE_OLLAMA_EMBEDDINGS=0 OPENCLAW_LIVE_OLLAMA_WEB_SEARCH=0 pnpm test:live -- extensions/ollama/ollama.live.test.ts
# 2 passed: dynamic built-CLI model resolution and native chat
# 2 skipped: embeddings and hosted web search intentionally disabled

All isolated services were stopped, temporary proof state was removed, and the clean worktree still points at the reviewed head. Exact-head pull-request CI: https://github.com/openclaw/openclaw/actions/runs/32343492054.

ClawSweeper status: exact-head review started; its current comment contains no findings and no published rank-up moves. Required exact-head CI is already green; the asynchronous review publisher is still pending.

No merge has been attempted.

@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 20, 2026, 3:33 AM ET / 07:33 UTC.

ClawSweeper review

What this changes

The branch lets provider plugins return a prepared dynamic model directly, removing shared discovery caches while preserving the existing resolver fallback.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open for maintainer review. The patch provides a coherent request-scoped replacement for shared dynamic-model discovery caches, preserves the established void-return fallback, and has focused behavior and live-provider evidence; the public plugin contract remains compatibility-sensitive until exact-head checks finish.

Priority: P2
Reviewed head: 0a5e9e16f56a407351405a6561482f7ab7814bbb

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused, covered at its runtime boundary, and backed by live provider runs, with normal public-contract merge checks remaining.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body supplies after-fix live llama-server, LM Studio, and Ollama output covering the affected discovery flows.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body supplies after-fix live llama-server, LM Studio, and Ollama output covering the affected discovery flows.
Evidence reviewed 8 items Public contract and runtime forwarding: The provider hook explicitly permits a prepared model return, and the runtime forwards that result rather than discarding it.
Consumer preserves fallback: The embedded runner uses a prepared result when present and otherwise calls the existing synchronous dynamic-model resolver.
Behavioral coverage: The model-resolution tests verify prepared results receive configured overrides and normalization without invoking the synchronous resolver.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw models --help

Result: PASS (completed)

pnpm openclaw models --help
runner@runnervmzvulz:/tmp/clawsweeper-live-proof-126574-V86CfF/target$ pnpm openclaw models --help
$ node scripts/run-node.mjs models --help
pnpm openclaw models --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 107.62 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.7s
node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

[tsdown-build] invocation 2/2 finished in 14.2s
[plugin-control-plane-loads] verified 35 built modules with native require and checked doctor closures
runtime-postbuild: 10 phases completed in 4410ms (slowest: built plugin control-plane loads 3636ms)
│
◇

OpenClaw 2026.8.1 (0a5e9e1) — All your chats, one OpenClaw.

Usage: openclaw models [options] [command]

Model discovery, scanning, and configuration

Options:
  --agent ‹id›     Agent id to inspect (overrides OPENCLAW_AGENT_DIR)
  -h, --help       Display help for command
  --json           Output JSON (alias for ˋmodels status --jsonˋ) (default: false)
  --status-json    Output JSON (alias for ˋmodels status --jsonˋ) (default: false)
  --status-plai
… output truncated …

Assertions:

  • PASS expect_output: Model discovery, scanning, and configuration

How this fits together

Provider plugins prepare model metadata that the embedded agent runner uses to select and execute a model. A prepared result now flows directly into the runner; plugins that return nothing continue through the synchronous registry resolver.

flowchart LR
  A[Provider plugin] --> B[Prepare dynamic model]
  B --> C{Prepared model returned?}
  C -->|Yes| D[Embedded agent runner]
  C -->|No| E[Registry resolver]
  E --> D
  D --> F[Model execution]
Loading

Before merge

  • Resolve merge risk (P2) - The public Provider SDK hook now has an additive return contract; existing third-party plugins must continue to work when they return void, which the fallback is designed to preserve.
Agent review details

Security

None.

PR surface

Source -162, Tests +290, Docs +2. Total +130 across 23 files.

View PR surface stats
Area Files Added Removed Net
Source 14 101 263 -162
Tests 7 448 158 +290
Docs 2 6 4 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 23 555 425 +130

Review metrics

Metric Value Why it matters
Production versus test delta production +89/-253; tests +448/-158; docs +6/-4 The refactor removes more production code than it adds while expanding behavior and concurrency coverage.
Provider preparation contract 1 changed, 0 added, 0 removed prepareDynamicModel may now return a prepared model, while void-returning implementations retain the existing fallback.

Stored data model

Persistent data-model change detected: vector/embedding metadata: docs/plugins/sdk-provider-plugins.md, vector/embedding metadata: extensions/llama-cpp/src/external-server/provider.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Confirm SDK consumer compatibility (recommended)
    Merge after exact-head checks confirm void-returning provider plugins continue through the documented resolver fallback.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Wait for exact-head checks to pass, then merge.

Technical review

Best possible solution:

Merge after exact-head checks confirm the documented void-return fallback remains compatible for existing provider plugins.

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

Not applicable: the PR refactors discovery-state flow rather than reporting a standalone current-main failure.

Is this the best way to solve the issue?

Yes: carrying a request-scoped prepared model through generic runtime code removes cache coupling while retaining the existing resolver contract for plugins that return void.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2a79f747019c.

Labels

Label changes:

  • add P2: This is a bounded provider-runtime cleanup with compatibility-sensitive SDK behavior, not an urgent outage.
  • add merge-risk: 🚨 compatibility: The PR changes a public provider hook consumed by plugins, even though its void-return fallback is explicitly preserved.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies after-fix live llama-server, LM Studio, and Ollama output covering the affected discovery flows.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: This is a bounded provider-runtime cleanup with compatibility-sensitive SDK behavior, not an urgent outage.
  • merge-risk: 🚨 compatibility: The PR changes a public provider hook consumed by plugins, even though its void-return fallback is explicitly preserved.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies after-fix live llama-server, LM Studio, and Ollama output covering the affected discovery flows.

Evidence

Acceptance criteria:

  • [P1] Confirm all exact-head GitHub checks complete successfully.
  • [P1] Run pnpm openclaw models --help and confirm it prints Model discovery, scanning, and configuration.

What I checked:

Likely related people:

  • steipete: Authored the current provider-runtime refactor and is attributed by blame for the changed runtime forwarding path. (role: recent area contributor; confidence: high; commits: 0a5e9e16f56a; files: src/plugins/provider-runtime.ts, src/plugins/provider-plugin.types.ts, src/agents/embedded-agent-runner/model.registry-resolution.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Confirm remaining exact-head checks pass before merge.

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.

@steipete
steipete merged commit 01e8887 into main Aug 21, 2026
807 of 821 checks passed
@steipete
steipete deleted the steipete/dynamic-model-return branch August 21, 2026 18:40
@steipete

steipete commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Merged via squash.

  • Prepared head SHA: 0a5e9e16f56a407351405a6561482f7ab7814bbb
  • Landed commit: 01e888795978ede45f9cbeaf6d8bfc4bbbb9987d
  • Fresh exact-head hosted pull-request CI: run 32343492054, attempt 3.
  • Fresh exact-head Workflow Sanity: run 32343446055, attempt 2.
  • Exact-head focused coverage: 16 files / 615 passing tests; plugin contracts: 42 files / 1,033 passing tests; SDK surface/exports, changed checks, docs, and build all passed.
  • Real provider proof: llama-server 3 passed / 1 tool-template skip; LM Studio dynamic CLI inference returned pong; Ollama dynamic CLI resolution and native chat both passed, with embeddings and hosted web search intentionally skipped.
  • Final diff: production +89/-253 (net -164); tests +448/-158 (net +290); test support +12/-10 (net +2); docs +6/-4 (net +2).

The request lifecycle now carries its exact prepared dynamic model through the existing override, transport, normalization, and preference pipeline. llama.cpp, LM Studio, and local Ollama no longer need request-bridging provider caches; existing void-returning provider hooks retain their synchronous retry compatibility.

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 extensions: llama-cpp extensions: lmstudio extensions: ollama maintainer Maintainer-authored PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant