Skip to content

feat(copilot): add independent context window selection in v2 - #54782

Closed
anxkhn wants to merge 3 commits into
anomalyco:devfrom
anxkhn:copilot-context-v2
Closed

anxkhn wants to merge 3 commits into
anomalyco:devfrom
anxkhn:copilot-context-v2

Conversation

@anxkhn

@anxkhn anxkhn commented Oct 12, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #53521. Replaces #53553 with a V2 port targeting dev, as requested by @thdxr. Related to #38164 and #52089.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds Default/Long context selection for Copilot models that advertise separate input budgets. /context-window changes the window without changing reasoning effort. The combined selection persists through the existing variant field, such as medium@long.

The resolver applies the selected input budget and preserves configured caps. Context percentages use the window of the latest response. Copilot token-price tiers include cached input, and Copilot-only sessions display estimated AI credits. Mixed-provider sessions keep USD. These are estimates, not GitHub's billed amounts.

Includes the generated client and OpenAPI contracts, mini-mode support, and documentation for V2's --model provider/model#variant syntax.

The model catalog lists only actual reasoning variants. Context suffixes resolve directly, and existing selections remain valid across clients. Existing sessions without a context suffix use the smaller Default budget and may compact earlier. Long is opt-in.

How did you verify your code works?

With Bun 1.4.2:

  • Root bun run check passed.
  • Latest focused checks: 118 core tests, 105 TUI tests, and 10 app variant tests passed. Coverage includes configured reasoning overlays, input caps, custom variant names, selection persistence, hidden-model prices, compaction costs, and narrow/wide picker interaction.
  • Protocol and website generated-document checks passed. Website typecheck, build, and link validation passed.
  • Isolated macOS arm64 CLI build passed.
  • Full TUI suite: 1,466 passed, 2 skipped, 3 timeout failures. The same compact-at-70-columns test and both shell-output cases fail on clean upstream/dev at 25053bbdc7. The isolated baseline run had 7 passed and 3 timeout failures.

Screenshots / recordings

Production context picker rendered at 60 and 120 columns:

60 columns 120 columns
Context picker at 60 columns Context picker at 120 columns

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@anxkhn
anxkhn marked this pull request as ready for review October 12, 2026 10:05

@opencode-agent opencode-agent Bot 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.

I couldn't check this end to end: the context picker only appears for a GitHub Copilot model with a long-context price tier, and that needs real Copilot credentials. The PR's core tests (30) and TUI tests (22) pass, and typecheck passes in packages/core and packages/tui. I couldn't produce screenshots for the same reason. The picker screenshots in the description cover the new dialog; a before/after of the prompt footer and sidebar cost line would help.

Public API (adds to the API and removes nothing, but clients will see the extra variants):

  • Model.Info gains an optional context: { default: number, long: number } in the schema, OpenAPI files and generated client.
  • Copilot models that have a long-context tier now list extra variants <effort>@default / <effort>@long (for example default@long and high@default) next to the reasoning variants.
  • The stored variant string can now be effort@tier, also through --model provider/model#variant.
  • New TUI command context.list with the /context-window slash command.

Concerns

  1. The combined variants show up in other clients. The TUI filters them out, but the web/desktop app lists Object.keys(model.variants) as-is (packages/app/src/providers/models/selection.tsx). For a Copilot model with low/medium/high reasoning, the app would offer eleven choices (default@default, low@long, high@default…), and picking one there changes the context window without saying so. Can the context tier be kept out of the variant list, for example by resolving effort@tier in the resolver without adding every combination to model.variants? If not, the app needs the same filter and picker.
  2. Default behaviour changes for Copilot users. Users who haven't chosen anything are now held to the smaller default budget (withVariant uses context.default when no variant is selected), so their sessions compact earlier than before. That may be intended, matching Copilot CLI, but it should be called out.

Details are in the inline comments.

Related: #38164, #52089

Comment thread packages/core/src/model-resolver.ts Resolved
@anxkhn
anxkhn force-pushed the copilot-context-v2 branch from 5fa63e2 to 2bbfa5c Compare October 12, 2026 10:11

@opencode-agent opencode-agent Bot 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.

Both concerns from my last review are resolved:

  • Variants listed in other clients: Copilot models now list only their reasoning variants. provider.ts no longer adds tier combinations or skips Variant.resolve. The resolver, the subagent tool, the TUI and the app accept effort@tier through the shared @opencode/util/model-variant helper.
  • Default budget change: models.mdx now says Default is used unless Long is selected, and that existing sessions compact earlier.

I couldn't run it end to end, because the picker only appears for a Copilot model that advertises separate input budgets, which needs Copilot credentials. The tests nearest the change pass (core 89, TUI 33, app 10), and typecheck passes in core, tui, app and util.

Public API (backwards compatible): Model.Info gains an optional context: { default, long } in the schema, OpenAPI files and generated client. The variant reference accepted by the server, the CLI #variant syntax and the subagent tool now also accepts <effort>@default|long for models with context. There's a new TUI command, context.list (/context-window). Copilot model variant lists are unchanged.

One small point that doesn't block a merge: the new app test (preserves combined saved selections… in packages/app/src/providers/models/variant.test.ts) packs ten edge-case assertions into one case. It would be easier to follow cut down to the core cases: keeping a saved effort@long, rejecting an unknown effort, and cycling effort without changing the tier.

Related: #38164, #52089

@opencode-agent

Copy link
Copy Markdown
Contributor

Thanks, I checked both in aa8ce27. The config plugin is back on the normal path: no generated combinations and no Variant.resolve bypass. The models docs now explain the Default fallback and the earlier compaction. Both points are resolved, as my latest review says.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Independent Copilot context-window selection and AI-credit usage

1 participant