Skip to content

fix(agents): keep a stored context window when the same model is re-picked - #547

Open
Leo310 wants to merge 2 commits into
mainfrom
fix/542-context-window
Open

Leo310 wants to merge 2 commits into
mainfrom
fix/542-context-window

Conversation

@Leo310

@Leo310 Leo310 commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

What

Re-picking the same chat model no longer overwrites its stored context window with provider metadata or the 128000 fallback. hydrateChatModel always fills contextWindow (falling back to 128000 when the provider reports nothing), and buildPersistedChatModel let that win, so a tuned window (e.g. an Ollama num_ctx sized to the machine) was lost as soon as the model was re-selected after Ollama came up. Now: same provider+model → stored value wins; different model → catalogue value as before.

Also adds a Context window number field under "Chat model" in the Agent editor, so the value can be set without hand-editing data.json. Shown only when a chat model is set; rejects non-positive values with a Notice and invalidates the agent runnable so the new value applies.

Fixes #542

Not in this PR (follow-ups):

  • onExternalSettingsChange, so edits to data.json while Obsidian runs are picked up.
  • The summary trigger has a 12000-token floor (getSummarizationTriggerTokens), so windows below about 15k can fill up before history is summarized. This predates the PR.
  • A model picked while its provider was unreachable still stores the 128000 fallback, and re-picking it now keeps that. The new field is the way out. Telling a fallback apart from a tuned value would mean making HydratedChatModelMetadata.contextWindow optional, which ripples into the picker's "ctx" labels, so I left it out.

How I tested it

  • New unit tests in test/utils/persistedChatModel.test.ts cover the precedence: same model keeps the stored window; a different model, or the same model name on another provider, takes the catalogue value; missing stored value falls back to the catalogue; vision follows the catalogue and temperature is kept.
  • bun run check, format, lint, test pass locally (1995 tests).
  • Dev build is in slot wt1 (S2B WT1 vault), not yet live-tested in Obsidian; Leo will test the editor field and the Ollama re-pick there.

AI assistance: Claude Code (Opus) wrote the fix, tests and editor field from Leo's triage brief for #542; Leo reviews and live-tests before merge.

Checklist

  • bun run check, bun run format, bun run lint, and bun run test pass locally
  • I tried the change in a real Obsidian vault (or explained above why that isn't applicable)
  • I read CONTRIBUTING.md, including the section on AI assistance
  • If this adds a provider, a bundled skill, a built-in tool, or changes manifest.json: I noted that the docs site needs updating (see "Documentation" in CONTRIBUTING.md) — n/a

…icked (#542)

buildPersistedChatModel let hydrated catalogue metadata win over the stored
contextWindow. hydrateChatModel always fills that field (128000 when the
provider reports nothing), so once Ollama was reachable any re-pick of the
same model replaced a user-tuned window. Re-picking the stored provider+model
now keeps the stored value; a different model still takes the catalogue value.

Also adds a Context window field under the chat model in the Agent editor so
the value no longer has to be edited by hand in data.json.

Co-Authored-By: Claude <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge with no outstanding findings.

Summary

The PR keeps a stored context window when the same provider and model are picked again. It also adds a context-window field to the agent editor.

  • Picking the same chat model keeps its saved context window.
  • The Agent editor lets users set a chat model’s context window.

Reviews (2) · Last reviewed commit: "fix(agents): restore the saved context w..." · Reviewed by Greptile

Comment thread src/components/modal/AgentEditorModal.svelte
Comment thread src/components/modal/AgentEditorModal.svelte
Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: When restarting Ollama & Obsidian, wrong context size set

1 participant