Skip to content

fix(runtime): honor endpoint-reported context windows - #2484

Merged
vastsa merged 7 commits into
vastsa:mainfrom
zhanglinrun:fix/session-discovered-context
Nov 21, 2026
Merged

vastsa merged 7 commits into
vastsa:mainfrom
zhanglinrun:fix/session-discovered-context

Conversation

@zhanglinrun

Copy link
Copy Markdown
Contributor

Problem

A saved Responses relay can report a 500,000-token context window while its catalog-owned binding resolves to 1,050,000. The composer used the endpoint value, but the launched session received the larger catalog value. With a 128,000-token output limit, the two windows yield automatic-compaction thresholds of 337,500 and 829,800 tokens. Regular follow-up requests can continue after the composer indicates the context is full.

The launch regression on 48a655826 received 1050000 where it expected 500000. The production-sidecar fixture also exercises both thresholds with the same consistent 400,000-token usage report. With the smaller window it writes one checkpoint before the follow-up request. With the larger window it sends the follow-up without a checkpoint.

Refs #1760. This reproduction exercises the window passed to the runtime. #1994 covers cached input omitted from the provider usage total. The original environment reported in #1760 has yet to be verified against this patch.

Fix

  • Carry the window explicitly reported by discovery through the host cache to main-session launch for catalog-owned bindings on saved non-OAuth endpoints. Match the provider and complete wire ID.
  • Store the reported window separately from display enrichment. The additive migration backs up v33 and preserves existing rows. Older cache rows can supply a reported limit after the next successful discovery refresh.
  • Check the saved endpoint under the Host lock and clear its reported capacity when the endpoint changes. Preserve manual and legacy bindings, output limits, and normal catalog fallback.

Verification

Windows x64, Node 22.19.0, pnpm 12.8.1. Tested candidate 5145ff846fba15f8ef360d80782d50ee4a7928a0 on 48a65582678ec04e018f90f8bc075253bad27085.

  • Session launch and related Desktop tests: 65 passed, including reported versus enriched cache values, manual and legacy bindings, mismatched model IDs, unlisted rows, and cache failure.
  • Agent-runtime budget and compaction tests: 20 passed.
  • Host provider and plugin-provider tests: 64 passed. The cache RPC and v33 migration tests each passed, including stale endpoint rejection and preservation of the old display cache.
  • Production sidecar with a localhost Responses fixture: all 5 scenarios passed. node scripts/e2e-context-usage-compaction.mjs after bundling the runtime.
  • Desktop build and typecheck, lint, docs checks, Rust formatting, and pnpm check:pr-base passed.

The full workspace test command stopped at a Windows path-separator assertion that also fails on the base. Separate local full Desktop and agent-runtime runs also had failures, including Electron-dependent failures and timeouts. Those broader failures were not all classified. The focused checks above ran against this change.

A saved relay can report a different context window from its catalog
binding. The inspector sees the endpoint limit, but session launch uses
the catalog window when deciding whether to compact.

Keep the reported limit separate from enriched display values and reuse
it at session launch for catalog-owned bindings. Older cache rows keep
their display data and fall back until the next successful discovery.
@vastsa

vastsa commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thanks — the root cause and the v33→v34 migration look right, but this cannot land yet: Rust host-core format / lint / test fails.

crates/host-core/src/mode_runs/elapsed_tests.rs:310 still asserts assert_eq!(version, 33);. With SCHEMA_VERSION = 34, the v29 upgrade now runs through the new 33→34 step and ends at 34. The PR removed the equivalent hard-coded 33 assertions in completion_report_migration_tests.rs and mode_runs_migration.rs but missed this one. Dropping that line (the next line already asserts SCHEMA_VERSION) should be enough; please re-run the full cargo test -p host-core --locked.

zhanglinrun and others added 6 commits November 21, 2026 13:49
The v29 upgrade also runs the migrations added after v33. Keep the assertion against SCHEMA_VERSION so the fixture verifies the full upgrade and continues checking the restored data.
The discovery handler now adds endpoint provenance before it writes the cache. Keep the existing checks for the live result and saved-endpoint guard without pinning the old argument expression.
The RPC fixtures upgrade through the current host schema. Compare with SCHEMA_VERSION so the existing data-preservation and constraint assertions continue to run after v34.
@vastsa
vastsa merged commit 6ec971c into vastsa:main Nov 21, 2026
6 checks passed
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.

2 participants