Skip to content

Remove await in discovery phase#300537

Merged
pwang347 merged 4 commits intomainfrom
pawang/discoveryPerf
Mar 10, 2026
Merged

Remove await in discovery phase#300537
pwang347 merged 4 commits intomainfrom
pawang/discoveryPerf

Conversation

@pwang347
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings March 10, 2026 20:04
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 prompt discovery debug logging in the chat prompts service to avoid awaiting discovery info computation on the critical path, so agent/skill/hook/instruction resolution can return sooner while discovery details are collected asynchronously.

Changes:

  • Make discovery-info collection fire-and-forget for custom agents, skills, hooks, and instruction files.
  • Keep existing discovery log entries, but emit them after discovery info resolves.
Comments suppressed due to low confidence (3)

src/vs/workbench/contrib/chat/common/promptSyntax/service/promptsServiceImpl.ts:1201

  • getHookDiscoveryInfo() is now executed without await, but the promise rejection isn’t handled. If it rejects (IO/JSON parse errors outside the inner try, or cancellation), this will produce an unhandled promise rejection. Add a rejection handler (ignore CancellationError, log others) to keep this safe.
			void this.getHookDiscoveryInfo(token).then((discoveryInfo) => {
				const details = hookCount === 1
					? localize("promptsService.resolvedHook", "Resolved {0} hook in {1}ms", hookCount, elapsed.toFixed(1))
					: localize("promptsService.resolvedHooks", "Resolved {0} hooks in {1}ms", hookCount, elapsed.toFixed(1));
				this._onDidLogDiscovery.fire({
					sessionResource,
					name: localize("promptsService.loadHooks", "Load Hooks"),
					details,
					discoveryInfo,
					category: 'discovery',
				});
			});

src/vs/workbench/contrib/chat/common/promptSyntax/service/promptsServiceImpl.ts:1222

  • Fire-and-forget getInstructionsDiscoveryInfo() call doesn’t handle rejection. If listPromptFiles/_collectSourceFolderDiagnostics fails or the token is cancelled, this can create an unhandled promise rejection. Add a .catch (and ignore CancellationError) so discovery logging doesn’t destabilize the request path.
			void this.getInstructionsDiscoveryInfo(token).then((discoveryInfo) => {
				const details = result.length === 1
					? localize("promptsService.resolvedInstruction", "Resolved {0} instruction in {1}ms", result.length, elapsed.toFixed(1))
					: localize("promptsService.resolvedInstructions", "Resolved {0} instructions in {1}ms", result.length, elapsed.toFixed(1));
				this._onDidLogDiscovery.fire({
					sessionResource,
					name: localize("promptsService.loadInstructions", "Load Instructions"),
					details,
					discoveryInfo,
					category: 'discovery',
				});
			});

src/vs/workbench/contrib/chat/common/promptSyntax/service/promptsServiceImpl.ts:659

  • These fire-and-forget discoveryInfo calls don’t handle rejections. If getAgentDiscoveryInfo() throws (e.g. listPromptFiles / diagnostics collection fails or token cancellation), this becomes an unhandled promise rejection and can surface as noisy errors or crash telemetry. Add a rejection handler (and consider ignoring CancellationError) so failures are logged/ignored and don’t go unobserved.
			void this.getAgentDiscoveryInfo(token).then((discoveryInfo) => {
				const details = result.length === 1
					? localize("promptsService.resolvedAgent", "Resolved {0} agent in {1}ms", result.length, elapsed.toFixed(1))
					: localize("promptsService.resolvedAgents", "Resolved {0} agents in {1}ms", result.length, elapsed.toFixed(1));
				this._onDidLogDiscovery.fire({
					sessionResource,
					name: localize("promptsService.loadAgents", "Load Agents"),
					details,
					discoveryInfo,
					category: 'discovery',
				});
			});

@pwang347 pwang347 marked this pull request as ready for review March 10, 2026 20:26
@vs-code-engineering vs-code-engineering bot added this to the 1.112.0 milestone Mar 10, 2026
@pwang347 pwang347 merged commit d71bb75 into main Mar 10, 2026
19 checks passed
@pwang347 pwang347 deleted the pawang/discoveryPerf branch March 10, 2026 20:52
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