Skip to content

NES: opt-in global-budget cascade for prompt parts#315565

Merged
ulugbekna merged 4 commits into
mainfrom
ulugbekna/nes-global-budget-cascade
May 11, 2026
Merged

NES: opt-in global-budget cascade for prompt parts#315565
ulugbekna merged 4 commits into
mainfrom
ulugbekna/nes-global-budget-cascade

Conversation

@ulugbekna
Copy link
Copy Markdown
Contributor

Behind a new exp flag, NES prompt parts (recentlyViewedDocuments, languageContext, neighborFiles, diffHistory) share a single token pool with cascading surplus, mirroring completions-core's `CascadingPromptFactory`. `currentFile` and `lintOptions` stay outside the budget.

Today

Each NES prompt part has its own absolute `maxTokens` cap (e.g. `recentlyViewedDocuments: 2000`, `diffHistory: 1000`). Unused tokens in one part are wasted — they cannot flow to another part. By contrast, completions-core's production path uses a single `promptTokenLimit` with weighted/percentage allocation; surplus from earlier components naturally feeds later ones.

Change

Add an opt-in `globalBudget` field to `PromptOptions`. When set, `getUserPrompt` runs a cascade: each part gets `surplus + totalTokens * shares[part]`, sub-builders are invoked with that override (existing logic untouched), unspent budget cascades to the next part.

Default order: `languageContext → recentlyViewedDocuments → neighborFiles → diffHistory` (neighborFiles must follow recentlyViewed because it consults `docsInPrompt`; enforced at runtime). Default shares match today's `maxTokens` ratios over a 6000-token total — volume-neutral baseline.

Exp flags

  • `chat.advanced.inlineEdits.xtabProvider.globalBudget.enabled` (default `false`)
  • `chat.advanced.inlineEdits.xtabProvider.globalBudget.totalTokens` (default `6000`)

Regression safety

When `globalBudget` is undefined, `getUserPrompt` takes the legacy code path verbatim. A new parity test asserts the cascade with a large `totalTokens` produces byte-identical output to the legacy path. All 252 xtab unit tests pass.

Commits

  1. Add `GlobalBudgetOptions` type (no behavior change)
  2. Implement cascade in `getUserPrompt` + tests
  3. Wire exp flags in `xtabProvider`

Copilot AI review requested due to automatic review settings May 10, 2026 19:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an experiment-gated “global budget” cascade for NES (xtab) prompt construction so multiple prompt parts share a single token pool with surplus flowing to later parts, similar to completions-core’s cascading prompt factory.

Changes:

  • Introduces GlobalBudgetOptions/globalBudget in PromptOptions, with defaults for order/shares/total tokens.
  • Implements the cascade path in getUserPrompt and refactors recent-files helpers to support independent sub-builder invocation.
  • Wires new experiment settings in the xtab provider and adds unit tests for cascade parity/validation.
Show a summary per file
File Description
extensions/copilot/src/platform/inlineEdits/common/dataTypes/xtabPromptOptions.ts Adds global-budget types + defaults and plumbs globalBudget into PromptOptions.
extensions/copilot/src/platform/configuration/common/configurationService.ts Adds experiment-based config keys for enabling global budget and setting totalTokens.
extensions/copilot/src/extension/xtab/common/promptCrafting.ts Implements the global-budget cascade and switches getUserPrompt between legacy vs cascade paths.
extensions/copilot/src/extension/xtab/common/recentFilesForPrompt.ts Extracts helpers (prepareRecentCodeSnippets, exports appenders) to enable cascade sub-builders.
extensions/copilot/src/extension/xtab/node/xtabProvider.ts Wires the new experiment flags into constructed promptOptions.globalBudget.
extensions/copilot/src/extension/xtab/test/common/promptCrafting.spec.ts Adds tests for cascade parity (large budgets) and order validation.

Copilot's findings

  • Files reviewed: 6/6 changed files
  • Comments generated: 2

Comment thread extensions/copilot/src/extension/xtab/common/promptCrafting.ts
Comment thread extensions/copilot/src/extension/xtab/common/promptCrafting.ts Outdated
Copy link
Copy Markdown

@almassolarenrgi almassolarenrgi left a comment

Choose a reason for hiding this comment

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

ulugbekna added 4 commits May 11, 2026 12:59
When opts.globalBudget is set, recentlyViewedDocuments, languageContext,
neighborFiles and diffHistory share a single token pool: each part is
allocated totalTokens*shares[part] plus the cumulative surplus from
earlier parts in the cascade order. Mirrors completions-core's
CascadingPromptFactory model. currentFile and lintOptions stay outside
the budget.

The legacy code path is byte-identical when globalBudget is undefined.
Adds two exp-based config keys:
- chat.advanced.inlineEdits.xtabProvider.globalBudget.enabled (default false)
- chat.advanced.inlineEdits.xtabProvider.globalBudget.totalTokens (default 6000)

When enabled, populates PromptOptions.globalBudget with the default
cascade order and shares matching today's per-part maxTokens ratios.
…onfig

Address PR review:
- Each sub-builder now returns tokensConsumed measured with its own
  internal accounting (paged-clipping line cost, raw-snippet cost for
  appenders, diff-entry cost for history). The cascade uses that value
  to compute surplus so it stays consistent with how each part charges
  against its own budget.
- Validate GlobalBudgetOptions at runtime: no duplicates in order, every
  part in order has a share entry, and shares sum to ~1 (epsilon 1e-3).
  Tests added for each failure mode.
@ulugbekna ulugbekna force-pushed the ulugbekna/nes-global-budget-cascade branch from c455673 to 2933ad2 Compare May 11, 2026 07:59
@ulugbekna ulugbekna merged commit 6ca8278 into main May 11, 2026
25 checks passed
@ulugbekna ulugbekna deleted the ulugbekna/nes-global-budget-cascade branch May 11, 2026 08:16
@vs-code-engineering vs-code-engineering Bot added this to the 1.121.0 milestone May 11, 2026
@ulugbekna ulugbekna added the ~release-cherry-pick Trigger: cherry-pick this PR to the latest release branch label May 12, 2026
@vs-code-engineering vs-code-engineering Bot added release-cherry-pick Automated cherry-pick between release and main branches and removed ~release-cherry-pick Trigger: cherry-pick this PR to the latest release branch labels May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-cherry-pick Automated cherry-pick between release and main branches

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants