pendingRequestRegistry.ts ×9

Frontier kind: Code frontier

unlabeled · c_f6d6bfaf2d96

641 tests · 6974 LOC · 32 files · introduces 0 tests · 75 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
9 ranges75 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1005 ranges6974 lines · 32 files · Browse complete extent
All tests (intent)
641 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 75 introduced LOC across 9 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/common/pendingRequestRegistry.ts 75 introduced LOC · 9 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- pendingRequestRegistry.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { DeferredPromise } from '../../../base/common/async.js';
7 > import { CancellationError } from '../../../base/common/errors.js';
8 >
9 > /**
10 > * Registry of parked deferred promises keyed by string id. Used to
11 > * track request/response round-trips where a callback fires a signal
12 > * that an external responder may resolve synchronously.
13 > *
14 > * The atomic register-then-fire is enforced by {@link registerAndFire}
15 > * rather than by convention: a synchronous responder (e.g.
16 > * `agentSideEffects.ts:_handleToolReady` auto-approving writes inside
17 > * the listener for the fired signal) registered AFTER the fire would
18 > * miss its response and the awaited promise would deadlock — a
19 > * regression caught in Claude phase 7.
20 > */
21 > export class PendingRequestRegistry<T> {
22 private readonly _entries = new Map<string, DeferredPromise<T>>();
23 /**
28 */
29 private readonly _earlyResults = new Map<string, T>();
31 > registerAndFire(key: string, fire: () => void): Promise<T> {
32 if (this._earlyResults.has(key)) {
33 const buffered = this._earlyResults.get(key) as T;
40 return deferred.p;
41 }
43 > /**
44 > * Park a deferred under `key` and return its promise. Use when there
45 > * is no synchronous responder to guard against — the request that
46 > * eventually feeds {@link respond} originates from a different code
47 > * path (e.g. an MCP handler invoked by the SDK whose completion
48 > * arrives via a workbench round-trip).
49 > *
50 > * If `key` is already registered (duplicate `tool_use_id` from the
51 > * SDK, retry, or logic bug), the previous deferred is rejected with
52 > * a {@link CancellationError} so its awaiter unwinds instead of
53 > * leaking forever.
54 > */
55 > register(key: string): Promise<T> {
56 if (this._earlyResults.has(key)) {
57 const buffered = this._earlyResults.get(key) as T;
67 return deferred.p;
68 }
70 > respond(key: string, value: T): boolean {
71 const deferred = this._entries.get(key);
72 if (!deferred) {
77 return true;
78 }
80 > /**
81 > * Like {@link respond}, but if no deferred is parked under `key`, buffer
82 > * the value so a subsequent {@link register} / {@link registerAndFire}
83 > * for the same key resolves immediately. Use when the completion may
84 > * legitimately arrive before the awaiting handler registers (the
85 > * Copilot client-tool round-trip, whose SDK handler and the workbench
86 > * completion race).
87 > */
88 > respondOrBuffer(key: string, value: T): void {
89 if (!this.respond(key, value)) {
90 this._earlyResults.set(key, value);
91 }
92 }
94 > /** Whether a result arrived before a request registered under `key`. */
95 > hasBufferedResult(key: string): boolean {
96 return this._earlyResults.has(key);
97 }
99 > /**
100 > * Resolve every parked deferred with `denyValue` and clear the registry.
101 > *
102 > * Designed for the permission-deny path: a "deny" answer is itself a
103 > * successful round-trip result, so awaiting consumers receive `denyValue`
104 > * rather than an error. Use {@link rejectAll} when callers must observe
105 > * a thrown error instead (cancellation, dispose).
106 > */
107 > denyAll(denyValue: T): void {
108 for (const [, deferred] of this._entries) {
109 if (!deferred.isSettled) {
114 this._earlyResults.clear();
115 }
117 > /**
118 > * Reject every parked deferred with `error` and clear the registry.
119 > *
120 > * Use this when in-flight requests must be cancelled rather than
121 > * answered (e.g. session dispose, `Query` rebind on tool-set change).
122 > * Compare with {@link denyAll}, which *resolves* every deferred with a
123 > * supplied value — that is right for the permission-deny path where a
124 > * "deny" is itself a successful answer, but wrong for cancellation
125 > * where the awaited consumer must observe an error to unwind.
126 > */
127 > rejectAll(error: Error): void {
128 for (const [, deferred] of this._entries) {
129 if (!deferred.isSettled) {