Skip to content

fix(lmstudio): avoid fresh-session overflow after slow model loads - #168044

Merged
steipete merged 3 commits into
mainfrom
fix/lmstudio-preload-timeout-routing
Oct 10, 2026
Merged

steipete merged 3 commits into
mainfrom
fix/lmstudio-preload-timeout-routing

Conversation

@steipete

@steipete steipete commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes fresh LM Studio sessions failing with context overflow after a slow preload falls back to a loaded instance that is too small. Related: #141357.

User Impact

OpenClaw waits for cold loads using the existing provider/request timeout or a two-minute default. Failed capacity upgrades stop inference and show the model, requested context, and loading/retry guidance in both the live error and saved history. Existing configuration is preserved; no new configuration or migration is required.

Why This Change Was Made

The LM Studio plugin previously used a 30-second native-load deadline and discarded failed capacity upgrades. It now retains that failure through backoff and failed rediscovery until preparation succeeds. Unknown-capacity discovery failures keep their best-effort fallback. Shared load cancellation and canonical conversation identity are preserved.

The plugin owns loading decisions. Core renders a generic loading-failure code and validated context count through the existing error envelope, with a redacted, bounded, escaped model label. It creates fixed guidance rather than exposing provider diagnostics; no SDK field, trusted-text hook, or retry policy was added.

Evidence

Real LM Studio, Gemma 4 E4B, isolated Gateway on port 19247, proxy on 19248 forwarding to LM Studio on 1234. Configured contextTokens: 49152, with canonical 8192-token and named 32768-token instances. Replay uses the production Gateway client and fresh chat.send sessions, then reads chat.history.

  • Before: a proxy delayed only /api/v1/models/load by 35 seconds. Main aborted loading at 30 seconds, sent inference to the canonical 8K ID, and returned the misleading overflow/reset error in 50.221 seconds.
  • After, rejected upgrade: proxy-injected native HTTP 503 sent no inference request. The live error and saved history both name the model, 49152 context tokens, and loading/retry/lower-context guidance (23.060 seconds including Gateway preparation).
  • After, delayed success: native loading returned after 57.798 seconds (35 seconds proxy delay plus 22.793 seconds real loading). The chat request addressed the returned 49152-token instance google/gemma-4-e4b:2, and real Gemma replied PRELOAD_OK. through the Gateway in 72.664 seconds.
  • Regressions: five instance cases fail original production; the live/history presentation case fails the old renderer. Malformed facts and raw private prose remain suppressed, and model labels are redacted, bounded, and escaped.
  • Focused owner proof: 66 stream/model/load-error tests passed in 105.20 seconds wrapper wall time. After the presentation addition, 105 core-copy/format/instance tests passed in 68.50 seconds. Test bodies take milliseconds; cold worker/transform preparation dominates these wall times. No real sleeps, polling, or per-test Gateway boots were added.
  • Core and extension production types, extension test types, the changed agents-other core test graph, targeted core/plugin lint, formatting, and all required baseline ratchets pass. Config-doc and plugin-inventory checks pass. Final runtime-only pnpm build passed in 2m08s; full default declaration build was not run, but SDK boundary declarations completed for lint. The first declaration preparation hit its five-minute tool deadline; the supported longer compiler budget completed it.
  • Exact-head CI passed, including openclaw/ci-gate. Changed Node shards took 58–228 seconds; the changed extension-config shard took 73 seconds; baseline ratchets took 94 seconds.
  • Fresh independent Codex autoreview: scoped-clean, no actionable P0–P2 findings on 2d1bd18f3c886457e4808362d7104314b2c2b117.
Commands and change size
node scripts/run-vitest.mjs extensions/lmstudio/src/stream.instances.test.ts extensions/lmstudio/src/stream.test.ts extensions/lmstudio/src/models.test.ts extensions/lmstudio/src/models.load-error.test.ts --maxWorkers=1
node scripts/run-vitest.mjs src/agents/failover/assistant-request-failure-copy.test.ts src/agents/embedded-agent-helpers.formatassistanterrortext.test.ts extensions/lmstudio/src/stream.instances.test.ts --maxWorkers=1

Gateway: pnpm openclaw --profile lmstudio-fixes gateway run --port 19247 --bind loopback --auth none, with task-owned OPENCLAW_STATE_DIR and OPENCLAW_CONFIG_PATH. chat.send prompt: /think off\nReply exactly PRELOAD_OK. Do not use tools. No external channel sends.

