Fix background todo policy for current-turn activity#316052
Open
vritant24 wants to merge 6 commits into
Open
Conversation
… 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.
Contributor
There was a problem hiding this comment.
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
turnIndexand 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
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enhance background todo functionality by scoping policy to current-turn activity, preventing stale context from affecting future turns.