fix(vscode): file an editor comment under the session it was delivered to

A comment written with no session tab open opens one, and that panel knows
its directory long before it has loaded the session list and selected its
session. The webview filed the draft on the first snapshot that had a
directory, with the session key falling back to "draft" because no session
was current yet. The panel's composer reads the session's key, so the chip
never appeared, while the editor thread saw the draft in the store snapshot
and reported it attached.

A session panel now stamps its session on every comment it delivers, and
the webview waits until it actually shows that session before filing. The
sidebar files on its current session or an open new-session draft, and no
longer falls back to "draft" merely because nothing is selected yet. The
resolver is a pure module with tests.

Claude-Session: https://claude.ai/code/session_01VqV56Hez25hTxXH4ipJfzH
This commit is contained in:
Bohdan Triapitsyn
2026-09-05 14:18:51 +03:00
parent 4f1f9e6650
commit 60a4dccb32
5 changed files with 141 additions and 17 deletions
@@ -30,6 +30,12 @@ type LineCommentPayload = {
type SessionPanelState = {
/** This panel's id, which is also its surface identity for comment threads. */
id: string;
/**
* The session this panel was opened for; null for a new-session panel. A
* comment delivered here names it, so the webview files the draft under that
* session's key rather than whatever it shows while still booting.
*/
sessionId: string | null;
panel: vscode.WebviewPanel;
sseStreams: Map<string, AbortController>;
/**
@@ -148,6 +154,7 @@ export class SessionEditorPanelProvider {
const state: SessionPanelState = {
id: panelId,
sessionId: initialSessionId,
panel,
sseStreams: new Map(),
pendingLineComments: [],
@@ -183,7 +190,7 @@ export class SessionEditorPanelProvider {
void panel.webview.postMessage({
type: 'command',
command: 'addLineComment',
payload: pending,
payload: { ...pending, targetSessionId: state.sessionId ?? undefined },
});
}
@@ -363,7 +370,7 @@ export class SessionEditorPanelProvider {
void entry.panel.webview.postMessage({
type: 'command',
command: 'addLineComment',
payload,
payload: { ...payload, targetSessionId: entry.sessionId ?? undefined },
});
return entry.id;
}