fix(local-model): ask the launch guard before every start of an agent on the managed endpoint

Only the two session routes asked launchRefusalMessage(). The attach that
finds no pane, the respawn of a dead pane (a click on the tab, a respawn
start, the boot recovery), restartCli() and the reboot-restore rebuild
started an agent on the endpoint unasked. Session gains setLaunchGuard(),
asked right before a NEW agent process is started and never for an attach to
an agent that runs; WebServer.setupSessionListeners() sets it for every
session; a refusal is a LaunchRefusedError that never falls back to a direct
PTY. The reboot-restore route asks before it builds and skips the entry with
its own reason, left on offer.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-11-06 23:54:46 +01:00
1 parent fa978008d2
commit 3c4bb91d6f
7 files changed
+380 -2

No files matched your search

+11
View File
@@ -2194,6 +2194,17 @@ export class WebServer extends EventEmitter {
// First keep-warm evaluation: publishes the effective opt-in for the Session Options
// readout even before any cache report arrives.
void this.keepWarmService.schedule(session.id);
// Before every start of a NEW agent process the session asks this (a fresh pane, the
// respawn of a dead one, a restart in place; never an attach to an agent that runs).
// The model Codeman runs on this Mac is the one endpoint with something to say: no agent
// is started on it while its runtime is down or its model is not the one that was
// installed. Every other session, and every other endpoint, is answered `undefined`.
// Set on every call, above the idempotency return: it holds no state of its own.
session.setLaunchGuard(async () => {
const selection = session.customModel;
if (!selection) return undefined;
return getLocalModelService().launchRefusalMessage(selection.endpointId, selection.modelId);
});
// Idempotent: the wiring exit handler detaches ALL listeners on every PTY exit
// (removeSessionListenerRefs), so the re-attach routes (/interactive,
// /interactive-respawn, /shell) call this again to restore observability