agentSubscription.ts ×16

Frontier kind: Joint frontier

unlabeled · c_d62b4c5346e8

1 test · 15608 LOC · 93 files · introduces 1 test · 62 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
16 ranges62 lines · 1 files
Tests
1 test

Contains — complete concept membership

All code (extent)
1378 ranges15608 lines · 93 files · Browse complete extent
All tests (intent)
1 testBrowse 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.

1 test introduced at this concept.

Introduced code

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

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

src/vs/platform/agentHost/common/state/agentSubscription.ts 62 introduced LOC · 16 ranges

Open complete file

417
418 constructor(
419 > chatUri: string, agentSubscription.ts
420 > clientId: string,
421 > seqAllocator: () => number,
422 > log: (msg: string) => void,
423 > ) {
424 > super(clientId, log);
425 > this._chatUri = chatUri;
426 > this._seqAllocator = seqAllocator;
427 > }
428
429 /**
432 */
433 applyOptimistic(action: ChatAction): number {
434 > const clientSeq = this._seqAllocator(); agentSubscription.ts
435 > this._pendingActions.push({ clientSeq, action });
436 > const base = this._optimisticState ?? this.verifiedValue;
437 > if (base) {
438 > this._optimisticState = chatReducer(base, action as IProtocolChatAction, this._log);
439 > this._onDidChange.fire(this._optimisticState);
440 > }
441 > return clientSeq;
442 > }
443
444 protected override _getOptimisticState(): ChatState | undefined {
445 > return this._optimisticState; agentSubscription.ts
446 > }
447
448 protected override _applyReducer(state: ChatState, action: StateAction): ChatState {
449 > return chatReducer(state, action as IProtocolChatAction, this._log); agentSubscription.ts
450 > }
451
452 protected override _isRelevantEnvelope(envelope: ActionEnvelope): boolean {
453 > return isChatAction(envelope.action) && envelope.channel === this._chatUri; agentSubscription.ts
454 > }
455
456 protected override _onSnapshotApplied(fromSeq: number): void {
457 > super._onSnapshotApplied(fromSeq); agentSubscription.ts
458 > this._recomputeOptimistic();
459 > }
460
461 protected override _reconcile(envelope: ActionEnvelope, isOwnAction: boolean): void {
462 > // A rejected envelope must never mutate confirmed state — it only rolls agentSubscription.ts
463 > // back the originating client's matching optimistic action. Guarding all
464 > // apply branches also prevents a broadcast rejection from leaking the
465 > // rejected action into a non-origin client's state.
466 > if (isOwnAction && envelope.origin) {
467 const idx = this._pendingActions.findIndex(p => p.clientSeq === envelope.origin!.clientSeq);
468 if (idx !== -1) {
474 this._confirmedApply(envelope.action);
475 }
476 > } else if (!envelope.rejectionReason) { agentSubscription.ts
477 > this._promotePendingTurnStartIfTerminal(envelope.action);
478 > this._confirmedApply(envelope.action);
479 > }
480 > this._recomputeOptimistic();
481 > }
482
483 private _promotePendingTurnStartIfTerminal(action: StateAction): void {
484 > // A backend-originated terminal turn action may arrive without the clientSeq agentSubscription.ts
485 > // that would normally confirm our optimistic turn start. Promote that start
486 > // first so the terminal action can close it instead of leaving it pending.
487 > if (!isChatAction(action)) {
488 return;
489 }
490 > if (action.type !== ActionType.ChatTurnComplete && action.type !== ActionType.ChatTurnCancelled && action.type !== ActionType.ChatError) { agentSubscription.ts
491 return;
492 }
493 > const index = this._pendingActions.findIndex(p => p.action.type === ActionType.ChatTurnStarted && p.action.turnId === action.turnId); agentSubscription.ts
494 > if (index === -1) {
495 return;
496 }
497 > const [{ action: pendingAction }] = this._pendingActions.splice(index, 1); agentSubscription.ts
498 > if (this._confirmedState && (!this._confirmedState.activeTurn || this._confirmedState.activeTurn.id !== action.turnId)) {
499 > this._confirmedState = this._applyReducer(this._confirmedState, pendingAction);
500 > }
501 > }
502
503 private _confirmedApply(action: StateAction): void {
504 > if (this._confirmedState) { agentSubscription.ts
505 > this._confirmedState = this._applyReducer(this._confirmedState, action);
506 > }
507 > }
508
509 private _recomputeOptimistic(): void {
510 > const confirmed = this._confirmedState; agentSubscription.ts
511 > if (!confirmed) {
512 this._optimisticState = undefined;
513 return;
514 }
515 > if (this._pendingActions.length === 0) { agentSubscription.ts
516 > this._optimisticState = undefined;
517 > this._onDidChange.fire(confirmed);
518 > return;
519 > }
520 let state = confirmed;
521 for (const pending of this._pendingActions) {
524 this._optimisticState = state;
525 this._onDidChange.fire(state);
527
528 clearPending(): void {