fix(vscode): cancel activity watcher retries on stop (#1194)
Co-authored-by: Isaac Sanchez <isanchez-hawkins@arize.com>
This commit is contained in:
committed by
GitHub
co-authored by
Isaac Sanchez
parent
f7c5144c62
commit
736e33ab67
@@ -15,6 +15,16 @@ const SESSION_COOLDOWN_DURATION_MS = 2000;
|
|||||||
|
|
||||||
let globalEventWatcherAbortController: AbortController | null = null;
|
let globalEventWatcherAbortController: AbortController | null = null;
|
||||||
let chatViewProvider: { postMessage: (message: unknown) => void } | null = null;
|
let chatViewProvider: { postMessage: (message: unknown) => void } | null = null;
|
||||||
|
let globalEventWatcherRetryTimer: NodeJS.Timeout | null = null;
|
||||||
|
let globalEventWatcherStartToken = 0;
|
||||||
|
|
||||||
|
const clearGlobalEventWatcherRetry = (): void => {
|
||||||
|
if (!globalEventWatcherRetryTimer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
clearTimeout(globalEventWatcherRetryTimer);
|
||||||
|
globalEventWatcherRetryTimer = null;
|
||||||
|
};
|
||||||
|
|
||||||
const reconcileSessionActivityFromStatus = async (manager: OpenCodeManager): Promise<void> => {
|
const reconcileSessionActivityFromStatus = async (manager: OpenCodeManager): Promise<void> => {
|
||||||
const baseUrl = manager.getApiUrl();
|
const baseUrl = manager.getApiUrl();
|
||||||
@@ -171,12 +181,22 @@ export const startGlobalEventWatcher = async (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const startToken = ++globalEventWatcherStartToken;
|
||||||
|
clearGlobalEventWatcherRetry();
|
||||||
chatViewProvider = provider;
|
chatViewProvider = provider;
|
||||||
|
|
||||||
const port = await waitForOpenCodePort(manager);
|
const port = await waitForOpenCodePort(manager);
|
||||||
|
if (startToken !== globalEventWatcherStartToken) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!port) {
|
if (!port) {
|
||||||
console.warn('[VSCode:Activity] OpenCode port unavailable; will retry');
|
console.warn('[VSCode:Activity] OpenCode port unavailable; will retry');
|
||||||
setTimeout(() => startGlobalEventWatcher(manager, provider), 2000);
|
globalEventWatcherRetryTimer = setTimeout(() => {
|
||||||
|
globalEventWatcherRetryTimer = null;
|
||||||
|
if (startToken === globalEventWatcherStartToken) {
|
||||||
|
void startGlobalEventWatcher(manager, provider);
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,13 +266,15 @@ export const startGlobalEventWatcher = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const stopGlobalEventWatcher = (): void => {
|
export const stopGlobalEventWatcher = (): void => {
|
||||||
if (!globalEventWatcherAbortController) {
|
globalEventWatcherStartToken += 1;
|
||||||
return;
|
clearGlobalEventWatcherRetry();
|
||||||
}
|
|
||||||
try {
|
if (globalEventWatcherAbortController) {
|
||||||
globalEventWatcherAbortController.abort();
|
try {
|
||||||
} catch {
|
globalEventWatcherAbortController.abort();
|
||||||
// ignore
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
globalEventWatcherAbortController = null;
|
globalEventWatcherAbortController = null;
|
||||||
chatViewProvider = null;
|
chatViewProvider = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user