Item 2: session start never argues against delegating on missing data. done / next: item 3 route with providers down

This commit is contained in:
swaits committed 2026-11-23 12:25:25 -07:00
1 parent e875ac9a7f
commit 1208df9b1b
3 files changed
+63 -35

No files matched your search

+34 -33
View File
@@ -712,8 +712,8 @@ def facts_line(now=None):
return ("sisi: %s: ask a fast, cheap worker to research current prices and " return ("sisi: %s: ask a fast, cheap worker to research current prices and "
"software-engineering benchmark standing for the workers found here (`sisi workers`) " "software-engineering benchmark standing for the workers found here (`sisi workers`) "
"and record each with its source: `sisi workers fact WORKER --price N --source S` " "and record each with its source: `sisi workers fact WORKER --price N --source S` "
"and `sisi workers fact WORKER --score N --source S`. Until then routing has no " "and `sisi workers fact WORKER --score N --source S`. Until then routing "
"price or prior to go on." % what) "goes by the judged record alone." % what)
def estimate_cost(tokens, price_entry): def estimate_cost(tokens, price_entry):
@@ -1105,9 +1105,7 @@ def strength_scores(candidates, records):
def _cached_candidates(records=None): def _cached_candidates(records=None):
"""Candidates from the discovery cache only: session start must stay fast and run no tool.""" """Candidates from the discovery cache only: session start must stay fast and run no tool."""
cached = load_discovery() cached = load_discovery()
if not cached.get("tools"): return build_candidates(cached, read_records() if records is None else records), cached.get("tools") or []
return [], []
return build_candidates(cached, read_records() if records is None else records), cached["tools"]
def is_subagent_payload(payload): def is_subagent_payload(payload):
@@ -1127,44 +1125,47 @@ def _with_facts(lines):
def session_lines(model, payload=None): def session_lines(model, payload=None):
"""One or two plain lines at session start about delegating (plus one asking for worker """Plain lines at session start about delegating, or nothing for a session another agent
facts when they are missing or stale), or nothing for a session another agent started. started. When the main model's standing is unknown it says nothing about whether to delegate:
Uses only cached discovery and the record.""" a missing number never argues against orchestrating. At most one extra line asks for worker
facts to be researched when they are missing or stale (the caller shows these lines once per
session). Uses only cached discovery and the record."""
if not model or is_subagent_payload(payload or {}): if not model or is_subagent_payload(payload or {}):
return [] return []
records = read_records() records = read_records()
candidates, _tools = _cached_candidates(records) candidates, _tools = _cached_candidates(records)
waiting = len(unjudged_runs(records)) waiting = len(unjudged_runs(records))
suffix = "" suffix = ""
if waiting: if waiting == 1:
suffix = " %d delegation%s waiting for a judgement: run `sisi workers` to see, then `sisi delegate judge`." \ suffix = " One delegation is waiting for a judgement: run `sisi workers`, then `sisi delegate judge`."
% (waiting, " is" if waiting == 1 else "s are") elif waiting:
if waiting == 1: suffix = " %d delegations are waiting for a judgement: run `sisi workers` to see, then `sisi delegate judge`." % waiting
suffix = " One delegation is waiting for a judgement: run `sisi workers`, then `sisi delegate judge`." scores = strength_scores(candidates, records) if candidates else {}
if not candidates: cand = resolve_worker(model, candidates) if candidates else None
return _with_facts(["sisi: the strength of this session's model (%s) is unknown here: no workers have been "
"discovered yet (`sisi workers` finds them), so do the work yourself for now.%s" % (model, suffix)])
cand = resolve_worker(model, candidates)
scores = strength_scores(candidates, records)
own = scores.get(cand["worker"]) if cand else None own = scores.get(cand["worker"]) if cand else None
if own is None and cand is None: if own is None:
prior = load_strength_prior().get(model) prior = load_strength_prior().get(model)
if isinstance(prior, dict) and isinstance(prior.get("score"), (int, float)): if isinstance(prior, dict) and isinstance(prior.get("score"), (int, float)):
own = (float(prior["score"]), "stored prior (%s, %s)" % (prior.get("source") or "no source stated", own = (float(prior["score"]), "stored prior (%s, %s)" % (prior.get("source") or "no source stated",
prior.get("date") or "no date stated")) prior.get("date") or "no date stated"))
if own is None: lines = []
return _with_facts(["sisi: the strength of this session's model (%s) is unknown here (no stored prior and no " if own is not None:
"measured record yet), so do the work yourself rather than delegating on a guess.%s" best_score = max([s for s, _h in scores.values()] + [own[0]])
% (model, suffix)]) if own[0] >= best_score - routing.STRONG_BAND:
best_worker, (best_score, _how) = max(scores.items(), key=lambda kv: kv[1][0]) if scores else (None, (own[0], "")) lines.append("sisi: this session's model (%s) is among the strongest available here (%s): plan, ask `sisi route` who "
if own[0] >= best_score - routing.STRONG_BAND: "should do each piece, start that worker with this tool's own subagents (use `sisi delegate` "
return _with_facts(["sisi: this session's model (%s) is among the strongest available here (%s): plan, ask `sisi route` who " "only if it has none), and judge what comes back.%s" % (model, own[1], suffix))
"should do each piece, start that worker with this tool's own subagents (use `sisi delegate` " else:
"only if it has none), and judge what comes back.%s" % (model, own[1], suffix)]) stronger = [w for w, _s in sorted(scores.items(), key=lambda kv: -kv[1][0])[:3] if scores[w][0] > own[0]]
return _with_facts(["sisi: this session's model (%s) is not among the strongest available here (%s): do the work " lines.append("sisi: this session's model (%s) stands at %g (%s)%s. Ask `sisi route` who should do each piece, "
"yourself rather than delegating. Stronger models are available here, strongest first: %s.%s" "start that worker with this tool's own subagents (use `sisi delegate` only if it has none), "
% (model, own[1], ", ".join(w for w, _s in sorted(scores.items(), key=lambda kv: -kv[1][0])[:3] "and judge what comes back.%s"
if scores[w][0] > own[0]), suffix)]) % (model, own[0], own[1],
("; stronger models available here, strongest first: %s" % ", ".join(stronger)) if stronger else "",
suffix))
elif suffix:
lines.append("sisi:" + suffix)
return _with_facts(lines)
# ---------------------------------------------------------------- commands # ---------------------------------------------------------------- commands
@@ -1333,7 +1334,7 @@ def cmd_route(args=()):
"are not candidates" % excluded) "are not candidates" % excluded)
if cold: if cold:
print("cold start: no worker here has a judged record, a known price or a benchmark " print("cold start: no worker here has a judged record, a known price or a benchmark "
"prior yet, so this pick is a trial, not a recommendation from evidence. " "prior yet, so nothing is known yet about this pick. "
"Judge its result (`sisi delegate judge`) and record worker facts " "Judge its result (`sisi delegate judge`) and record worker facts "
"(`sisi workers fact`) so the next choice has something to go on.") "(`sisi workers fact`) so the next choice has something to go on.")
line = facts_line() line = facts_line()
+27
View File
@@ -78,5 +78,32 @@ class HostNativeTests(RouteCase):
self.assertNotIn("wk-", r.stdout.splitlines()[0]) self.assertNotIn("wk-", r.stdout.splitlines()[0])
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,
"model": model}))
def test_unknown_standing_says_nothing_about_delegating(self):
"""R-7.1-1, R-17-3: with no facts and an unknown main model, session start argues
neither for nor against delegating; at most one line asks for facts, once per session."""
r = self.tick("s-unk")
self.assertEqual(r.returncode, 0, r.stderr)
low = r.stdout.lower()
for bad in ("yourself", "rather than delegating", "on a guess", "do the work"):
self.assertNotIn(bad, low)
sisi_lines = [l for l in r.stdout.splitlines() if "worker facts" in l]
self.assertEqual(len(sisi_lines), 1, r.stdout)
again = self.tick("s-unk", source="resume")
self.assertNotIn("worker facts", again.stdout)
def test_unknown_standing_with_a_recorded_ledger(self):
"""The same holds with a thick ledger and no discovered tools."""
self.seed_real_shape()
r = self.sisi("tick", stdin=json.dumps({"session_id": "s-led", "cwd": self.proj, "source": "startup",
"model": "mystery-9"}), env=dict(PATH=""))
self.assertNotIn("yourself", r.stdout.lower())
self.assertNotIn("rather than", r.stdout.lower())
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
+2 -2
View File
@@ -214,7 +214,7 @@ class SessionModelTests(WorkerCase):
def test_tick_weak_line_names_stronger(self): def test_tick_weak_line_names_stronger(self):
self.seed_strength({"beta-1": 95, "alpha-1": 60}) self.seed_strength({"beta-1": 95, "alpha-1": 60})
r = self.tick({"session_id": "weak-1", "cwd": self.proj, "source": "startup", "model": "alpha-1"}) r = self.tick({"session_id": "weak-1", "cwd": self.proj, "source": "startup", "model": "alpha-1"})
self.assertIn("do the work yourself", r.stdout) self.assertNotIn("do the work yourself", r.stdout) # a lower standing never argues against orchestrating
self.assertIn("beta-1", r.stdout) self.assertIn("beta-1", r.stdout)
def test_tick_subagent_gets_no_delegation_line(self): def test_tick_subagent_gets_no_delegation_line(self):
@@ -226,7 +226,7 @@ class SessionModelTests(WorkerCase):
def test_tick_unknown_strength_says_so(self): def test_tick_unknown_strength_says_so(self):
r = self.tick({"session_id": "unk-1", "cwd": self.proj, "source": "startup", "model": "mystery-9"}) r = self.tick({"session_id": "unk-1", "cwd": self.proj, "source": "startup", "model": "mystery-9"})
self.assertIn("unknown", r.stdout.lower()) self.assertNotIn("yourself", r.stdout.lower()) # unknown standing says nothing about delegating
class RoutingPropertyTests(unittest.TestCase): class RoutingPropertyTests(unittest.TestCase):