Skip to content

improve(ollama): reduce inactive startup cost - #119745

Merged
vincentkoc merged 3 commits into
mainfrom
improve/ollama-lazy-runtime-20260805
Aug 5, 2026
Merged

vincentkoc merged 3 commits into
mainfrom
improve/ollama-lazy-runtime-20260805

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 5, 2026 •

Copy link
Copy Markdown
Member

Related: #119087

What Problem This Solves

The bundled Ollama plugin loaded setup, embedding, media, node-inference, web-search, and native-stream runtimes during registration even when an operator did not use Ollama. That increased startup import time and memory for every process that registered bundled plugins.

Why This Change Was Made

This keeps lightweight registration contracts synchronous while loading each optional runtime once, on its first owning operation. Dynamically imported implementations now live in dedicated *.runtime.ts modules; the original public module names are lightweight contract facades.

The native stream transport follows the existing lazy StreamFn pattern. Compatibility payload policy stays synchronous, so wrapper behavior and ordering do not change.

No config, default, persistence, protocol, or public API contract changes are introduced.

User Impact

Operators who do not use Ollama pay less startup time and memory. Operators who do use Ollama retain the same setup, discovery, embedding, media, node-inference, web-search, compatibility-wrapper, and native-stream behavior; the owning runtime loads on first use.

Exact-Head Evidence

  • Current exact head: 55a9e7179c1bad965c5ac3342b22d2fb98657362.
  • Current origin/main: d3d25737cf31547bd70ef9f0e1fcf2e3e7115f64; its newer Codex and Slack changes are path-disjoint, GitHub reports the PR mergeable, and repo-native prepare will integrate the final current main before merge.
  • Exact-head autoreview reported no actionable findings at 0.99 confidence.
  • 393 focused assertions passed across 10 Ollama test files on Node 26.4.0. The pre-split test set also passed on Node 24.15.0.
  • git diff --check and exact-head oxfmt --check passed.
  • The no-reconcile sourcePerformance packaged build passed in 9.36 seconds with zero ineffective-dynamic-import advisories.
  • The packaged entry emits distinct lazy chunks for setup.runtime, embedding-provider.runtime, stream.runtime, and web-search-provider.runtime; the startup registration entry imports none of those implementations eagerly.
  • Blacksmith Testbox was unavailable locally because its CLI was not authenticated, so the trusted-source build used the repository-authorized local fallback. Exact-head GitHub CI remains the merge gate.

Performance Evidence

Measured implementation head: 992d7ccc841520c767ee9f1e30be562853b99c1e. The exact head preserves those lazy owner boundaries and adds the dedicated packaged runtime split above.

  • Packaged Ollama entry: 53,809 -> 39,989 bytes (-25.7%).
  • Fifteen paired cold imports on baseline 7b8bba26c9539eb631a56ea65c2ff22771b2d0db, Node 24.15.0:
    • p50: 681.1 -> 621.6 ms (-8.7%).
    • p95: 820.2 -> 641.3 ms (-21.8%).
    • RSS p50: 360.2 -> 337.3 MB (-6.4%).
    • RSS p95: 362.0 -> 355.7 MB (-1.7%).
  • Five paired runs of the canonical extension-memory profiler:
    • max RSS median: 370.4 -> 334.3 MB (-9.8%).
    • extension delta median: 324.8 -> 288.5 MB (-11.2%).

Diff Shape

  • Production: +3,431/-3,139, net +292 without rename detection.
  • Tests: +296/-38, net +258.
  • Most gross production churn is content-preserving movement of the existing implementations into dedicated runtime-owner modules. The two ClawSweeper repair commits add 66 net production lines for the lightweight facades and cached lazy loaders; the final CI repair removes 7 net production lines.

ClawSweeper Resolution

The prior exact-head review's two Before merge items and both rank-up moves are implemented:

  • dynamically loaded implementations are isolated from statically exported facade modules;
  • the source and packaged builds report no ineffective dynamic imports;
  • the packaged output contains separate runtime chunks rather than folding those implementations back into the registration entry.
  • the original oversized stream.ts implementation is now a verified rename to stream.runtime.ts, while public barrels use the explicit lazy stream-api.ts facade;
  • the three test-only exports reported by exact-head dead-code CI were removed from production facades.