Production +130/-92, net +38. Plugin loading/backoff code is LOC neutral after removing redundant error and abort wrappers. The net growth supplies one shared safe renderer for live and saved errors; trimming it further would remove required fact validation or sanitization. Tests +140/-21, net +119; docs +6; ratchet baselines -3 obsolete entries. No model-facing prompt/tool text changes.

The generic fresh-session /reset overflow copy remains a separate follow-up: multiple renderers lack session-freshness facts. This fix keeps capacity-loading failures out of that overflow path.

@clawsweeper

clawsweeper Bot commented Oct 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: lmstudio size: M labels Oct 10, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR extends LM Studio loading deadlines and reports failed context-capacity upgrades instead of sending inference to a known undersized instance.

Example: Gemma 4 E4B requests 49152 context tokens while loaded instances provide 8192 and 32768 tokens.

  • Before: A slow load exceeds the 30-second deadline, and inference falls back to the smaller canonical instance with a misleading overflow error.
  • After: A successful slow load routes inference to the returned 49152-token instance; a rejected upgrade stops inference and displays loading and retry guidance.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct provider repair with detailed shipped-entry-point proof, useful regression coverage, and green exact-head gating checks.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The full body records real LM Studio behind an injected-fault proxy, exercised through production Gateway chat.send and chat.history: rejected capacity loading sends no inference and displays matching recovery guidance, while delayed loading selects the returned 49152-token instance and receives PRELOAD_OK.; the inspected historical screenshots are not counted toward this proof.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Fresh LM Studio conversations can fail with misleading context-overflow guidance after a slow capacity upgrade falls back to a smaller instance.
Reason: The supplied real failure and successful Gateway replay establish user value, and the change preserves existing configuration and successful routing.

Merge readiness

✅ Ready for maintainer review

Keep this PR: it repairs a concrete LM Studio inference failure still present on current main, with supplied Gateway behavior proof and no actionable findings.

Priority: P2
Reviewed head: 2d1bd18f3c886457e4808362d7104314b2c2b117

Before merge

None.

Findings

None.

Agent review details

How this fits together

The LM Studio plugin prepares model capacity before OpenAI-compatible inference; core projects structured loading failures into live replies and saved chat history.

flowchart TD
  A[Gateway chat request] --> B[LM Studio preload wrapper]
  B --> C[Native model discovery and loading]
  C --> D[Prepared inference instance]
  D --> E[Chat completion]
  C --> F[Structured capacity failure]
  F --> G[Live reply and history renderer]
Loading

Technical review

Best possible solution:

Land the plugin-owned capacity repair with shared safe loading guidance and existing model identities and configuration intact.

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

Yes: the supplied delayed-load replay matches current main's 30-second deadline and fallback path; this review inspected source and supplied evidence without executing target code.

Is this the best way to solve the issue?

The repair addresses the loading owner, preserves unknown-capacity fallback and canonical routing, and gives live replies and history one safe renderer.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Native loading deadline changes intended behavior with a stated reason (0cfb83e: The original LM Studio integration bounded discovery and native loading with a 30-second default.)
  • Preload backoff and fallback changes intended behavior with a stated reason (b555214: Backoff avoided repeated rejected loads while allowing inference against models already loaded in LM Studio's UI.)
  • Canonical model identity keeps the original intent (405896a: Variant identifiers must resolve to canonical loadable keys, including after failed loading.)
  • Prepared instance routing keeps the original intent (2ddc37e: Inference must address the selected capacity while configuration and transcript identity remain canonical.)
  • Shared preload cancellation keeps the original intent (a92f85e: Cancelling one caller must not cancel a shared model load needed by another caller.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current main still contains the defect: Current main retains the 30000-millisecond native-load default and continues inference after preload failure without preserving a known capacity failure. (extensions/lmstudio/src/models.fetch.ts:240, 4ac1a8028b31)
  • Introduced loading repair: The pinned introduction diff propagates existing timeout settings, retains capacity failures through cooldown and failed rediscovery, and suppresses inference only for established capacity failures. (extensions/lmstudio/src/stream.ts:235, 2d1bd18f3c88)
  • Shared safe presentation: Live and recorded errors share a renderer that validates context counts and redacts, bounds, and escapes model labels without publishing provider diagnostics. (src/agents/failover/assistant-request-failure-copy.ts:218, 2d1bd18f3c88)
  • Supplied production Gateway proof: The full PR body records real LM Studio chat.send and chat.history replay: rejected loading produced no inference request and matching live/history guidance; delayed loading routed to google/gemma-4-e4b:2 and returned PRELOAD_OK. (2d1bd18f3c88)
  • Exact-head checks: Paginated check runs and commit statuses confirm a successful openclaw/ci-gate on the reviewed head; historical cancelled dispatch/context runs do not establish a patch failure. (2d1bd18f3c88)
  • Prior routing contract: Merged fix(lmstudio): route chat to the prepared model instance #141390 established transient instance routing while preserving canonical identity; this PR retains that behavior and repairs its failed-loading path. (extensions/lmstudio/src/stream.ts:276, 2ddc37e61d20)

Likely related people:

  • Peter Steinberger: Raw commit 2ddc37e adds extensions/lmstudio/src/models.fetch.ts:302 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2ddc37e61d20; files: extensions/lmstudio/src/models.fetch.ts)
  • Xan Torres: Raw commit b555214 adds extensions/lmstudio/src/stream.ts:38 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: b555214c9626; files: extensions/lmstudio/src/stream.ts)
  • Ted Li: Raw commit 405896a adds extensions/lmstudio/src/models.fetch.ts:241 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 405896a4a31b; files: extensions/lmstudio/src/models.fetch.ts)
  • Rugved Somwanshi: Raw commit 0cfb83e adds extensions/lmstudio/src/models.fetch.ts:202 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 0cfb83edfae9; files: extensions/lmstudio/src/models.fetch.ts)

