Skip to content

Add /context-size command to set context window for local providers - #696

Closed
Gustav-Simonsson wants to merge 342 commits into
corbitsdev:mainfrom
Gustav-Simonsson:add-context-size-cmd
Closed

Add /context-size command to set context window for local providers#696
Gustav-Simonsson wants to merge 342 commits into
corbitsdev:mainfrom
Gustav-Simonsson:add-context-size-cmd

Conversation

@Gustav-Simonsson

Copy link
Copy Markdown

Summary

Add /context-size command to make it easier to set max context size for local models.

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.
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.
…ly-replay-guard

Replace thinking-only replay turns with a stable marker
TheGreatAxios and others added 19 commits August 26, 2026 09:15
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
@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA.
Posted by the CLA Assistant Lite bot.

@Gustav-Simonsson

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Aug 27, 2026
@TheGreatAxios

Copy link
Copy Markdown
Collaborator

Hey @Gustav-Simonsson

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?

@TheGreatAxios TheGreatAxios left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 by providerFromModel, which requires a provider:model string. The status bar passes bare config.model (src/tui/runner.ts:2081, 2092) and compaction passes bare event.source?.model (src/agent/compaction.ts:100), so neither ever sees the override; only the /model picker (src/tui/model-catalog.ts:241, which passes option.id) does. After /context-size 128000 on Ollama, the meter and compaction threshold do not change. An Ollama tag like qwen3:30b also makes providerFromModel return qwen3.
  • src/tui/runner.ts:2138-2143providers.X.contextWindow already has a meaning: it feeds maxTokensFor (src/config/inference-sources.ts:63-66) → defaults.maxTokensmax_tokens/max_output_tokens on the wire. After /context-size 131072 and a restart, every request carries max_tokens: 131072; llama.cpp/vLLM validating prompt + max_tokens <= n_ctx reject or clamp. This needs either a new settings field or reconciling what contextWindow means first.
  • src/tui/runner.ts:2131-2146 — in-memory config.settings is not updated; a same-session /model switch (buildSessionSources() at :2377-2378) reads the old value, so behavior differs before and after restart.
  • src/tui/runner.ts:2138-2144if (prov) silently skips the write when the provider is absent from the global file, but the command still reports "Context window set". loadGlobalSettingsWriteBase returns {providers:{}} for a missing file, so a provider defined elsewhere gets a false success.
  • src/tui/commands/built-in.ts:235-238Number(args) accepts 12.5, 1e5, 0x20000 while the usage text says <positive-integer>; 12.5 round-trips into settings. Add Number.isInteger and an upper bound.
  • No tests. src/provider/context-window.test.ts and src/tui/commands/built-in.test.ts cover the neighboring code.

Notes

  • Registration follows /yolo (built-in.ts:193, registry.ts:28-29), the keyless gate is correct, and passing option.id to contextWindowFor in model-catalog.ts:238-242 is 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants