Fix background todo agent behavior on main agent completion#314277
Merged
Fix background todo agent behavior on main agent completion#314277
Conversation
…w with drain-queue architecture Replace the old single-slot coalescing model with a two-slot queue (regular pass + final review) and a central _drainQueue() scheduler. Key changes: - requestRegularPass(): enqueues/coalesces regular passes, always updates _lastExecutionContext - requestFinalReview(turnId): enqueues a final-review pass that drains after all regular work, deduplicated by turn ID - _drainQueue(): central scheduler called after every state transition; picks regular work first, then final review - advanceCursor parameter on _runPass(): regular passes advance the delta tracker cursor, final review does not (fixes hidden bug where the old code accidentally called markProcessed despite the comment saying it should not) - Turn-scoped _finalReviewAttemptedTurnId replaces the fragile boolean _finalReviewQueued that was reset by executePass The old executeFinalReview() called start() which checked _state === InProgress as a coalescing gate. Since a regular pass always finishes before the finally block runs executeFinalReview, the processor was always Idle and start() would fall through to _runPass()—but only if the preconditions were met. The new architecture makes final review a pending queue item that _drainQueue() will run regardless of whether the processor is Idle, InProgress, or Failed at the time of the request.
- _maybeStartBackgroundTodoPass() calls requestRegularPass() instead of executePass(), including for the processorInProgress coalescing case - handleRequest() finally block calls requestFinalReview(turnId) instead of executeFinalReview(), passing the turn ID for deduplication - Update JSDoc @link reference in BackgroundTodoPromptProps
- Add makeExecutionContext() helper for requestRegularPass/requestFinalReview tests - Add advanceCursor=false cursor test (verifies final review does not advance the delta tracker) - Add requestFinalReview tests: no-op guards, runs-when-idle, turn-ID dedup, drains-after-regular-pass - Update cancel test to verify it clears final review queue - Rename executeFinalReview references to requestFinalReview
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the Copilot extension’s background todo processor scheduling so that regular background passes coalesce while a “final review” pass is queued separately and reliably drained after regular work once the main agent turn completes.
Changes:
- Replaced the previous single pending-delta coalescing with a two-slot drain queue: (1) coalesced regular pass, then (2) once-per-turn final review.
- Introduced
requestRegularPassandrequestFinalReview(turnId)APIs and updated the agent intent orchestration to use them. - Updated/expanded unit tests to cover the new queueing semantics and cursor-advancement behavior.
Show a summary per file
| File | Description |
|---|---|
| extensions/copilot/src/extension/prompts/node/agent/test/backgroundTodoProcessor.spec.ts | Adds tests for requestFinalReview, queue draining, and cursor advancement behavior. |
| extensions/copilot/src/extension/prompts/node/agent/backgroundTodoPrompt.tsx | Updates docs/comment reference from executeFinalReview to requestFinalReview. |
| extensions/copilot/src/extension/prompts/node/agent/backgroundTodoProcessor.ts | Implements the two-slot queue, adds new public queue APIs, and ensures final review does not advance the delta cursor. |
| extensions/copilot/src/extension/intents/node/agentIntent.ts | Switches orchestration to requestRegularPass/requestFinalReview(turnId) and awaits completion at turn end. |
Copilot's findings
- Files reviewed: 4/4 changed files
- Comments generated: 2
Contributor
Screenshot ChangesBase: Changed (5)Errored (18)Fixtures that failed to render — no screenshot was produced.
|
benvillalobos
approved these changes
May 5, 2026
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.
Reworks the background todo processor to use a small drain queue for regular passes and final review. Regular passes still coalesce, but final review is now queued separately and drained once per turn after regular work, so it can run reliably even when the processor is idle.