PR surface

Source +38, Tests +119, Docs +6, Other -3. Total +160 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 130 92 +38
Tests 3 140 21 +119
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 2 0 3 -3
Total 10 276 116 +160

Review metrics

Metric Value Why it matters
Production versus test changes Production +130/-92; tests +140/-21 Plugin production changes are LOC neutral; net production growth supplies shared validated presentation, while tests protect capacity failures, timeout precedence, and diagnostic suppression.

Labels

Label changes:

  • add proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The shared live loading-failure guidance can appear in Telegram replies when an LM Studio capacity upgrade fails.

Label justifications:

  • P2: A bounded LM Studio cold-load defect breaks inference without evidence of widespread outage or blocked first-time onboarding.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The shared live loading-failure guidance can appear in Telegram replies when an LM Studio capacity upgrade fails.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-10T00:32:05.946Z sha d6e3c6a :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T01:05:42.639Z sha d6e3c6a :: blocked before merge. :: [P3] Describe the failure copy users actually receive
  • reviewed 2026-10-10T01:46:16.268Z sha 2d1bd18 :: needs maintainer review before merge. :: none

Reviewed October 9, 2026, 10:04 PM ET / October 10, 2026, 02:04 UTC (Revision 4).

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 10, 2026
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Oct 10, 2026
@steipete
steipete marked this pull request as ready for review October 10, 2026 01:32
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. 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. labels Oct 10, 2026
@steipete steipete self-assigned this Oct 10, 2026
@steipete
steipete merged commit 41cd441 into main Oct 10, 2026
215 of 217 checks passed
@steipete
steipete deleted the fix/lmstudio-preload-timeout-routing branch October 10, 2026 05:32
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
…penclaw#168044)

* fix(lmstudio): preserve context capacity when model loading fails

* test(lmstudio): collect preload events within supported TypeScript lib

* fix(agents): render structured model-loading failure guidance
RomneyDa added a commit that referenced this pull request Oct 12, 2026
…168044) (extracted hotfix)

Extracted from #168044 (41cd441): took only the default preload timeout
in extensions/lmstudio/src/models.fetch.ts (30s -> 120s). The branch's
stream preload never passes a timeout, so slow LM Studio model loads hit the
30s default, fall back to a too-small context instance, and fresh sessions
overflow. Left out the LmstudioModelLoadError class, the stream.ts rework that
threads configured request/provider timeouts into preload, the failover copy
in src/agents, docs, and baseline updates: they are a larger behavior and
error-surface change beyond the approved one-line fix.

Extracted-from: 41cd441
Co-authored-by: Peter Steinberger <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 12, 2026
Release provenance: 89329f6 -> #168587
Release provenance: e6a9022 -> #168905
Release provenance: 15f3f12 -> #162266
Release provenance: 20805b8 -> #169430
Release provenance: 568fec8 -> #169102
Release provenance: 39dba6d -> #160440
Release provenance: 5df28c7 -> #168393
Release provenance: 10bcd8e -> #168164
Release provenance: dc5f1f5 -> #168446
Release provenance: 9f1e441 -> #168044
Release provenance: 5a235fc -> #168651
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: lmstudio P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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