Skip to content

Commit a0b8f59

Browse files
committed
feat: persist agentId across remote-authority reload
commands.open() triggers vscode.openFolder with a remote authority, which reloads the window and wipes in-memory state. To survive this, handleOpen now saves the agentId to globalState before the reload. After the reload, activate() reads and clears it once the deployment is configured, then opens the chat panel. This follows the same set-and-clear pattern used by firstConnect.
1 parent d9c8417 commit a0b8f59

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

src/core/mementoManager.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,28 @@ export class MementoManager {
5757
}
5858
return isFirst === true;
5959
}
60+
61+
/**
62+
* Store a chat agent ID to open after a window reload.
63+
* Used by the /open deep link handler: it must call
64+
* commands.open() which triggers a remote-authority
65+
* reload, wiping in-memory state. The agent ID is
66+
* persisted here so the extension can pick it up on
67+
* the other side of the reload.
68+
*/
69+
public async setPendingChatAgentId(agentId: string): Promise<void> {
70+
await this.memento.update("pendingChatAgentId", agentId);
71+
}
72+
73+
/**
74+
* Read and clear the pending chat agent ID. Returns
75+
* undefined if none was stored.
76+
*/
77+
public async getAndClearPendingChatAgentId(): Promise<string | undefined> {
78+
const agentId = this.memento.get<string>("pendingChatAgentId");
79+
if (agentId !== undefined) {
80+
await this.memento.update("pendingChatAgentId", undefined);
81+
}
82+
return agentId;
83+
}
6084
}

src/extension.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,15 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
336336
url: details.url,
337337
token: details.token,
338338
});
339+
340+
// If a deep link stored a chat agent ID before the
341+
// remote-authority reload, open it now that the
342+
// deployment is configured.
343+
const pendingAgentId =
344+
await mementoManager.getAndClearPendingChatAgentId();
345+
if (pendingAgentId) {
346+
chatPanelProvider.openChat(pendingAgentId);
347+
}
339348
}
340349
} catch (ex) {
341350
if (ex instanceof CertificateError) {

src/uri/uriHandler.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,7 @@ function getRequiredParam(params: URLSearchParams, name: string): string {
9191
}
9292

9393
async function handleOpen(ctx: UriRouteContext): Promise<void> {
94-
const {
95-
params,
96-
serviceContainer,
97-
deploymentManager,
98-
commands,
99-
chatPanelProvider,
100-
} = ctx;
94+
const { params, serviceContainer, deploymentManager, commands } = ctx;
10195

10296
const owner = getRequiredParam(params, "owner");
10397
const workspace = getRequiredParam(params, "workspace");
@@ -107,10 +101,14 @@ async function handleOpen(ctx: UriRouteContext): Promise<void> {
107101
params.has("openRecent") &&
108102
(!params.get("openRecent") || params.get("openRecent") === "true");
109103

110-
// Optional: if agentId is present, also open the embedded chat
111-
// panel. Old extensions silently ignore this unknown param,
112-
// giving backwards compatibility.
104+
// Persist the chat agent ID before commands.open() triggers
105+
// a remote-authority reload that wipes in-memory state.
106+
// The extension picks this up after the reload in activate().
113107
const agentId = params.get("agentId");
108+
if (agentId) {
109+
const mementoManager = serviceContainer.getMementoManager();
110+
await mementoManager.setPendingChatAgentId(agentId);
111+
}
114112

115113
await setupDeployment(params, serviceContainer, deploymentManager);
116114

@@ -121,10 +119,6 @@ async function handleOpen(ctx: UriRouteContext): Promise<void> {
121119
folder ?? undefined,
122120
openRecent,
123121
);
124-
125-
if (agentId) {
126-
chatPanelProvider.openChat(agentId);
127-
}
128122
}
129123

130124
async function handleOpenDevContainer(ctx: UriRouteContext): Promise<void> {

0 commit comments

Comments
 (0)