357
358
this._register(this._stateManager.onDidEmitEnvelope(envelope => {
360
>
if (this._replayBuffer.length > REPLAY_BUFFER_CAPACITY) {
361
this._replayBuffer.shift();
362
}
364
>
// A client tool call may be issued for a client that is no longer
365
>
// connected — e.g. a stale stamp from a window that reloaded. The
366
>
// live-disconnect path (`_handleClientDisconnected`) does not cover
367
>
// these because no disconnect event fires for an already-gone
368
>
// client. Detect the orphan at issuance time and arm the same
369
>
// grace-period timeout so the call cannot hang forever. Calls
370
>
// stamped while no client is connected are failed immediately by
371
>
// the provider, so they never reach this path.
372
>
if (envelope.action.type === ActionType.ChatToolCallStart || envelope.action.type === ActionType.ChatToolCallReady) {
373
if (!isAhpChatChannel(envelope.channel)) {
374
throw new Error(`[ProtocolServer] Chat tool-call action emitted on non-chat channel: ${envelope.channel}`);