Forget the old console on a project switch, so its end never covers what shows next

AI Assisted
This commit is contained in:
Seth committed 2026-12-05 00:10:45 -08:00
1 parent 59d226c2a6
commit 8b5932c351
2 files changed
+56 -2

No files matched your search

+31 -2
View File
@@ -972,6 +972,29 @@ let helloTimer = null;
// Nothing has shown here yet: no agent has opened the dashboard. No polling,
// no "reconnect" button makes sense until that first page lands.
let consoleKnown = false;
// Which console the checks below ask about. A project switch moves it on, so
// an answer that comes back afterward is about a console that is gone.
let consoleEpoch = 0;
// The project moved on, and its console was stopped on purpose: nothing is
// known here again until the new agent opens a page. Left known, the next
// poll found no console and put "The console stopped" over the new agent's
// start, or the launch card; left in the frame, the old page showed its "Lost
// contact" around it.
function forgetConsole() {
consoleEpoch += 1;
consoleKnown = false;
clearInterval(pollTimer);
pollTimer = null;
clearTimeout(helloTimer);
currentUrl = null;
frameReady = false;
// As for any page going away (loadFrame): its taskbar dot and its game go too.
clearAttention();
setGameFull(false);
frame.src = 'about:blank';
markConsoleAlive();
}
function loadFrame(url) {
currentUrl = url;
@@ -1252,6 +1275,7 @@ setWindowTheme(document.documentElement.getAttribute('data-theme') === 'light' ?
// No hello in time: ask the console why, and say so with a way forward.
async function onNoHello() {
if (frameReady || !consoleKnown || restarting) return;
const epoch = consoleEpoch;
// A page that does not answer cannot say it is done needing the person.
clearAttention();
// The next phase's console is on its way; the poll says so instead. Look
@@ -1267,6 +1291,7 @@ async function onNoHello() {
} catch {
// The status check itself failed; treat it as a console that is not answering.
}
if (epoch !== consoleEpoch) return;
if (!status || status.state !== 'running') {
showState('The console stopped, so the page could not show.', 'Reconnect the console', reconnectConsole);
} else {
@@ -1434,12 +1459,15 @@ let pollTimer = null;
// on its own session. The app never opens a dashboard on its own (the agent
// does, by running the skill), so there is nothing to start before that.
async function reconnectConsole() {
const epoch = consoleEpoch;
markConsoleAlive();
showState('Reconnecting to the console...');
try {
const info = await invoke('console_start');
if (epoch !== consoleEpoch) return;
loadFrame(info.url);
} catch (error) {
if (epoch !== consoleEpoch) return;
showErrorState(error, 'reach the console', 'Retry', reconnectConsole);
// An old console cannot be framed: the fix is the skills update, so offer it.
if (String(error).includes('too old')) setVersionState({ kind: 'too-old' });
@@ -1453,8 +1481,10 @@ const RECONNECT_LIMIT = 3;
let reconnects = 0;
async function pollConsole() {
const epoch = consoleEpoch;
try {
const status = await invoke('console_status');
if (epoch !== consoleEpoch) return;
if (status.state === 'running') {
markConsoleAlive();
return;
@@ -2115,8 +2145,7 @@ async function doChangeProject(prior = null) {
setProjectDir(dir);
if (appState) appState.projectDir = dir;
restarting = false;
currentUrl = null;
frameReady = false;
forgetConsole();
// An agent was in use: start the same one (agent, model, effort and
// permission mode) in the new folder, rather than leaving the launch card
// and an empty terminal. Nothing to carry over: the launch card as before.