Item 3: route recommends a host worker while providers are down, and says what is down and what to do. done / next: item 4 worker notes

This commit is contained in:
swaits committed 2026-11-23 12:26:10 -07:00
1 parent 1208df9b1b
commit 3307fadee3
3 files changed
+55

No files matched your search

+2
View File
@@ -221,6 +221,8 @@ def choose(candidates, records, availability, kind, difficulty, review_of=None,
def load_ratio(c):
left = c.get("allowance_pct_left")
if left is None and c.get("host_native"):
return 0.0 # a host worker has no allowance to spread work across: the record decides
weight = float(left) if left else UNKNOWN_ALLOWANCE
return stats.get(c["worker"], {}).get("uses", 0) / max(weight, 1.0)
+24
View File
@@ -1291,6 +1291,22 @@ def cmd_workers(args=()):
return 0
def _down_now(avail, now):
"""[(key, entry)] for every provider or worker marked down whose retry time is still ahead."""
return [(k, v) for k, v in sorted((avail or {}).items())
if isinstance(v, dict) and float(v.get("retry_at") or 0) > now]
def _down_lines(down, limit=3):
"""One line naming what is down and when each is due for another try, or nothing."""
if not down:
return []
shown = ["%s (%s, next try %s)" % (k, v.get("reason") or "down", _when(v.get("retry_at")))
for k, v in down[:limit]]
more = " and %d more" % (len(down) - limit) if len(down) > limit else ""
return ["down now: %s%s" % ("; ".join(shown), more)]
def _route_setup(args):
ensure_imported()
kind = _opt(args, "--kind")
@@ -1318,14 +1334,22 @@ def cmd_route(args=()):
result = routing.choose(candidates, records, read_availability(), kind, difficulty,
review_of=_opt(args, "--review-of"), now=time.time(),
avoid=prefs["avoid"], prefer=prefs["prefer"])
down = _down_now(read_availability(), time.time())
if result["choice"] is None:
print("no usable worker for kind %s at difficulty %d" % (kind, difficulty))
for line in _down_lines(down):
print(line)
print("nothing is usable right now: the main agent does this task itself meanwhile, "
"and tries `sisi route` again after the next-try time above%s."
% ("" if down else " or once a worker is recorded or fixed (`sisi workers`)"))
if "--explain" in args:
for line in routing.explain_choice(result, kind, difficulty)[1:]:
print(line)
return 1
print(result["choice"]["worker"])
print("mechanism: %s" % mechanism_for(result["choice"]))
for line in _down_lines(down):
print(line)
if "--explain" in args:
for line in routing.explain_choice(result, kind, difficulty):
print(line)
+29
View File
@@ -78,6 +78,35 @@ class HostNativeTests(RouteCase):
self.assertNotIn("wk-", r.stdout.splitlines()[0])
class DownProvidersTests(RouteCase):
def test_host_worker_recommended_while_providers_are_down(self):
"""R-7.2-1, R-7.2-3, R-17-5: every provider down, a record exists: route still names the best
host worker, says which providers are down and when each is due, and gives the mechanism."""
self.seed_real_shape()
self.down("muse", "codex")
r = self.sisi("route", "--kind", "impl", "--difficulty", "2", env=self.env())
self.assertEqual(r.returncode, 0, r.stdout)
lines = r.stdout.splitlines()
self.assertTrue(lines[0].startswith("wk-"), r.stdout)
self.assertIn("host's own subagent tool", r.stdout)
down = [l for l in lines if l.startswith("down now")]
self.assertEqual(len(down), 1, r.stdout)
self.assertIn("muse", down[0])
self.assertIn("codex", down[0])
self.assertIn("2099-01-02", down[0])
def test_nothing_usable_says_exactly_what_to_do(self):
"""R-7.2-3, R-17-5: only when nothing is usable does route say so, with providers, due times
and that the main agent does the task itself meanwhile."""
self.seed([("muse/beta-1", 12, 11), ("codex/alpha-1", 9, 8)])
self.down("muse", "codex")
r = self.sisi("route", "--kind", "impl", "--difficulty", "2", env=self.env())
self.assertEqual(r.returncode, 1)
self.assertIn("no usable worker", r.stdout)
self.assertIn("2099-01-02", r.stdout)
self.assertIn("main agent does this task itself", r.stdout)
class SessionStartTests(RouteCase):
def tick(self, sid, model="mystery-9", source="startup"):
return self.sisi("tick", stdin=json.dumps({"session_id": sid, "cwd": self.proj, "source": source,