Skip to content

agent-host: log subscribe + state replay in IPC output channel#314916

Draft
roblourens wants to merge 2 commits intomainfrom
roblou/log-ahp-subscription-state-replay
Draft

agent-host: log subscribe + state replay in IPC output channel#314916
roblourens wants to merge 2 commits intomainfrom
roblou/log-ahp-subscription-state-replay

Conversation

@roblourens
Copy link
Copy Markdown
Member

The LoggingAgentConnection wrapper was passing getSubscription through unwrapped, so neither the subscribe call nor the snapshot/state replay the server sends back surfaced in the per-host output channel. When opening a session, the channel showed nothing for the subscription handshake.

Wrap the returned subscription with a logger that emits:

  • >> subscribe { kind, resource } when getSubscription is called
  • ** <kind>(<resource>).current if the inner sub is already hydrated
  • ** <kind>(<resource>).onDidChange on each value change (this is what surfaces the server snapshot / state replay)
  • >> unsubscribe { kind, resource } on ref dispose

Refcount the logger per inner IAgentSubscription instance via a static WeakMap so multiple wrappers (e.g. chat + terminal) sharing the same underlying sub still only log once, and the listener is torn down with the last ref.

No-op when agentHost.ipcLogging is disabled.

The LoggingAgentConnection wrapper was passing getSubscription through
unwrapped, so neither the subscribe call nor the snapshot/state replay
that the server sends back surfaced in the per-host output channel.

Wrap the returned subscription with a logger that emits a one-shot
.current line (if already hydrated) and an .onDidChange line per state
change. Refcount the logger per inner subscription instance so multiple
wrappers (e.g. chat + terminal) sharing the same underlying sub still
only log once, and tear it down with the last ref. Also log >> subscribe
and >> unsubscribe at the call sites.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Base: f6d5140c Current: efe3499d

No screenshot changes.

Copilot AI review requested due to automatic review settings May 7, 2026 06:18
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 the agent-host IPC tracing wrapper (LoggingAgentConnection) so that getSubscription(...) calls are logged to the per-host output channel, including initial hydration/current state and subsequent state replay via onDidChange.

Changes:

  • Wrap getSubscription(...) to log subscribe/unsubscribe calls and state changes (current + onDidChange).
  • Deduplicate per-subscription onDidChange logging across multiple wrappers via a static WeakMap refcount.
Show a summary per file
File Description
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/loggingAgentConnection.ts Adds logging + deduped refcounted listeners for state subscriptions to surface snapshot/state replay in the output channel.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 2

* onDidChange logger per inner subscription and dispose it when the last
* wrapper goes away.
*/
private static readonly _subscriptionLoggers = new WeakMap<IAgentSubscription<unknown>, { refCount: number; store: DisposableStore }>();
Comment on lines +232 to +237
const store = new DisposableStore();
const label = `${kind}(${resource.toString()})`;
if (sub.value !== undefined) {
this._log('**', `${label}.current`, sub.value);
}
store.add(sub.onDidChange(value => this._log('**', `${label}.onDidChange`, value)));
Map StateComponents (numeric const enum) to 'root'/'session'/'terminal'
strings before logging, and widen the static WeakMap key type to
`object` so it accepts subscriptions with any `T` parameter.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@roblourens roblourens force-pushed the roblou/log-ahp-subscription-state-replay branch from 449a32e to 69e3c70 Compare May 7, 2026 18:33
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