Skip to content

Fix background todo policy for current-turn activity#316052

Open
vritant24 wants to merge 6 commits into
mainfrom
vritant/bg-todo-cross-turn-fix
Open

Fix background todo policy for current-turn activity#316052
vritant24 wants to merge 6 commits into
mainfrom
vritant/bg-todo-cross-turn-fix

Conversation

@vritant24
Copy link
Copy Markdown
Member

Enhance background todo functionality by scoping policy to current-turn activity, preventing stale context from affecting future turns.

vritant24 added 3 commits May 12, 2026 09:37
… against stale turns

Background todo passes were triggered by accumulated activity from previous
turns when a conversation continued, causing todos to be recreated even for
trivial messages like 'hi'.

Three interacting problems are fixed:

1. Policy threshold used total substantiveToolCallCount across all unprocessed
   rounds (including previous turns). Add currentTurnSubstantiveToolCallCount
   to IBackgroundTodoDeltaMetadata and use it in shouldRun() so only current-
   turn activity drives threshold checks.

2. requestFinalReview fired on every turn end as long as _hasCreatedTodos was
   true, using _lastExecutionContext from a previous turn. Track
   _lastExecutionContextTurnId and skip when the context is stale.

3. _consecutiveInitialNoops persisted across turns, penalizing a new user
   message with backoff from a previous turn's exploration. Track
   _lastSeenTurnId and reset per-turn state when the turn changes.

Also annotate tool-call rounds with 1-based turn indices (IToolCallRoundWithTurn)
so the prompt can render <turn> boundary markers, and add renderRoundsGroupedByTurn
for token-efficient turn grouping.

Fixes stream: false on the copilot-fast request that caused SSE parse failures.
Update both system messages (regular and final-review) with turn-aware
trajectory format documentation and cross-turn rules:

- Rounds are now grouped inside <turn index="N"> wrappers instead of
  repeating a turn attribute per round, saving tokens.
- Cross-turn rules instruct the model to treat previous turns as already-
  reflected context and only update todos based on current-turn activity.
- Final-review prompt focuses completion evidence on the latest turn and
  skips tool calls when the turn had no substantive activity.

PreviousContextRoundChunk emits <turn> open/close tags at boundaries via
annotateWithTurnBoundaries(). Inline rendering uses renderRoundsGroupedByTurn.
- backgroundTodoDelta: test currentTurnSubstantiveToolCallCount only counts
  current-turn rounds, is zero for history-only deltas, excludes processed
  rounds, and matches total when no history is present.

- backgroundTodoHistory: update collectAllRounds test for turn-annotated
  output, wrap buildBackgroundTodoHistory rounds with turnIndex, add turnIndex
  to all IBackgroundTodoHistoryRound inline objects, add renderRoundsGroupedByTurn
  tests for turn boundary wrapping.
Copilot AI review requested due to automatic review settings May 12, 2026 16:39
@vritant24 vritant24 self-assigned this May 12, 2026
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

This PR updates the background todo invocation policy and prompt format to scope “activity” to the current user turn, reducing cases where unprocessed historical rounds inflate thresholds or create stale-context updates.

Changes:

  • Adds current-turn-only substantive tool-call counting (currentTurnSubstantiveToolCallCount) and switches policy thresholds to use it.
  • Annotates tool-call rounds with 1-based turnIndex and renders <turn index="…"> groupings in the background todo prompt.
  • Tracks last-seen turn IDs to reset per-turn policy state and to skip final review when the cached execution context is from a different turn.
Show a summary per file
File Description
extensions/copilot/src/extension/prompts/node/agent/test/backgroundTodoHistory.spec.ts Updates history tests for turn-indexed rounds and adds coverage for turn-group rendering.
extensions/copilot/src/extension/prompts/node/agent/test/backgroundTodoDelta.spec.ts Adds tests validating current-turn-only substantive tool-call counting.
extensions/copilot/src/extension/prompts/node/agent/backgroundTodoPrompt.tsx Updates prompt instructions and renders rounds grouped by <turn> boundaries.
extensions/copilot/src/extension/prompts/node/agent/backgroundTodoProcessor.ts Switches policy to current-turn counts and adds turn-aware state/reset + stale-context final review skipping.
extensions/copilot/src/extension/prompts/node/agent/backgroundTodoDelta.ts Extends delta metadata with current-turn substantive counts used by policy.
extensions/copilot/src/extension/intents/node/agentIntent.ts Plumbs latest turnId into background todo processor requests.

Copilot's findings

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

vritant24 added 2 commits May 12, 2026 09:53
- Make PreviousContextRoundChunk self-contained by always wrapping each
  round in <turn> tags, preventing unbalanced tags when PrioritizedList
  prunes boundary rounds. Remove annotateWithTurnBoundaries helper.

- Add currentTurnSubstantiveToolCallCount to all dummyMeta object literals
  in policy and processor tests for type safety.

- Add unit tests for requestFinalReview turn-ID guard: verify it skips
  when execution context is from a different turn and runs when IDs match.
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.

3 participants