Repository navigation
add model level context_window config - #4941
Conversation
|
👋 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. |
There was a problem hiding this comment.
🟡 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 reservingprovider_opts.context_sizefor 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
246d2c1 to
91be62f
Compare
There was a problem hiding this comment.
🟡 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
Preserve context_window when serializing shorthand models · New Expand model environment variables before cap lookup · New Validate inline compaction models before construction · New Honor inherited api_type when validating DMR context_size Validate provider options after migration and provider resolution
1 resolved since last review
Review effort: Balanced
91be62f to
e6788d5
Compare
There was a problem hiding this comment.
🟡 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
e6788d5 to
8d088b0
Compare
There was a problem hiding this comment.
🟡 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
8d088b0 to
a3fc7a2
Compare
There was a problem hiding this comment.
🟡 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
a3fc7a2 to
673db0b
Compare
There was a problem hiding this comment.
🟡 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
673db0b to
700f4a6
Compare
There was a problem hiding this comment.
🟡 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
…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>
700f4a6 to
1acc9f7
Compare



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 definitionerror in the chat, with no explanation of why or how to fix it.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:
context_windowdirectly to model configuration to declare the supported context capacity.provider_opts.context_sizeexclusively for DMR, where it configures the actual inference engine (the provider).For example:
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_sizemust move that value to the model’scontext_window. An actionable validation error explains this. DMR’s existing engine setting remains supported.Includes documentation, schema updates, and regression tests.