fix(home): decide() respects the status field — symmetry with cloud auto-inject gate

27f31cb introduced the agent-driven status field as the gate for the
cloud /control auto-inject. The home/ Brain's decide() function read
lastHandoff.health but not lastHandoff.status — meaning the home/
stack's autonomous dispatches (autonomy=auto, autonomy=sleep) would
fire on a project whose agent said status=working, contradicting the
cloud's behavior.

shouldAutoExecute now takes a status parameter (defaults to '' for
back-compat with any external callers). When autonomy is non-manual
AND status is anything other than 'ready' (including empty, missing,
or 'working'), it returns false — same strict semantics as the cloud
gate in src/hooks/use-project-card-actions.ts and BeaconClient.tsx.
Manual mode bypasses (user click is the gate).

decide() pulls status from project.lastHandoff?.status and threads it
to all four shouldAutoExecute call sites (the recovery branch, the
queue-head branch, and the next_best branch — caught one I missed on
the first pass by re-running tests).

home/decide tests: 14/14 (was 11) — three new cases:
  • sleep mode does NOT fire when status='working'
  • auto mode does NOT fire when status is missing
  • manual mode ignores status (user click IS the gate)
Plus an update to the existing 'sleep auto-fires on high confidence'
fixture to include status: 'ready' (otherwise it'd fail the new
gate). All eight home/ suites: 85/85 total (was 82).

tsc clean, eslint clean.
This commit is contained in:
g-but committed 2026-05-20 10:17:43 +02:00
1 parent e332f37e26
commit b51fa18cbf
1 file changed
+50 -6
+50 -6
View File
@@ -101,11 +101,19 @@ export function shouldAutoExecute(
autonomy: Autonomy,
confidence: number,
health: string,
status: string = "",
): boolean {
// Critical health blocks autoExecute in every mode except manual (which is
// already false). The brain must surface a recovery prompt, not bury it
// under sleep-mode autonomy.
if (health.toLowerCase().includes("critical")) return false;
// Agent-driven gate: autonomous dispatches (auto, sleep) only fire when
// the latest handoff EXPLICITLY signals status="ready". Missing, empty,
// "working", or any other value suppresses. Manual mode bypasses — user
// clicked Dispatch explicitly, they ARE the gate. Mirrors the cloud
// /control auto-inject gate from 27f31cb (handleAutoInject) so home/ and
// cloud agree on when to fire.
if (autonomy !== "manual" && status.toLowerCase() !== "ready") return false;
return confidence >= AUTONOMY_THRESHOLD[autonomy];
}
@@ -134,6 +142,7 @@ export function decide(input: DecideInput): Decision {
const { project, queueHead, autonomy = "confirm" } = input;
const confidence = computeConfidence(project.recentOutcomes);
const health = project.lastHandoff?.health ?? "";
const status = project.lastHandoff?.status ?? "";
// 1. If a run is currently active, decide() has nothing to do — let it
// finish. The next call after worker.finished will produce the next move.
@@ -153,7 +162,7 @@ export function decide(input: DecideInput): Decision {
return {
action: { kind: "recovery", intent: recovery.intent, reason: recovery.reason },
confidence,
autoExecute: shouldAutoExecute(autonomy, confidence, health),
autoExecute: shouldAutoExecute(autonomy, confidence, health, status),
};
}
@@ -171,7 +180,7 @@ export function decide(input: DecideInput): Decision {
reason: "Draining queue head.",
},
confidence,
autoExecute: shouldAutoExecute(autonomy, confidence, health),
autoExecute: shouldAutoExecute(autonomy, confidence, health, status),
};
}
@@ -183,7 +192,7 @@ export function decide(input: DecideInput): Decision {
reason: "Queue empty, health good — let the agent pick next.",
},
confidence,
autoExecute: shouldAutoExecute(autonomy, confidence, health),
autoExecute: shouldAutoExecute(autonomy, confidence, health, status),
};
}
@@ -278,16 +287,51 @@ function selfTest() {
expect: (d) => !d.autoExecute,
},
{
name: "sleep mode auto-fires on high confidence + healthy",
name: "sleep mode auto-fires on high confidence + healthy + status=ready",
input: {
project: {
...baseProject,
recentOutcomes: ["success", "success", "success", "success", "success"],
lastHandoff: { status: "ready", done:"x", next: "", tests: "all pass", todos: "0", health: "good" },
},
autonomy: "sleep",
},
expect: (d) => d.autoExecute && d.confidence > 0.75,
},
{
name: "sleep mode does NOT fire when status='working' (mirrors cloud auto-inject gate)",
input: {
project: {
...baseProject,
recentOutcomes: ["success", "success", "success", "success", "success"],
lastHandoff: { status: "working", done:"x", next: "more to do", tests: "all pass", todos: "0", health: "good" },
},
autonomy: "sleep",
},
expect: (d) => !d.autoExecute,
},
{
name: "auto mode does NOT fire when status is missing (default-suppress)",
input: {
project: {
...baseProject,
recentOutcomes: ["success", "success", "success", "success", "success"],
lastHandoff: { status: "", done:"x", next: "", tests: "all pass", todos: "0", health: "good" },
},
autonomy: "sleep",
autonomy: "auto",
},
expect: (d) => d.autoExecute && d.confidence > 0.75,
expect: (d) => !d.autoExecute,
},
{
name: "manual mode ignores status (user clicked Dispatch, they ARE the gate)",
input: {
project: {
...baseProject,
lastHandoff: { status: "working", done:"x", next: "more to do", tests: "all pass", todos: "0", health: "good" },
},
autonomy: "manual",
},
expect: (d) => d.autoExecute,
},
{
name: "sleep mode holds when recent errors drop confidence",