The stored-data detector is a false positive: this PR changes no config, schema, migration, persistence, vector metadata, or embedding data model. It only changes when existing Ollama runtime code is imported.

Merge Gate

Merge only after clean exact-head CI and the latest exact-head ClawSweeper review has no unresolved Before merge, finding, security, owner-decision, merge-risk, or blocking rank-up item.

Punchcard-Session: coral-workshop-workshop-3f

@vincentkoc vincentkoc self-assigned this Aug 5, 2026
@vincentkoc
vincentkoc force-pushed the improve/ollama-lazy-runtime-20260805 branch from 992d7cc to 6410dca Compare August 5, 2026 21:40
@vincentkoc
vincentkoc marked this pull request as ready for review August 5, 2026 21:45
Punchcard-Session: coral-workshop-workshop-3f
@vincentkoc
vincentkoc force-pushed the improve/ollama-lazy-runtime-20260805 branch from 6410dca to 7301506 Compare August 5, 2026 22:02
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 5, 2026, 7:30 PM ET / 23:30 UTC.

ClawSweeper review

What this changes

This PR moves optional Ollama setup, embedding, media, node-inference, streaming, and web-search implementations behind cached lazy runtime loaders to reduce default startup work.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open. The prior lazy-boundary finding is resolved on the exact head: registration now exposes lightweight contracts and defers optional Ollama runtimes until their owning operation. The PR remains a P1 performance repair for the broader cold-start regression and should await its exact-head checks before merge.

Priority: P1
Reviewed head: 55a9e7179c1bad965c5ac3342b22d2fb98657362

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused owner-boundary refactor with regression coverage and no actionable correctness finding; exact-head CI should complete before merge.
Proof confidence 🌊 off-meta tidepool Not applicable: This member-authored internal performance refactor is not subject to the external-contributor proof gate; the PR body supplies benchmark claims and exact-head CI remains the merge gate.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This member-authored internal performance refactor is not subject to the external-contributor proof gate; the PR body supplies benchmark claims and exact-head CI remains the merge gate.
Evidence reviewed 6 items Current-main startup cost is real: The default-startup Ollama entry statically imports setup/API, embedding, media, node inference, stream, web-search, and WSL checks before registration; the manifest enables the plugin at startup by default.
Exact head resolves the earlier lazy-target concern: The reviewed head imports dedicated runtime targets through cached loaders while leaving registration contracts local and lightweight.
Registration boundary coverage: The added test asserts zero optional runtime imports immediately after registration and one import per owner after first use.
Findings None None.
Security None None.

How this fits together

OpenClaw loads bundled plugins during gateway startup; the Ollama plugin currently starts by importing provider, setup, stream, embedding, and optional tool implementations. This change keeps registration metadata and wrappers available immediately, then loads the relevant implementation on first use.

flowchart LR
  GatewayStartup[Gateway startup] --> PluginManifest[Bundled plugin activation]
  PluginManifest --> Registration[Ollama registration]
  Registration --> Contracts[Lightweight contracts]
  Contracts --> FirstUse[Setup or provider operation]
  FirstUse --> LazyLoad[Load owning runtime]
  LazyLoad --> Result[Ollama capability result]
Loading

Before merge

  • Resolve merge risk (P1) - The claimed packaged-bundle size and benchmark improvements were not independently reproduced during this read-only review; exact-head CI is still running.
  • Complete next step (P2) - No mechanical repair is identified; retain normal maintainer ownership and wait for exact-head CI before deciding to merge.
Agent review details

Security

None.

PR surface

Source +292, Tests +258, Other 0. Total +550 across 28 files.

View PR surface stats
Area Files Added Removed Net
Source 20 2090 1798 +292
Tests 7 296 38 +258
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 28 2387 1837 +550

Review metrics

