probe: weekly timer, and only dead lanes fail the unit

- handoff-probe.service + .timer (Mon 08:00, persistent) run free-agent --probe
  and append to ~/.local/state/free-agent/probe.log.
- probe now separates BUSY (429, quota, empty reply) from DEAD (retired slug,
  dead key, broken template); only DEAD fails the unit, so a weekly red status
  means the pool needs an edit rather than a provider being momentarily full.
This commit is contained in:
Ziad Arafat committed 2026-11-28 21:52:16 -07:00
1 parent 8d719140ba
commit 710b5f59cb
2 files changed
+41 -5

No files matched your search

+17 -5
View File
@@ -116,13 +116,25 @@ if (opts.probe) {
const code = await proc.exited;
clearTimeout(timer);
const out = o + e;
const ok = code === 0 && /\bOK\b/.test(o);
const why = ok ? "" : (out.match(/"message"\s*:\s*"([^"]{0,80})/)?.[1] || out.replace(/\s+/g, " ").slice(0, 80));
return { id: m.id, ok, ms: Date.now() - t0, why };
// A completed turn is healthy even if the model answered in prose instead of "OK".
const ok = code === 0;
// Permanent failures are the ones that mean "edit the pool": retired slug, dead
// key, broken chat template. Everything else (429, empty output, timeouts) is a
// quota/timing wall that clears on its own.
const dead = !ok && /404|not found|no longer available|unknown model|invalid model|template|401|403|invalid.*(api )?key/i.test(out);
const why = ok ? "" : (out.match(/"message"\s*:\s*"([^"]{0,90})/)?.[1] || out.replace(/\s+/g, " ").trim().slice(0, 90) || "no output");
return { id: m.id, ok, dead, busy: !ok && !dead, ms: Date.now() - t0, why };
})
);
for (const r of res) console.log(`${r.ok ? "OK " : "DEAD"} ${r.id.padEnd(50)} ${String(r.ms).padStart(6)}ms ${r.why}`);
process.exit(res.some((r) => r.ok) ? 0 : 1);
for (const r of res) {
const tag = r.ok ? "OK " : r.dead ? "DEAD" : "BUSY";
console.log(`${tag} ${r.id.padEnd(50)} ${String(r.ms).padStart(6)}ms ${r.why}`);
}
const dead = res.filter((r) => r.dead);
console.log(`\n${res.filter((r) => r.ok).length} ok, ${res.filter((r) => r.busy).length} busy, ${dead.length} dead${dead.length ? ": " + dead.map((d) => d.id).join(", ") : ""}`);
// Non-zero only for lanes that will not come back by themselves, so the weekly
// timer raises its hand exactly when the pool needs an edit.
process.exit(dead.length ? 1 : 0);
}
if (opts.list) {
+24
View File
@@ -82,6 +82,30 @@ in
Install.WantedBy = [ "default.target" ];
};
# Free lanes rot: OpenRouter retires :free slugs and providers change limits.
# A weekly probe writes the result to probe.log and fails the unit when a lane
# is dead, so "systemctl --user --failed" is the reminder instead of a surprise.
systemd.user.services.handoff-probe = {
Unit = { Description = "Probe every free-model lane in the handoff pool"; };
Service = {
Type = "oneshot";
ExecStart = "${config.home.homeDirectory}/.dotfiles/bin/free-agent --probe";
StandardOutput = "append:${config.home.homeDirectory}/.local/state/free-agent/probe.log";
StandardError = "append:${config.home.homeDirectory}/.local/state/free-agent/probe.log";
Environment = "PATH=${config.home.homeDirectory}/.dotfiles/bin:${config.home.homeDirectory}/.nix-profile/bin:${config.home.homeDirectory}/.local/bin:${config.home.homeDirectory}/.local/share/mise/shims:/run/current-system/sw/bin:/usr/bin:/bin";
};
};
systemd.user.timers.handoff-probe = {
Unit = { Description = "Weekly free-model lane probe"; };
Timer = {
OnCalendar = "Mon 08:00";
Persistent = true;
RandomizedDelaySec = 900;
};
Install.WantedBy = [ "timers.target" ];
};
# MCP servers carry tokens, so they are rendered from config/*/mcp*.json templates
# plus ~/.config/dotfiles/secrets.env by `dot secrets render` (never committed).
}