From 66045a9ba1e3e6fa2b330d52d1ab54f87e6a987e Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 23 Nov 2026 16:35:17 -0700 Subject: [PATCH] A worker is recognised when its brief's opening line starts a line near the top of its first prompt, not only at character zero, and is marked in the session record so every path exempts it Co-Authored-By: Claude Fable 5.2 --- sisi/orchestration.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sisi/orchestration.py b/sisi/orchestration.py index f8d51d1..6600702 100644 --- a/sisi/orchestration.py +++ b/sisi/orchestration.py @@ -323,8 +323,19 @@ def new_turn(sid, cwd=None, prompt=None): m["turn"] += 1 m.update(calls=0, chars=0, ext=0, refusals=0, fails={}, ext_log=[], same_model_ok=False, unavail=None) m["prompts"] += 1 - if m["prompts"] == 1 and text.lstrip()[:200].lower().startswith(brief_line()): + # A host may put its own context in front of a child's first prompt, so the brief's opening line is + # looked for near the top, not only at character zero. The session record is marked too: the contract + # guard and the gate read `subagent` there, and a worker must be a worker on every path. + if m["prompts"] == 1 and any(ln.strip().lower().startswith(brief_line()) + for ln in text.lstrip()[:600].splitlines()): m["worker"] = True + try: + rec = store.load_session(sid) or {} + if not rec.get("subagent"): + rec["subagent"] = True + store.save_session(sid, rec) + except Exception as e: + store.log_error("orchestration-worker-mark", e) return None