Skip to content

add model level context_window config - #4941

Merged
aheritier merged 1 commit into
docker:mainfrom
krissetto:fix/compaction-model-definition-warning
Nov 17, 2026
Merged

aheritier merged 1 commit into
docker:mainfrom
krissetto:fix/compaction-model-definition-warning

Conversation

@krissetto

Copy link
Copy Markdown
Contributor

The runtime needs to know how much context a model can handle before it can summarize a long conversation.

When that information is missing (e.g. for custom providers or local models that don't have a catalog entry in models.dev), upon compaction users get a Failed to get model definition error in the chat, with no explanation of why or how to fix it.

⚠️ Breaking change ⚠️
These changes should only impact users of local models/custom providers etc when using models that can't be resolved from the models.dev catalog, but they are a breaking change to the configuration

What?

This PR:

  • Adds context_window directly to model configuration to declare the supported context capacity.
  • Turns the missing-context error into an error notification that names the affected model and explains how to fix it.
  • Rejects non-positive values and values above the model’s known catalogue maximum (when present).
  • Keeps provider_opts.context_size exclusively for DMR, where it configures the actual inference engine (the provider).

For example:

models:
  my_model:
    provider: my_provider
    model: my_model_name
    context_window: 128000 # Use the deployment’s actual supported limit or what you want to limit to

This setting doesn’t make the model’s window bigger or reconfigure the server. It tells Docker Agent what capacity is available. The existing compaction threshold still controls when to summarize.

Migration

Non-DMR configurations using provider_opts.context_size must move that value to the model’s context_window. An actionable validation error explains this. DMR’s existing engine setting remains supported.

Includes documentation, schema updates, and regression tests.

Copilot AI balanced review requested due to automatic review settings November 16, 2026 10:54
@aheritier aheritier added area/config For configuration parsing, YAML, environment variables area/docs Documentation changes area/models LLM model integrations and model providers area/providers/openai For features/issues/fixes related to the usage of OpenAI models area/providers/anthropic For features/issues/fixes related to the usage of Anthropic models area/providers/docker-model-runner Docker Model Runner (DMR) local inference area/runtime Runtime engine, agent loop execution, tool dispatch, loop detection kind/feat PR adds a new feature (maps to feat:). Use on PRs only. status/needs-rebase PR has merge conflicts or is out of date with main labels Nov 16, 2026
@aheritier

Copy link
Copy Markdown
Collaborator

👋 This PR has merge conflicts with the base branch. Please rebase or merge the latest base branch and resolve them. I've moved it to draft and added ; it'll be picked back up automatically once the conflicts are cleared.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Context-size validation and picker calculations use incompletely resolved provider configurations, causing valid aliases to be rejected, incompatible declarations to bypass checks, and displayed context windows to disagree with runtime behavior.

3 open issues
What changed in this PR

This PR adds explicit model context capacity to Docker Agent, enabling context accounting and compaction for uncatalogued models without changing the provider’s engine configuration.

Changes:

  • Adds model-level context_window, validation, and catalogue-cap checks while reserving provider_opts.context_size for DMR.
  • Uses declared windows in compaction, output-token limits, and model-picker metadata.
  • Adds actionable, session-scoped compaction warnings, documentation, schema updates, and regression coverage.
File Description
sdk/​typescript/​src/​generated/​runtime.ts Adds optional warning session IDs.
sdk/​typescript/​src/​generated/​config.ts Exposes context_window in generated types.
sdk/​typescript/​schemas/​docker-agent.schema.json Adds context-window and warning-session fields.
pkg/​tui/​page/​chat/​warning_routing_test.go Tests root and sub-session warning presentation.
pkg/​tui/​page/​chat/​runtime_events.go Labels warnings from sub-agents.
pkg/​teamloader/​teamloader.go Checks declared windows against catalogue limits.
pkg/​server/​runtime_config_test.go Migrates the fixture to context_window.
pkg/​runtime/​warning_session_test.go Tests warning session scope and serialization.
pkg/​runtime/​session_compaction.go Resolves declared windows and explains missing capacity.
pkg/​runtime/​modelcatalog/​dmr_models.go Uses effective windows for DMR picker metadata.
pkg/​runtime/​modelcatalog/​dmr_models_test.go Tests model-level DMR picker capacity.
pkg/​runtime/​modelcatalog/​catalog.go Uses effective windows for configured models.
pkg/​runtime/​loop.go Updates comments describing window resolution.
pkg/​runtime/​loop_steps_test.go Allows additional warnings during overflow recovery.
pkg/​runtime/​event.go Adds session-scoped warning support.
pkg/​runtime/​context_window_thresholds_test.go Tests capacity-based compaction thresholds.
pkg/​runtime/​context_breakdown_test.go Updates a comment to reference context_window.
pkg/​runtime/​compaction_unknown_window_test.go Tests actionable warnings and history preservation.
pkg/​runtime/​compaction_scenarios_test.go Updates failed-compaction event expectations.
pkg/​runtime/​compaction_context_limit_test.go Tests declared-window precedence and fallback behavior.
pkg/​runtime/​clone_failure_test.go Migrates provider fixtures to declared windows.
pkg/​model/​provider/​openai/​max_tokens_test.go Uses model-level windows in output-limit tests.
pkg/​model/​provider/​openai/​context_window_test.go Tests clamping and request-field exclusion.
pkg/​model/​provider/​openai/​client.go Uses declared windows for output-token clamping.
pkg/​model/​provider/​dmr/​context_window_model_test.go Tests separation of metadata and engine settings.
pkg/​model/​provider/​dmr/​configure.go Adds a comment explaining engine-setting separation.
pkg/​model/​provider/​anthropic/​client.go Prefers declared context windows.
pkg/​mcp/​runtime_config_test.go Migrates the fixture to context_window.
pkg/​config/​schema_test.go Tests rejection of invalid context-window values.
pkg/​config/​max_tokens_warning.go Updates output-limit diagnostics for declared windows.
pkg/​config/​max_tokens_warning_test.go Tests the updated diagnostics.
pkg/​config/​latest/​validate.go Adds context-declaration and selector validation.
pkg/​config/​latest/​types.go Defines the field and window-resolution helpers.
pkg/​config/​latest/​context_size_test.go Tests decoding, precedence, and validation.
pkg/​config/​context_window_cap.go Implements catalogue-cap validation.
pkg/​config/​context_window_cap_test.go Tests catalogue limits and unavailable-store handling.
pkg/​acp/​runtime_config_test.go Migrates the fixture to context_window.
pkg/​acp/​outcome_test.go Expects actionable compaction warnings.
pkg/​acp/​commands.go Preserves root routing for untagged events.
pkg/​acp/​commands_test.go Migrates the native-compaction fixture.
pkg/​a2a/​runtime_config_test.go Migrates the fixture to context_window.
examples/​model_context_window.yaml Demonstrates custom and DMR model declarations.
e2e/​tui/​routing_test.go Migrates scripted model capacities.
e2e/​tui/​background_agent_test.go Exposes scripted capacity through context_window.
docs/​providers/​dmr/​index.md Distinguishes accounting metadata from engine sizing.
docs/​guides/​compaction/​index.md Explains unknown windows and threshold behavior.
docs/​configuration/​models/​index.md Documents configuration, precedence, and migration.
cmd/​root/​run_config_propagation_test.go Migrates the CLI propagation fixture.
agent-schema.json Defines the positive-integer field and its semantics.

Review effort: Balanced

Comment thread pkg/config/latest/validate.go Resolved
Comment thread pkg/config/latest/validate.go Resolved
Comment thread pkg/runtime/modelcatalog/catalog.go Resolved
@krissetto
krissetto force-pushed the fix/compaction-model-definition-warning branch from 246d2c1 to 91be62f Compare November 16, 2026 11:38
Copilot AI balanced review requested due to automatic review settings November 16, 2026 11:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

YAML serialization can silently discard default_model.context_window during saves, while environment-based model names and inline compaction models can bypass required context-window validation.

5 open issues
1 resolved since last review

Review effort: Balanced

Comment thread pkg/config/latest/types.go Resolved
Comment thread pkg/config/context_window_cap.go Resolved
Comment thread pkg/teamloader/teamloader.go Resolved
@aheritier aheritier removed the status/needs-rebase PR has merge conflicts or is out of date with main label Nov 16, 2026
@krissetto
krissetto force-pushed the fix/compaction-model-definition-warning branch from 91be62f to e6788d5 Compare November 16, 2026 12:03
Copilot AI balanced review requested due to automatic review settings November 16, 2026 12:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Inline compaction and title model references bypass the migration validation, allowing configurations to load while silently losing configured context windows instead of producing actionable errors.

4 open issues
2 resolved since last review

Review effort: Balanced

Comment thread pkg/config/context_window.go Resolved
@krissetto
krissetto force-pushed the fix/compaction-model-definition-warning branch from e6788d5 to 8d088b0 Compare November 16, 2026 12:32
Copilot AI balanced review requested due to automatic review settings November 16, 2026 12:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Model Garden catalogue-identity mismatches can allow oversized context windows, while inline fallback and title models bypass migration validation for inherited context_size settings.

2 open issues
4 resolved since last review

Review effort: Balanced

Comment thread pkg/config/context_window.go Resolved
Comment thread pkg/config/context_window_cap.go Resolved
@krissetto
krissetto force-pushed the fix/compaction-model-definition-warning branch from 8d088b0 to a3fc7a2 Compare November 16, 2026 13:08
Copilot AI balanced review requested due to automatic review settings November 16, 2026 13:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Cap validation expands environment variables for unselected model candidates, causing configuration loading to fail when an optional candidate references an unset variable even though a local model was selected.

3 open issues

Review effort: Balanced

Comment thread pkg/config/context_window_cap.go Resolved
@krissetto
krissetto force-pushed the fix/compaction-model-definition-warning branch from a3fc7a2 to 673db0b Compare November 16, 2026 13:35
Copilot AI balanced review requested due to automatic review settings November 16, 2026 13:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The router’s declared context window is not passed to its fallback client, allowing uncatalogued OpenAI-compatible endpoints to receive oversized max_tokens values inconsistent with runtime accounting.

1 open issue
3 resolved since last review

Review effort: Balanced

Comment thread pkg/model/provider/factory.go Resolved
@krissetto
krissetto force-pushed the fix/compaction-model-definition-warning branch from 673db0b to 700f4a6 Compare November 16, 2026 14:29
Copilot AI balanced review requested due to automatic review settings November 16, 2026 14:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The migration instructions omit updating the top-level version to "16", leaving older configs unloadable because version-specific strict parsing rejects context_window before migration.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread docs/configuration/models/index.md Resolved
…paction windows

Models outside the models.dev catalogue (custom openai_responses or
openai_chatcompletions endpoints, self-hosted models) had no way to declare
their context window, so context accounting and compaction could not run.

Add a model-level `context_window` to the latest config. It is capacity
metadata: it sets the window that context usage, compaction thresholds and
max_tokens clamping are measured against. It is never sent as a request
parameter and never reconfigures the DMR engine.

Precedence for a model's window, highest first:
- models.<name>.context_window
- provider_opts.context_size, for the dmr provider only (it also sizes the
  DMR engine, so it must equal context_window when both are set)
- the window discovered at runtime
- the models.dev catalogue

provider_opts.context_size is no longer read for non-DMR providers. Config
validation rejects it there and names context_window as the replacement.
Custom providers and aliases are judged by the provider they run.

Validation also rejects a non-positive context_window, a DMR conflict with
provider_opts.context_size, and a context_window above the context window
the models.dev catalogue declares for the same model. The catalogue check
uses the runtime's model identity after alias resolution and compares the
raw catalogue limit. Models the catalogue has no limit for accept any
positive value. Dedicated compaction_model entries are checked like any other.

The compaction-window warning now names models.<name>.context_window. Unknown
compaction windows are reported as a session-tagged WarningEvent instead of a
transcript error, and the outcome stays "failed" (previously the
"Failed to get model definition" error). WarningEvent carries an optional
session_id, and ACP /compact no longer drops untagged events.

Schema, TypeScript SDK, docs, an example and tests are updated to match.

Signed-off-by: Christopher Petito <chrisjpetito@gmail.com>
@krissetto
krissetto force-pushed the fix/compaction-model-definition-warning branch from 700f4a6 to 1acc9f7 Compare November 16, 2026 14:49
Copilot AI balanced review requested due to automatic review settings November 16, 2026 14:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the model-level context-window change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@krissetto
krissetto marked this pull request as ready for review November 16, 2026 16:19
@krissetto
krissetto requested a review from a team as a code owner November 16, 2026 16:19
@aheritier
aheritier added this pull request to the merge queue Nov 17, 2026
Merged via the queue into docker:main with commit 19a7356 Nov 17, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config For configuration parsing, YAML, environment variables area/docs Documentation changes area/models LLM model integrations and model providers area/providers/anthropic For features/issues/fixes related to the usage of Anthropic models area/providers/docker-model-runner Docker Model Runner (DMR) local inference area/providers/openai For features/issues/fixes related to the usage of OpenAI models area/runtime Runtime engine, agent loop execution, tool dispatch, loop detection kind/feat PR adds a new feature (maps to feat:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants