fix: a run started a moment ago is never judged dead — another dashboard's tmux list may predate it
Only the process that starts a pane writes it into its own cached tmux list (noteSession); a second dashboard on the same database (a dev server) holds a member list up to 15 s old, so its heal beat ended a Codex pane seconds after it started and the proxy gateway answered 401. reconcileOrphans and healRunId skip a run younger than 20 s (dashboard-runs.isYoungRun). Tests: dashboard-runs (young vs old).
This commit is contained in:
@@ -258,8 +258,21 @@ function claimToolSessions(sessionId = null) {
|
||||
}
|
||||
|
||||
const runningStmt = db.prepare(
|
||||
"SELECT id, tool, session_id, cwd FROM dashboard_runs WHERE status IN ('running', 'spawning')"
|
||||
"SELECT id, tool, session_id, cwd, started_at FROM dashboard_runs WHERE status IN ('running', 'spawning')"
|
||||
);
|
||||
|
||||
/**
|
||||
* How long a new run is never judged dead. A tmux list is a cached answer —
|
||||
* a member's may be up to 15 s old (tmux.js MEMBER_LIST_MAX_AGE_MS) — and only
|
||||
* the process that started a pane writes it into its own cache, so another
|
||||
* dashboard on the same database (a dev server) ended a pane it had simply
|
||||
* not listed yet: the proxy gateway then answered 401 to a live Codex.
|
||||
*/
|
||||
const YOUNG_RUN_MS = 20_000;
|
||||
function isYoungRun(startedAt, now = Date.now()) {
|
||||
const t = Date.parse(startedAt || "");
|
||||
return Number.isFinite(t) && now - t < YOUNG_RUN_MS;
|
||||
}
|
||||
const endStmt = db.prepare(`
|
||||
UPDATE dashboard_runs
|
||||
SET status = @status,
|
||||
@@ -300,7 +313,7 @@ function reconcileOrphans(isAlive = () => false) {
|
||||
let changes = 0;
|
||||
const { unseenMemberFolder } = require("./linux-accounts");
|
||||
for (const row of runningStmt.all()) {
|
||||
if (isAlive(row.id) || unseenMemberFolder(row.cwd)) continue;
|
||||
if (isAlive(row.id) || unseenMemberFolder(row.cwd) || isYoungRun(row.started_at)) continue;
|
||||
const interrupted =
|
||||
row.tool !== "shell" &&
|
||||
!!row.session_id &&
|
||||
@@ -368,6 +381,7 @@ module.exports = {
|
||||
getRun,
|
||||
forgetShellRun,
|
||||
reconcileOrphans,
|
||||
isYoungRun,
|
||||
listInterrupted,
|
||||
dismissInterrupted,
|
||||
proxyForSession,
|
||||
|
||||
Reference in New Issue
Block a user