From 653d679dbc8d48ba5de9185242a4aa9f05c2624e Mon Sep 17 00:00:00 2001 From: Ziad Arafat Date: Sun, 29 Nov 2026 00:36:18 -0700 Subject: [PATCH] doctor: check the handoff pipeline; tests cover it end to end dot doctor gains four checks (daemon active, weekly probe timer scheduled, every pool lane usage=developer-api via the new bin/handoff-pool-check, and the pool readable by free-agent), so a dead daemon or an expired lane stops being invisible. tests/handoff.sh grows two checks for those and becomes hermetic: its daemon test runs in a private HANDOFF_TMUX session and points every brief at a path that does not exist, because a first version started a real worker inside the live session and spent a call. The doctor assertion captures the output instead of piping into grep -q, which with pipefail fails on SIGPIPE once the match is found. --- bin/dot | 7 +++++++ bin/handoff-pool-check | 25 +++++++++++++++++++++++++ tests/handoff.sh | 23 +++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100755 bin/handoff-pool-check diff --git a/bin/dot b/bin/dot index 057ff7e..c15d58c 100755 --- a/bin/dot +++ b/bin/dot @@ -727,6 +727,13 @@ cmd_doctor() { chk "konsole-daynight service" "systemctl --user is-active konsole-daynight" "dot switch, then log in to Plasma" chk "daynight-hooks service" "systemctl --user is-active daynight-hooks" "dot switch, then log in to Plasma" if ! in_container; then chk "netbird daemon" "systemctl is-active netbird" "dot system --netbird"; fi + + # Free-model handoff pipeline: a dead daemon or an off-policy lane stays invisible + # until someone tries to delegate, so check it here. + chk "handoff daemon" "systemctl --user is-active handoff.service" "systemctl --user start handoff" + chk "handoff probe timer" "systemctl --user list-timers handoff-probe.timer --no-pager | grep -q handoff-probe.timer" "systemctl --user start handoff-probe.timer" + chk "handoff pool policy" "handoff-pool-check" "edit config/free-agent/pool.json: every lane needs usage=developer-api" + chk "handoff pool alive" "free-agent --list >/dev/null" "free-agent --list" else chk "day/night daemons (XDG autostart)" "pgrep -f daynight-hooks" "log in to Plasma" fi diff --git a/bin/handoff-pool-check b/bin/handoff-pool-check new file mode 100755 index 0000000..f350948 --- /dev/null +++ b/bin/handoff-pool-check @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Fail when a pool lane is not a developer API. Called by `dot doctor`. +# +# handoff-pool-check [pool.json] +# +# Exit 0 = every lane is delegable, 1 = at least one is not, 2 = unreadable pool. +set -uo pipefail + +pool="${1:-${HOME}/.config/free-agent/pool.json}" +python3 - "$pool" <<'PY' +import json, sys +path = sys.argv[1] +try: + models = json.load(open(path)).get("models", []) +except Exception as exc: + print(f"handoff-pool-check: cannot read {path}: {exc}", file=sys.stderr) + sys.exit(2) +bad = [m.get("id", "?") for m in models if m.get("usage") != "developer-api"] +if bad: + print("handoff-pool-check: not a developer API: " + ", ".join(bad), file=sys.stderr) + sys.exit(1) +if not models: + print(f"handoff-pool-check: pool is empty ({path})", file=sys.stderr) + sys.exit(2) +PY diff --git a/tests/handoff.sh b/tests/handoff.sh index fe7c70c..02d9856 100755 --- a/tests/handoff.sh +++ b/tests/handoff.sh @@ -65,6 +65,14 @@ ok "submit stores a non-default role" # ---------------------------------------------------------------- orphan detection mkdir -p "$XDG_DATA_HOME/handoff/running" +# Nothing in this file may reach a provider: point the brief at a path that does not +# exist, so a task that gets started fails on validation instead of calling a model. +python3 - "$task" "$tmp/missing-brief.md" <<'PY' +import json, sys +path, missing = sys.argv[1:3] +d = json.load(open(path)); d["brief"] = missing +json.dump(d, open(path, "w")) +PY mv "$task" "$XDG_DATA_HOME/handoff/running/t-good.json" line="$(handoff list | grep 't-good')" grep -q '^orphan' <<<"$line" || fail "a running task with no window is not reported as orphan (got: $line)" @@ -76,7 +84,11 @@ cat > "$XDG_DATA_HOME/handoff/running/t-lost.json" <"$tmp/daemon.log" 2>&1 || true +tmux kill-session -t "$HANDOFF_TMUX" 2>/dev/null || true +unset HANDOFF_TMUX grep -q "requeued orphan t-lost" "$tmp/daemon.log" || fail "the daemon did not requeue the orphan (log: $(tail -3 "$tmp/daemon.log"))" ok "the daemon requeues an orphan instead of leaving it running" @@ -112,4 +124,15 @@ handoff pause >/dev/null && [ -f "$XDG_DATA_HOME/handoff/pause" ] || fail "pause handoff resume >/dev/null && [ ! -f "$XDG_DATA_HOME/handoff/pause" ] || fail "resume did not clear its marker" ok "pause and resume manage the daemon marker" +# doctor must report the pipeline, not just its handlers +doc="$(./bin/dot doctor 2>/dev/null)" +grep -q 'handoff pool policy' <<<"$doc" || fail "dot doctor has no handoff checks (lines: $(wc -l <<<"$doc"), tail: $(tail -2 <<<"$doc" | tr '\n' ' '))" +ok "dot doctor reports the handoff pipeline" + +# the pool checker must reject a lane that is not a developer API +out="$(handoff-pool-check "$tmp/pool-consumer.json" 2>&1)" && fail "handoff-pool-check accepted a consumer lane" +grep -q "consumer/app" <<<"$out" || fail "handoff-pool-check did not name the offending lane" +handoff-pool-check "$tmp/pool-ok.json" || fail "handoff-pool-check rejected a good pool" +ok "handoff-pool-check passes a clean pool and names a bad lane" + printf '\nHandoff pipeline checks passed\n'