Files
loki/scripts/test
g-butandClaude Opus 4.7 b89fdfc9d2 fix(dispatch): gate autopilot on status:working + pending blockers
Live-incident regression. Earlier today the autopilot injected a
2000-char next_best template into the user's keystrokes mid-typing
while they were composing a message to the agent, producing garbled
text like "wtf ust happened? what is this injecSetup (run, read
outputs):...". The session handoff said status:working — which is
documented in three places as the suppression signal — but the
daemon fired anyway because nothing in the dispatch pipeline
actually read the status field.

Root cause: agent-hook-bridge.sh:autopilot_dispatch_and_inject()
extracted done/next/tests/todos/health from the session file but
not status. The dispatch route's HandoffSchema didn't include
status either. The user trusted a guarantee the code never made.

Three coordinated fixes:

1. agent-hook-bridge.sh now reads `status:` from the session file
   AND counts files in ~/.claude/sessions/<P>.blockers/pending/.
   Either condition (status:working OR blockerCount>0) causes the
   daemon to skip the dispatch HTTP call entirely — saves a network
   round-trip and surfaces the gate in daemon logs.

2. The dispatch route's HandoffSchema gains a `status` field and
   the body gains `blockerCount`. Defence-in-depth: even if a
   custom integration or cloud-only caller bypasses the daemon's
   client-side gate, the route refuses to act on a working status
   or pending blockers. Two new DispatchResult.source values
   (status_gate, blocker_gate) make these refusals greppable in
   logs.

3. The gate logic moves out of the route handler into a pure
   helper at src/lib/orchestration/dispatch-gates.ts so the
   invariants can be unit-tested without spinning up a real Next
   request. 11 inline tests cover: status:working wins over every
   mode; blockers beat happy-path; legacy empty status preserves
   existing permissive behavior; etc. Wired into
   `npm run test:dispatch-gates`.

Closes the highest-impact symptom of the strategist's broken trust
model. The user can now leave autopilot on and trust that their
status:working handoff actually stops it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-31 06:45:24 +02:00
..