Metric Value Why it matters
Production versus test delta production +2,091/-1,799 (net +292); tests +296/-38 (net +258) Most production churn is implementation movement into explicit runtime owners; the remaining growth is the lazy registration boundary and its contracts.

Stored data model

Persistent data-model change detected: unknown-data-model-change: extensions/ollama/src/embedding-provider.runtime.ts, unknown-data-model-change: extensions/ollama/src/embedding-provider.ts, vector/embedding metadata: extensions/ollama/index.ts, vector/embedding metadata: extensions/ollama/lazy-import.test.ts, vector/embedding metadata: extensions/ollama/src/embedding-provider.runtime.ts, vector/embedding metadata: extensions/ollama/src/embedding-provider.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: partial_overlap
Canonical: #119087
Summary: This PR addresses the Ollama startup-import contribution, while the canonical issue also identifies broader default-plugin and lifecycle-hub startup work.

Members:

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

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the plugin-local lazy owner boundaries and merge only after exact-head packaging and behavior checks confirm the inactive startup path stays light while first-use operations retain behavior.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the plugin-local lazy owner boundaries and merge only after exact-head packaging and behavior checks confirm the inactive startup path stays light while first-use operations retain behavior.

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

Yes—source reproducible: the default-startup manifest and current entrypoint eagerly load optional Ollama runtime graphs before an operator uses Ollama.

Is this the best way to solve the issue?

Yes. Deferring imports inside the Ollama plugin preserves startup registration contracts; disabling the plugin by default or broadening core loader policy would be a worse owner boundary.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This member-authored internal performance refactor is not subject to the external-contributor proof gate; the PR body supplies benchmark claims and exact-head CI remains the merge gate.
  • 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.
  • remove merge-risk: 🚨 other: Current PR review selected no merge-risk labels.

Label justifications:

  • P1: This repairs a default-startup cost that contributes to the active gateway cold-start regression tracked in the related report.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This member-authored internal performance refactor is not subject to the external-contributor proof gate; the PR body supplies benchmark claims and exact-head CI remains the merge gate.

Evidence

What I checked:

  • Current-main startup cost is real: The default-startup Ollama entry statically imports setup/API, embedding, media, node inference, stream, web-search, and WSL checks before registration; the manifest enables the plugin at startup by default. (extensions/ollama/index.ts:33, d3d25737cf31)
  • Exact head resolves the earlier lazy-target concern: The reviewed head imports dedicated runtime targets through cached loaders while leaving registration contracts local and lightweight. (extensions/ollama/index.ts:87, 55a9e7179c1b)
  • Registration boundary coverage: The added test asserts zero optional runtime imports immediately after registration and one import per owner after first use. (extensions/ollama/lazy-import.test.ts:174, 55a9e7179c1b)
  • Stream wrapper contract: The shared stream type permits a promise-returning stream function, and the existing compatibility wrapper awaits that form, so the deferred stream wrapper preserves its call contract. (packages/llm-core/src/types.ts:681, d3d25737cf31)
  • No conflicting main-line Ollama change: There are no Ollama-path changes between the PR base and current main, so current main does not supersede this branch. (d3d25737cf31)
  • Current entry ownership history: The current entry import block traces to the recent main-line refactor commit; this is routing evidence, not regression attribution. (extensions/ollama/index.ts:33, 40a3bd2e10ef)

Likely related people:

  • steipete: Current-main blame and recent history place Peter Steinberger on the Ollama entrypoint that owns registration-time imports. (role: recent area contributor; confidence: medium; commits: 40a3bd2e10ef; files: extensions/ollama/index.ts)
  • vincentkoc: A prior merged Ollama performance commit covers the same lazy-loading startup neighborhood, in addition to this proposed change. (role: recent area contributor; confidence: medium; commits: e07d75dc091c; files: extensions/ollama/index.ts, extensions/ollama/provider-policy-api.ts)

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 (1 earlier review cycle)
  • reviewed 2026-08-05T22:40:47.282Z sha 7301506 :: found issues before merge. :: [P2] Split lazy targets from statically exported runtime modules

