Repository navigation
Proposal: Show the enforced context limit, and overflow-patch to a safe size #22
Description
Proposal
Why
opencode's context display and its 413-overflow auto-patch both use the wrong
"context size", which hid a fleet-wide misconfiguration for weeks (audit
2026-07-11).
-
The status bar shows capacity, not the enforced wall. The sidebar
denominator (packages/tui/src/feature-plugins/sidebar/context.tsx) reads
model.limit.context, which discovery sets to/api/fitmax_safe_ctx
(or, when fit is unavailable,/v1/models context_length, or ultimately the
models.dev catalog's native value). None of those is the enforced
--ctx-size. A fleet model pinned at--ctx-size 3072displayed as
"… / 467k" (the catalog native), so requests 413'd at 3072 while the UI
implied a 467k window. opencode already fetches the enforced value as a
separatecontextMax(configured_ctx) but never shows it. -
Setting ctx via opencode reverts.
setModelCtxSize
(server/routes/instance/httpapi/handlers/local.ts) PATCHes the backend
(correct) and optimistically writeslimit.contextin memory as the raw
ctx_size. Butprovider.list()never re-discovers, so on the next
discoverylimit.contextis repopulated frommax_safe_ctx— a different
quantity — and the set value appears to "not stick". -
The 413-overflow handler patches to the native max.
adjustLocalContextOnOverflow(packages/opencode/src/provider/provider.ts)
reacts to a 413 by PATCHing the backendctx_sizeto the reportedmax_ctx
(the model's native context). On a VRAM-constrained host that value cannot
load — observed live: it bumped one host's 35B to 262144 and another's 35B to
110592, both unloadable. It "fixes" overflow by creating an OOM.
What
- Display the enforced limit. The context denominator MUST be the enforced
per-request context (contextMax/configured_ctx), notmax_safe_ctxand
never the catalog native. Where both are useful, show used / safe-budget with
the enforced ceiling in parentheses; never present a capacity number the
backend will reject against. - Make a set stick. After
setModelCtxSizesucceeds, re-run discovery for
that provider (or re-fetch/api/fit) solimit.contextreflects the new
enforced value with consistent semantics, instead of an in-memory value that
reverts on the next discovery. - Overflow-patch to a safe size.
adjustLocalContextOnOverflowMUST patch
ctx_sizeto a VRAM-safe value derived from/api/fit(the achievable
ceiling for current VRAM), not the raw nativemax_ctx. If no safe value is
available it MUST surface the overflow rather than set an unloadable ctx.
Non-goals
- No routing/placement changes (separate change
ctx-aware-subagent-placement). - No change to llama-skein's
/api/fitmath (separate change
bound-max-safe-ctxin the llama-skein repo).
Impact
packages/tui/src/feature-plugins/sidebar/context.tsxand the app metrics
helper: denominator source.packages/opencode/src/provider/provider.ts:adjustLocalContextOnOverflow
target value; discovery-refresh after set.packages/opencode/src/server/routes/instance/httpapi/handlers/local.ts:
setModelCtxSizetriggers a provider re-discovery.
Disposition (2026-09-18)
Shipped. Shipped: sidebar shows limit.contextMax ?? limit.context; provider.test.ts covers adjustLocalContextOnOverflow.
Tasks
- 1. Sidebar denominator (
context.tsx) uses the enforced hard ceiling
(limit.contextMax= configured_ctx), falling back tocontextfor
cloud; discovery now setscontextMaxfrom fit's configured_ctx or the
reported context_length (never the models.dev catalog native). - 2.
adjustLocalContextOnOverflow: probes/api/fitat the target ctx and
only grows whenfit_level !== "no"; otherwise surfaces the overflow
instead of patching to an unloadable native ceiling. - 3.
setModelContextLimitalso setscontextMaxto the new ctx_size, so
the set persists in the display; the next discovery re-reads it from the
now-patched backend (no revert to a capacity number). - 4. Tests: display/overflow logic is in the large discovery/provider
module — covered by typecheck + deploy verification for now; a focused
unit test is a follow-up. (REMAINING) - 5.
bun run typecheckgreen in bothopencodeandtuipackages
(0 errors).
Unchecked items above: see Disposition in proposal.md (2026-09-18).
Plan changes
4 done
Activity
androidand commentedon Sep 17, 2026
Shipped; archived 2026-09-18 (see Disposition in proposal).