From aa6c268f58cc2b84bf630fef812c5990d51fb90b Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Tue, 24 Nov 2026 13:41:03 -0700 Subject: [PATCH] Review fixes: the agent marker counts only at the very start of the first request; quick work is timed from its first request, and a failed check or a backwards clock still sends it to the retro --- README.md | 4 ++-- sisi/hooks.py | 5 +++-- sisi/retro.py | 4 ++-- tests/test_core.py | 12 ++++++++++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0e7a43b..b4e8e15 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ by its full model id (`claude-sonnet-5-5`); anywhere else the name must match wh **Done.** Nothing starts before `sisi done` has recorded the goal, the checks that decide success and what the person will need next: delegating or editing is refused until then. Every check needs a verdict (`sisi done --pass N` or `--fail N`) before the turn ends; a turn that changed things, or failed a check, -is sent to the retro, and any other closes itself. Each record in `retro.jsonl` carries `session_id`, `retro_seconds` (when demanded), +is sent to the retro, and any other closes itself, as does work that took under `retro_minutes`, passed every check and delegated nothing. While a delegated job is open and not late, a stop is not held up for checks without a verdict. Each record in `retro.jsonl` carries `session_id`, `retro_seconds` (when demanded), the numbers (minutes, messages, tool calls, delegations, checks) and the `term` it fell short on (`value`, `evidence`, `time`, `cost`, `attention` or `learning`: the terms of the objective), and `sisi retro` lays the facts out under those terms and shows their trend. @@ -96,7 +96,7 @@ its limits are. Releases live in `$SISI_LIB`, else `~/.local/lib/sisi`. Settings go under `"core"` in `config.json` in your store: `gate`, `meter`, `direct_calls` (8), -`direct_extension` (8), `rules_lines` (30), `rules_chars` (4000), `organize_after` (8), `research_days` (7), +`direct_extension` (8), `rules_lines` (30), `rules_chars` (4000), `organize_after` (8), `research_days` (7), `worker_minutes` (15), `shell_workers` (false), `retro_minutes` (5: work that passed every check, delegated nothing and took less than this many minutes from `sisi done` closes without a retro). Workers are started with the host's own delegation tool, so by default a shell command that starts a worker (`opencode`, `muse`, `agy`: the first word of a command line in your models table) is refused. Set `"shell_workers": true` to allow it: it is then free on the meter, and needs a pick like any diff --git a/sisi/hooks.py b/sisi/hooks.py index 3a3830b..c8c9436 100644 --- a/sisi/hooks.py +++ b/sisi/hooks.py @@ -7,7 +7,7 @@ from . import models, rules, store # A delegated session says so in the first lines of its first request (the brief), or a host's bracketed line # at the start of a line says an agent, not the user, sent it. -WORKER = re.compile(r"(?im)^\W*(you are a (worker|subagent|sub-agent|delegate)\b|do this task yourself|do not delegate|\[[^\]\n]{0,200}\bsent this message, not the user\.?\])") +WORKER = re.compile(r"(?im)^\W*(you are a (worker|subagent|sub-agent|delegate)\b|do this task yourself|do not delegate)|\A\s*\[[^\]\n]{0,200}\bsent this message, not the user\.?\]") DIRECT = ("shell", "read", "edit", "search", "web") # the classes of tool call the meter counts METER = ("sisi: %d direct tool calls this turn (the limit is %d). Delegate the rest: `sisi models` lists your " @@ -125,6 +125,7 @@ def prompt(p): if not s.get("prompts") and WORKER.search(p["prompt"][:2000]): s["worker"] = True s["prompts"] = s.get("prompts", 0) + 1 + s.get("prompts_since") or s.update(began=time.time()) # the first request of a piece of work s["prompts_since"] = s.get("prompts_since", 0) + 1 s["direct"], s["extra"], s["blocks"] = 0, 0, 0 return 0 @@ -204,7 +205,7 @@ def gate(p, for_subagent=False): unsaid = ["%d. %s" % (i, c["text"]) for i, c in enumerate(checks, 1) if not c["verdict"]] failed = [str(i) for i, c in enumerate(checks, 1) if c["verdict"] == "fail"] worked = s.get("changed") or store.snapshot(cwd) != s.get("snapshot") - quick = time.time() - (s.get("done") or {}).get("at", 0) < 60 * store.config()["retro_minutes"] and not s.get("delegations_since") + quick = 0 <= time.time() - s.get("began", 0) < 60 * store.config()["retro_minutes"] and not s.get("delegations_since") and not s.get("fails_since") if checks and not unsaid and not failed and (not worked or quick): from . import retro retro.record(s, cwd, {}, sid) # every check passed and nothing changed, or it was quick and alone: the work closes itself diff --git a/sisi/retro.py b/sisi/retro.py index 0bcb1d0..454e6d8 100644 --- a/sisi/retro.py +++ b/sisi/retro.py @@ -112,7 +112,7 @@ def record(s, cwd, opt, sid=None): store.commit("retro recorded", log) s["snapshot"], s["changed"], s["retro_at"] = store.snapshot(cwd), False, now for key in ("prompts_since", "direct_since", "delegations_since", "reasons_since", "workers_since", "done", "paused", - "fails_since", "picked", "starts", "retro_demanded"): + "fails_since", "picked", "starts", "retro_demanded", "began"): s.pop(key, None) @@ -135,7 +135,7 @@ def done(args, cwd=None): return 1 with store.session(sid) as s: if new: - s["done"] = {"goal": opt["goal"][0], "next": opt["next"][0], "at": time.time(), + s["done"] = {"goal": opt["goal"][0], "next": opt["next"][0], "checks": [{"text": c, "verdict": None, "evidence": ""} for c in opt["check"]]} elif verdict: kind, n, why = verdict diff --git a/tests/test_core.py b/tests/test_core.py index ba322ae..89309c2 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -274,10 +274,15 @@ class Core(unittest.TestCase): "l2": "Ok I've been running the lead agent -> subagents for a short while. Can you see what's in the ledger already?", "l3": "install ZCode for me. I just got a z.ai subscription. I want to be able to use it from t3code as a subagent call.", "l4": "This project is in the current directory. Have a worker do one small task: list the python files in src/, one per line.", - "l5": 'Why did this arrive? "[T3 Code: the agent in T3 thread x sent this message, not the user.]" appears in the middle of a sentence, and you are a worker for me.'} + "l5": 'Why did this arrive? "[T3 Code: the agent in T3 thread x sent this message, not the user.]" appears in the middle of a sentence, and you are a worker for me.', + "l6": "What is this?\n> " + marker + "It showed up in my thread.", # the marker quoted on a later line + "l7": "> " + marker + "Why did the gate let this one through?"} # the marker quoted at the start for sid, text in dict(workers, **leads).items(): self.hook("prompt", sid=sid, prompt=text) self.assertEqual(bool(self.state(sid).get("worker")), sid in workers, sid) + began = time.time() + self.hook("prompt", sid="long", prompt="[" * 200000) # a long line of brackets costs no time + self.assertLess(time.time() - began, 5) def test_the_models_table_is_researched_recorded_and_goes_stale(self): self.assertIn("no models table yet", self.hook("tick")[1]) @@ -1591,7 +1596,7 @@ class Core(unittest.TestCase): path = os.path.join(self.tmp, "state", "core-sessions", sid + ".json") with open(path, "r+") as f: st = json.load(f) - st["done"]["at"] = time.time() - minutes * 60 # the done was recorded this long ago + st["began"] = time.time() - minutes * 60 # the work was asked for this long ago f.seek(0), f.truncate(), json.dump(st, f) return self.hook("gate", sid=sid)[1] self.assertEqual(work("a", 4), "") # 4 minutes, all passed, no delegation: closed @@ -1599,6 +1604,9 @@ class Core(unittest.TestCase): self.assertNotIn("gap", self.records()[0]) self.assertIn("no retro yet", work("b", 6)) # 6 minutes: the retro self.assertIn("no retro yet", work("c", 4, fail=True)) # a failed check: the retro + self.assertEqual(self.sisi("done", "--pass", "2", "empty name kept after the fix", sid="c")[0], 0) + self.assertIn("no retro yet", self.hook("gate", sid="c")[1]) # a check that failed and was then fixed: still the retro + self.assertIn("no retro yet", work("f", -1)) # a clock that went backwards: the retro self.assertIn("no retro yet", work("d", 4, delegate=True)) # a delegation: the retro self.assertEqual(len(self.records()), 1) self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"retro_minutes": 10}}))