@clawsweeper clawsweeper Bot added 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 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. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Aug 5, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

Resolved every item from the prior ClawSweeper review on exact head 55a9e7179c1bad965c5ac3342b22d2fb98657362.

  • Dedicated *.runtime.ts modules now own every dynamically imported implementation.
  • Public barrels use the explicit lazy stream-api.ts facade; plugin registration imports only stream.runtime.ts on first use.
  • The exact-head sourcePerformance packaged build passed with distinct setup, embedding, stream, and web-search runtime chunks and zero ineffective-dynamic-import advisories.
  • The max-lines ratchet now recognizes the existing oversized stream implementation as a verified rename to stream.runtime.ts.
  • The three test-only facade exports reported by dead-code CI were removed. Exact-head check-dependencies and checks-fast-max-lines-ratchet are green.
  • 393 focused assertions, git diff --check, exact-path oxfmt, dead-export scans, and autoreview pass.

The stored-data detector remains a false positive: this PR changes no config, schema, migration, persistence, vector metadata, or embedding data model.

All prior Before merge items and rank-up moves are addressed. @clawsweeper re-review

@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer resolution for exact head 55a9e7179c1bad965c5ac3342b22d2fb98657362:

  • ClawSweeper's P1 merge-risk item is resolved. Exact-head CI completed with 66 passing checks, 41 intentional skips, zero failures, and a successful openclaw/ci-gate. The exact-head packaged build also emitted distinct lazy runtime chunks with no ineffective-dynamic-import advisory.
  • ClawSweeper's P2 ownership item is resolved. Repo-native review artifacts validate READY FOR /prepare-pr with zero findings, and normal maintainer ownership accepts the plugin-local runtime boundary as the best fix.
  • The stored-data-model detector is a false positive: no config, schema, migration, persistence, vector metadata, or embedding data model changed.
  • The review has no correctness finding, security finding, merge-risk label, or blocking rank-up move remaining.

Proceeding to repo-native prepare. Merge remains gated on current-main integration and the prepared exact head.

@vincentkoc
vincentkoc merged commit 2fc2fc9 into main Aug 5, 2026
125 checks passed
@vincentkoc
vincentkoc deleted the improve/ollama-lazy-runtime-20260805 branch August 5, 2026 23:40
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 6, 2026
* improve(ollama): defer optional runtime imports

Punchcard-Session: coral-workshop-workshop-3f

* improve(ollama): isolate lazy runtime modules

* improve(ollama): preserve lazy runtime boundaries
vincentkoc added a commit to VACInc/openclaw that referenced this pull request Aug 6, 2026
…cope

* origin/main: (24 commits)
  fix(backup): skip transient gateway lock databases (openclaw#119782)
  test(agents): use canonical auth session fixtures (openclaw#119821)
  fix(memory): keep QMD file hints after stale docid misses (issue openclaw#113041) (openclaw#113515)
  test(doctor): align fast-path repair contracts (openclaw#119812)
  perf(agents): index subagent recovery ownership (openclaw#119793)
  fix(gateway): keep chat startup off catalog discovery (openclaw#119742)
  fix(test): keep TUI PTY suites in their owner lane (openclaw#119787)
  docs: correct dashboard auth precedence (openclaw#119785)
  docs: document control ui owner handoff
  fix: grant host-authorized control ui owner access
  fix(worktrees): preserve registered roots during orphan cleanup (openclaw#119709)
  fix(matrix): prevent shared client key collisions (openclaw#119667)
  fix(diagnostics-otel): propagate exported span context (openclaw#112283)
  fix(worker): isolate state observer failures (openclaw#117507)
  fix(qa): attest realized profile executions (openclaw#119761)
  fix(gateway): finish successful sessions after timestamp races (openclaw#119752)
  fix(agents): fence restart recovery lifecycle (openclaw#119776)
  fix(ui): preserve chat history and active run timing (openclaw#119729)
  improve(ollama): reduce inactive startup cost (openclaw#119745)
  improve(gateway): defer inactive plugin runtime imports (openclaw#119733)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: ollama maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. 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.

1 participant