mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 09:20:03 +01:00
fix(home): clean up runId sentinel on inject failure so it doesn't leak to later sessions
executeDispatch writes /tmp/<slug>-run-<tab> with the runId before
calling injectIntoTab so the stop hook can later read it and include
runId on worker.finished (fb6d5a0). On the happy path the sentinel is
consumed and deleted by finish_orchestration_run in the stop hook. On
the inject-failure path, no agent is running and no stop hook will
ever fire — so the sentinel sat in /tmp forever with the runId of a
dispatch that crashed at the wire.
The next manual claude launch in that tab would write a session.md
and trigger the stop hook, which reads the stale sentinel and tags an
unrelated worker.finished with our crashed runId. state.applyEvent
matches on runId for the cancelledRunIds → user_abort relabel, so a
stale match would also pollute confidence for the wrong run.
Added a fs.rmSync alongside the existing appendEvent worker.crashed
in the catch branch — symmetric with the dispatch-success path that
delegates cleanup to the stop hook chain. Wrapped in try/catch
because the sentinel write may have failed first (read-only /tmp,
weird FS), in which case there's nothing to clean up.
Worker self-tests still 12/12 (the cleanup happens in executeDispatch
which is I/O and not covered by the pure-function applyEvent suite —
manually verified the only behavior change is the cleanup path on
the catch branch). tsc clean.
This commit is contained in:
1 file changed
+9
@@ -171,6 +171,15 @@ function executeDispatch(state: WorkerState, event: Event) {
|
||||
runId: event.runId,
|
||||
error: `inject failed: ${msg}`,
|
||||
});
|
||||
// Inject failed → no agent is running → no stop hook will ever fire to
|
||||
// consume this sentinel. Without cleanup, the stale runId sits in /tmp
|
||||
// forever; the next manual claude session in this tab would write a
|
||||
// session.md, the stop hook would read this sentinel, and tag an
|
||||
// unrelated worker.finished with our crashed runId. Same trap that
|
||||
// motivated agent-hook-bridge.sh:finish_orchestration_run's rm — apply
|
||||
// it here too so the dispatch-fail path doesn't leak state.
|
||||
try { fs.rmSync(runSentinelPath(event.project), { force: true }); }
|
||||
catch { /* sentinel write may have failed too; nothing to clean up */ }
|
||||
console.error(`[worker] inject failed runId=${event.runId}: ${msg}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user