Add /context-size command to set context window for local providers - #696
Add /context-size command to set context window for local providers#696Gustav-Simonsson wants to merge 342 commits into
Conversation
Rename Unreleased to 0.2.104 and record the PRs that landed on main after 0.2.103. Compaction quality (corbitsdev#544) is still open and is not in this cut.
Cut changelog for 0.2.104
Release corbits 0.2.104
…b-agent-maxturns-hard-cap-of-100
…default-run_shell-timeout
0.2.104 is already tagged. Folding this into that section would claim a released cut contains work that is not in it.
0.2.104 is already tagged. Folding this into that section would claim a released cut contains work that is not in it.
…sub-agent-maxturns-hard-cap-of-100 Remove the sub-agent maxTurns hard cap of 100
Keep both Unreleased notes: run_shell timeout and maxTurns cap.
…s-default-run_shell-timeout Drop the built-in run_shell timeout default
…eserves-the-loop-and-drops-the-substance # Conflicts: # CHANGELOG.md
…preserves-the-loop-and-drops-the-substance Compaction preserves the loop and drops the substance
Walking the full history on every reactor event is wasteful. Cache prefix turn refs and add only the suffix when identities hold. Rewrite, shrink, or a middle identity break still fully recomputes so image-aging cannot leave a stale total.
The prompt Ctx meter kept showing prior occupancy after /new and /clear, and stayed inflated after a successful fold until the next inference.done. Clear the painted meter immediately on session clear, hide it when the session has no turns, and treat the post-compact governor estimate as authoritative until real usage arrives.
Operators could not tell from the TUI whether compaction folded context or no-op'd. Emit a short status flash only when the apply path records a summarized turn count — the same success gate as telemetry.
Idle compaction with an empty continuation never marked the governor estimate authoritative, so the prompt meter kept pre-fold occupancy until the next user turn. Resume with a meter-only settle so the shrunk estimate paints without starting another inference.
Bare HTTP 429s from known xAI/Grok providers remapped to retryable rate limits so moderate Retry-After no longer aborts as a long-window quota. The TUI stamps the live provider onto transcript formatting and the retry policy follows /model switches via a providerId getter.
transformMessages only drops an assistant turn when stripping thinking leaves empty content. Leftover thinking-only turns then replay as an identical request. Mark those turns at the sanitizer instead of dropping them.
…umentation-gaps-inference-error-partials-carry-no Persist inference errors on empty partials and honest exec turn counts
Prefix-stable compaction still uses one extractive shape on LLM failure, but dropping the CL-6906 marker made a lossy stub look like a real handoff summary. Restore the marker and keep the first summary turn byte-identical across later successful passes.
…n-every-reactor-event
…ead-100-kv-cache-loss
…ly-replay-guard Replace thinking-only replay turns with a stable marker
…ead-100-kv-cache-loss
…n-every-reactor-event
Accumulate turn, token, and tool counts in runSubAgent and send them on ambient subagent_end so dashboards stay answerable without leaf AI observability events.
Ambient capture sets $process_person_profile false so PostHog batch events stay anonymous; intentional survey capture omits the flag. Emit plugin_loaded once per plugin identity per process.
Update the event table and AI section for generation aggregates, opt-in spans, subagent_end rollups, director allowlisting, anonymous ambient processing, plugin_loaded dedupe, and generation sampling.
Capture parent_trace_id at task/spawn dispatch from the current turn noted at inference.start, instead of the last completed turn. Treat an empty generation sample-rate env as unset, and document that sampling drops opt-in spans with the generation.
…-event-volume-aggregate-tool-spans-into-the-turn Cut PostHog event volume with generation aggregates and subagent rollups
Release corbits 0.3.4
|
All contributors have signed the CLA. |
|
I have read the CLA Document and I hereby sign the CLA |
|
Question here for you -- how often do you change the context window for local models and is this something you generally define globally for local models or per model? Wondering if it makes more sense to expand a bit on what we define within the provider/model section and allow this to be overridden on models with a "local" tag? |
ab4779a to
8b115bf
Compare
TheGreatAxios
left a comment
There was a problem hiding this comment.
Review · Request changes
Adds a /context-size <tokens> command that, for keyless/local providers, writes providers.<name>.contextWindow to global settings and installs an in-process per-provider override consulted by contextWindowFor/hasContextWindowFor.
Diff hygiene
The PR shows +34382/−15173 across 666 files, but the real change is one commit (bb4a9b60, 5 files, +93/−7). The branch carries rewritten SHAs of upstream history (HEAD^ tree == origin/main at 0.3.4), so the PR diff is 0.3.4 → 0.3.7 noise. git merge-tree against origin/main conflicts in CHANGELOG.md, package.json, src/agent/tools.ts — all artifacts of the duplicated history; with --merge-base=HEAD^ the feature commit applies cleanly. Please git rebase --onto origin/main HEAD^ (or cherry-pick bb4a9b60 onto a fresh branch) so the PR shows the 5-file diff.
Findings
src/provider/context-window.ts:64-68, 84-97— the override is keyed byproviderFromModel, which requires aprovider:modelstring. The status bar passes bareconfig.model(src/tui/runner.ts:2081, 2092) and compaction passes bareevent.source?.model(src/agent/compaction.ts:100), so neither ever sees the override; only the/modelpicker (src/tui/model-catalog.ts:241, which passesoption.id) does. After/context-size 128000on Ollama, the meter and compaction threshold do not change. An Ollama tag likeqwen3:30balso makesproviderFromModelreturnqwen3.src/tui/runner.ts:2138-2143—providers.X.contextWindowalready has a meaning: it feedsmaxTokensFor(src/config/inference-sources.ts:63-66) →defaults.maxTokens→max_tokens/max_output_tokenson the wire. After/context-size 131072and a restart, every request carriesmax_tokens: 131072; llama.cpp/vLLM validatingprompt + max_tokens <= n_ctxreject or clamp. This needs either a new settings field or reconciling whatcontextWindowmeans first.src/tui/runner.ts:2131-2146— in-memoryconfig.settingsis not updated; a same-session/modelswitch (buildSessionSources()at:2377-2378) reads the old value, so behavior differs before and after restart.src/tui/runner.ts:2138-2144—if (prov)silently skips the write when the provider is absent from the global file, but the command still reports "Context window set".loadGlobalSettingsWriteBasereturns{providers:{}}for a missing file, so a provider defined elsewhere gets a false success.src/tui/commands/built-in.ts:235-238—Number(args)accepts12.5,1e5,0x20000while the usage text says<positive-integer>;12.5round-trips into settings. AddNumber.isIntegerand an upper bound.- No tests.
src/provider/context-window.test.tsandsrc/tui/commands/built-in.test.tscover the neighboring code.
Notes
- Registration follows
/yolo(built-in.ts:193,registry.ts:28-29), the keyless gate is correct, and passingoption.idtocontextWindowForinmodel-catalog.ts:238-242is behavior-preserving. - Checks:
bun run typecheck,bun run lint(prettier clean; 4 pre-existing warnings in runner.ts outside the diff),bun test src/provider/context-window.test.ts src/tui/commands/built-in.test.ts src/tui/commands/registry.test.ts src/tui/model-catalog.test.ts(59 pass).
Summary
Add /context-size command to make it easier to set max context size for local models.