Skip to content

v0.21.8 — plexus contextWindow fallback (live-trim tail-cap fix)

Choose a tag to compare

@TheArchitectit TheArchitectit released this 19 Aug 12:50
· 19 commits to master since this release

Fix

plexus (OpenAI-compatible) providers do not report contextWindow in getContextUsage(). The context handler set lastCtxWindow = usage.contextWindow ?? 0, so it was 0 for those providers. This silently disabled:

  • The live-trim tail-cap (guarded on ctxWindow > 0) — which reserves output headroom
  • The token-gate window math

Without the tail-cap, a 32k-context model's own ~12k output overflowed the window every turn → truncation loop (stopReason: "length"), even though mega-compact was running.

Root cause

context-handler.ts:119 had no fallback when usage.contextWindow was 0.

Fix

Fall back to runtime.currentModel?.contextWindow (populated from models.json via captureModel on model_select) when the provider-reported window is 0. Mirrors the gate's existing pct fallback (gateCheck.ts S27).

const reportedWindow = usage?.contextWindow ?? 0;
runtime.lastCtxWindow =
    reportedWindow > 0
        ? reportedWindow
        : (runtime.currentModel?.contextWindow ?? 0);

Test

New test auto-trigger: resolves lastCtxWindow from captured model when provider omits contextWindow (S29-b plexus fallback) — fires model_select (32k/20k model) then context with contextWindow: 0, asserts lastCtxWindow === 32000 and currentModel.maxTokens === 20000.

Note on the test

The test accesses lastRuntime via the module namespace (reg.lastRuntime) rather than destructuring (const { lastRuntime } = ...), because destructuring breaks the ES module live binding and snapshots a prior test's runtime.


LTS patch. No new features. No config changes required.