Skip to content

rewrite polling function #262947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

rewrite polling function #262947

wants to merge 15 commits into from

Conversation

meganrogge
Copy link
Contributor

@meganrogge meganrogge commented Aug 22, 2025

To do:

  • finish this
  • test all paths

@meganrogge meganrogge self-assigned this Aug 22, 2025
@meganrogge meganrogge marked this pull request as draft August 22, 2025 15:51
@meganrogge meganrogge added this to the August 2025 milestone Aug 22, 2025
@meganrogge meganrogge requested a review from Tyriar August 22, 2025 20:21
@meganrogge meganrogge marked this pull request as ready for review August 22, 2025 20:21
@meganrogge meganrogge requested a review from Copilot August 22, 2025 20:35
Copy link
Contributor

@Copilot 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 refactors the OutputMonitor polling functionality to use an event-driven approach instead of promise-based monitoring. The changes move from a startMonitoring() method that returns a result to one that fires events and exposes results via properties.

Key changes:

  • Replace promise-based polling with event-driven monitoring that fires onDidFinishCommand events
  • Restructure the constructor to automatically start monitoring and accept monitoring parameters
  • Extract common polling utilities into a new bufferOutputPolling.ts file

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
outputMonitor.test.ts Updated tests to use event-driven pattern and new constructor signature
runInTerminalTool.ts Modified to use new OutputMonitor API with event listening instead of promise awaiting
outputMonitor.ts Major refactor to event-driven polling with constructor-based initialization
taskHelpers.ts Updated to use new OutputMonitor event-driven API
bufferOutputPolling.ts New file containing extracted polling utility functions
mcpSamplingService.ts Updated ExtensionIdentifier from 'core' to 'Github.copilot-chat'

Comment on lines 85 to 86
// Ensure this method always runs truly async so listeners can attach
await Promise.resolve();
Copy link
Member

Choose a reason for hiding this comment

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

await timeout(0) would be more clear here, I'm not sure how awaiting a resolved promise behaves exactly.

Comment on lines 105 to 106
// If we timed out, optionally ask to keep waiting
if (this._state === OutputMonitorState.Timeout) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: switches are nicer when considering every state in a closed set of states like this imo

Comment on lines +50 to +51
private _pollingResult: IPollingResult & { pollDurationMs: number } | undefined;
get pollingResult(): IPollingResult & { pollDurationMs: number } | undefined { return this._pollingResult; }
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if we can hide anything here but any details we can hide we should so that the OutputMonitor API to the outside is as simple as possible

Comment on lines +273 to 281
// Let custom poller override if provided
const custom = await pollFn?.(execution, token, this._taskService);
if (custom) {
return custom;
}

const modelOutputEvalResponse = await this._assessOutputForErrors(buffer, token);
return { output: buffer, state: this._state, modelOutputEvalResponse };
}
Copy link
Member

Choose a reason for hiding this comment

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

Try splitting out the waiting for idle from the actioning and handling that in _startMonitoring. Can we leverage the waitForIdle helper here to simplify this?

…r/tools/monitoring/outputMonitor.ts

Co-authored-by: Daniel Imms <[email protected]>
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.

2 participants