Items 4 and 5: pause is refused without a valid session-bound unit and never silences another session's gate; the gate judges only the unit the session holds (send-back is continue/park/init). Existing gate tests bind their session. done / next: item 6 (independent evidence, rules, refusal counts)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-23 14:27:18 -07:00
1 parent ed55af910a
commit cf2587df21
8 files changed
+285 -28

No files matched your search

+1 -1
View File
@@ -126,7 +126,7 @@ def human(id, rung=5, kind="general"):
def contract(checks, invariants=()):
return {"id": "t", "goal": "g", "risk": {"profile": "isolated"}, "checks": list(checks),
return {"id": "t", "goal": "make the feature work", "risk": {"profile": "isolated"}, "checks": list(checks),
"invariants": list(invariants), "assumptions": [], "questions": []}
+1 -1
View File
@@ -45,7 +45,7 @@ class EndToEnd(SisiCase):
def agent_runs(self, command, *argv):
with open(self.tp, "a") as f:
f.write(json.dumps(tool_line("Bash", {"command": command})) + "\n")
return self.sisi(*argv)
return self.sisi(*argv, env={"SISI_SESSION_ID": "e2e"}) # what the session-start hook exports to the agent's shell
def finding(self, n):
r = self.sisi("retro", "--finding", "`cargo test` run %d took 4 minutes with no fuzz verifier in the project" % n,
+11 -4
View File
@@ -47,6 +47,13 @@ class GateBase(SisiCase):
self.tdir = os.path.join(self.tmp, "transcripts")
os.makedirs(self.tdir)
def write_contract(self, c, d=None, trusted=True, bind=True):
"""The unit this test's session holds (a unit the session did not open or continue is never judged: item 5)."""
super().write_contract(c, d, trusted)
if bind:
from sisi import unitguard
unitguard.bind(self.sid, d or self.proj, c, "init")
def put(self, rel, text="x\n", mode="w"):
p = os.path.join(self.proj, rel)
os.makedirs(os.path.dirname(p), exist_ok=True)
@@ -363,7 +370,7 @@ class FlowTests(GateBase):
s.write("app.py", "x = 1\n")
s.contract(contract([check("feature", "test -f ok.txt")]))
self.assertEqual(s.stop()[0], "block") # the offer
self.assertEqual(self.sisi("unit", "pause", "the reviewer").returncode, 0)
self.assertEqual(self.sisi("unit", "pause", "the reviewer", env={"SISI_SESSION_ID": self.sid}).returncode, 0)
self.assertEqual(s.stop(), ("allow", None))
self.assertEqual(self.unit_state()["status"], "paused")
s.edit("app.py", "y = 2\n")
@@ -377,7 +384,7 @@ class FlowTests(GateBase):
s = self.session()
s.write("app.py", "x = 1\n")
s.contract(contract([check("feature", "test -f ok.txt")]) | {"started": store.now()})
self.sisi("unit", "pause", "waiting for ever")
self.sisi("unit", "pause", "waiting for ever", env={"SISI_SESSION_ID": self.sid})
r = self.sisi("contract", "init")
self.assertEqual(r.returncode, 1)
self.assertIn("still open", r.stdout)
@@ -875,7 +882,7 @@ class GateFailOpenTests(GateBase):
self.assertIn("kaboom", f.read())
def test_unwritable_state_allows(self):
self.write_contract(contract([check("bad", "false")]))
self.write_contract(contract([check("bad", "false")]), bind=False)
os.makedirs(self.state, exist_ok=True)
open(os.path.join(self.state, "sessions"), "w").close() # session records can no longer be written
r = self.hook()
@@ -973,7 +980,7 @@ class GateSequenceTests(GateBase):
n_retro += 1
self.record_finding(n_retro, sid=a.sid)
elif op == "pause" and self.unit_state().get("status") == "open":
self.sisi("unit", "pause", "waiting for the reviewer %d" % step)
self.sisi("unit", "pause", "waiting for the reviewer %d" % step, env={"SISI_SESSION_ID": a.sid})
paused = True
elif op == "other_edits":
b.edit("other.py", "y = %d\n" % step)
+5 -5
View File
@@ -20,7 +20,7 @@ class UnitCase(SisiCase):
self.contract_path = os.path.join(self.proj, ".sisi", "contract.json")
def start(self, checks=None, **fields):
r = self.sisi("contract", "init", "--goal", "make the thing")
r = self.sisi("contract", "init", "--goal", "make the thing", env={"SISI_SESSION_ID": "p1"})
self.assertEqual(r.returncode, 0, r.stdout)
c = C.load(self.contract_path)
c["checks"] = checks or [real("works", "test -f done.txt")]
@@ -371,14 +371,14 @@ class PauseTests(UnitCase):
def test_pause_lets_the_turn_end_and_a_change_ends_the_wait(self):
"""R-6.1-5: a pause is recorded, the gate makes no demands while nothing changes, a new change
ends the wait, and the wait is telemetry."""
self.sisi("tick", stdin=json.dumps({"session_id": "p1", "cwd": self.proj, "hook_event_name": "SessionStart"})) # session start comes first
self.start()
self.assertEqual(self.sisi("unit", "pause", "").returncode, 1)
self.assertEqual(self.sisi("unit", "pause", "the owner's decision").returncode, 0)
self.assertEqual(self.sisi("unit", "pause", "", env={"SISI_SESSION_ID": "p1"}).returncode, 1)
self.assertEqual(self.sisi("unit", "pause", "the owner's decision", env={"SISI_SESSION_ID": "p1"}).returncode, 0)
c = C.load(self.contract_path)
self.assertEqual(c["status"], "paused")
self.assertEqual(c["pauses"][0]["what"], "the owner's decision")
stop = json.dumps({"session_id": "p1", "cwd": self.proj, "hook_event_name": "Stop", "stop_hook_active": False})
self.sisi("tick", stdin=json.dumps({"session_id": "p1", "cwd": self.proj, "hook_event_name": "SessionStart"}))
open(os.path.join(self.proj, "new.py"), "w").write("x = 1\n") # a change after the pause
self.assertIn("block", self.sisi("gate", stdin=stop).stdout)
self.assertEqual(C.load(self.contract_path)["status"], "open") # the wait ended
@@ -391,7 +391,7 @@ class PauseTests(UnitCase):
def test_a_paused_unit_with_no_change_passes_silently(self):
"""R-6.1-5."""
self.start()
self.sisi("unit", "pause", "waiting for a review")
self.sisi("unit", "pause", "waiting for a review", env={"SISI_SESSION_ID": "p1"})
stop = json.dumps({"session_id": "p2", "cwd": self.proj, "hook_event_name": "Stop", "stop_hook_active": False})
self.sisi("tick", stdin=json.dumps({"session_id": "p2", "cwd": self.proj, "hook_event_name": "SessionStart"}))
r = self.sisi("gate", stdin=stop)
+156
View File
@@ -522,5 +522,161 @@ class DelegationTests(GuardCase):
self.assertIsNone(self.spawn("Implement the new greeting"))
class PauseTests(GuardCase):
"""Item 4: pause is for waiting, not for skipping (R-10.3-1, R-14.2-1)."""
def pause(self, sid="me", why="waiting for the reviewer"):
return self.sisi("unit", "pause", why, env={"SISI_SESSION_ID": sid} if sid else {})
def test_pausing_with_no_unit_is_refused(self):
r = self.pause()
self.assertNotEqual(r.returncode, 0)
self.assertIn("never the contract", r.stdout)
self.assertIn("sisi contract init", r.stdout)
def test_pausing_a_unit_this_session_does_not_hold_is_refused_and_the_unit_is_untouched(self):
self.write_contract(good_contract(goal="old work"))
G.bind("someone", self.proj, C.load(self.contract_path), "init")
with open(self.contract_path) as f:
before = f.read()
r = self.pause()
self.assertNotEqual(r.returncode, 0)
for way in ("sisi unit continue", "sisi unit park"):
self.assertIn(way, r.stdout)
self.assertLessEqual(len(r.stdout.splitlines()), 12)
with open(self.contract_path) as f:
self.assertEqual(f.read(), before)
def test_pausing_without_a_known_session_is_refused(self):
self.open_unit()
self.assertNotEqual(self.pause(sid=None).returncode, 0)
def test_pausing_a_unit_missing_what_building_needs_is_refused(self):
"""The placeholder skeleton is not a unit to hide behind."""
self.sisi("contract", "init", "--goal", "make the app greet", env={"SISI_SESSION_ID": "me"})
r = self.pause()
self.assertNotEqual(r.returncode, 0)
self.assertIn("placeholder", r.stdout)
self.assertEqual(C.load(self.contract_path)["status"], "open")
def test_pausing_an_integration_unit_without_its_requirement_list_is_refused(self):
c = good_contract()
self.open_unit(c)
self.put("package.json", "{}\n") # the work already touches a manifest: the floor is integration
r = self.pause()
self.assertNotEqual(r.returncode, 0)
self.assertIn("requirement list", r.stdout)
def test_a_valid_unit_this_session_holds_can_be_paused(self):
self.open_unit()
r = self.pause()
self.assertEqual(r.returncode, 0, r.stdout)
self.assertEqual(C.load(self.contract_path)["status"], "paused")
def test_every_refused_pause_is_recorded(self):
self.pause()
self.write_contract(good_contract())
self.pause()
self.assertEqual([r["tool"] for r in self.refusals()], ["pause", "pause"])
self.assertTrue(all("pause" in r["what"] for r in self.refusals()))
class GateUnitTests(GuardCase):
"""Items 4 and 5: the gate judges only the unit the session holds, whatever is paused (R-5.3-1, R-10.1-1)."""
def setUp(self):
super().setUp()
os.environ["SISI_RETRO_REQUIRED"] = "1"
self.addCleanup(lambda: os.environ.__setitem__("SISI_RETRO_REQUIRED", "0"))
self.tick()
def stop(self, sid=None):
return gate.decide({"session_id": sid or self.sid, "cwd": self.proj, "hook_event_name": "Stop", "stop_hook_active": False})
def failing_foreign_unit(self, **kw):
c = good_contract(goal="redo the old report", id="old-report", checks=[dict(real("oldcheck"), cmd="false")], **kw)
self.write_contract(c)
G.bind("someone-else", self.proj, C.load(self.contract_path), "init")
def test_a_foreign_units_failing_checks_are_not_what_the_session_is_sent_back_for(self):
self.failing_foreign_unit()
self.put(SRC, "def greet():\n return 'yo'\n")
a, msg = self.stop()
self.assertEqual(a, "block")
for way in ("sisi unit continue", "sisi unit park", "sisi contract init"):
self.assertIn(way, msg)
self.assertIn("old-report", msg)
self.assertNotIn("oldcheck", msg)
self.assertNotIn("Failing checks", msg)
self.assertEqual([r for r in self.results() if r.get("contract") == "old-report"], [], "its checks must not run")
def test_a_trivial_change_with_a_foreign_unit_open_is_not_judged_at_all(self):
self.failing_foreign_unit()
self.put("README.md", "# app\nmore words\n")
self.assertEqual(self.stop(), ("allow", None))
self.assertEqual(self.results(), [])
def test_a_stale_unit_the_session_was_bound_to_asks_for_continue_not_for_its_checks(self):
self.write_contract(good_contract(checks=[dict(real("c1"), cmd="false")]))
self.age_unit(C.load(self.contract_path), 20 * 3600, "me")
self.put(SRC, "def greet():\n return 'yo'\n")
a, msg = self.stop()
self.assertEqual(a, "block")
self.assertIn("no activity since", msg)
self.assertIn("sisi unit continue", msg)
self.assertEqual(self.results(), [])
def test_the_send_backs_run_out_as_unverified_and_the_foreign_unit_is_left_exactly_as_it_was(self):
self.failing_foreign_unit()
with open(self.contract_path) as f:
before = f.read()
self.put(SRC, "def greet():\n return 'yo'\n")
outs = [self.stop() for _ in range(4)]
self.assertEqual([o[0] for o in outs[:3]], ["block"] * 3)
self.assertEqual(outs[3][0], "allow")
self.assertIn("UNVERIFIED", outs[3][1])
with open(self.contract_path) as f:
self.assertEqual(f.read(), before)
def test_a_paused_foreign_unit_does_not_silence_the_gate_for_another_session(self):
c = good_contract(goal="redo the old report", id="old-report")
c["status"] = "paused"
c["pauses"] = [{"what": "a review", "since": store.now(), "until": None}]
self.write_contract(c)
G.bind("someone-else", self.proj, C.load(self.contract_path), "init")
self.put(SRC, "def greet():\n return 'yo'\n")
a, msg = self.stop()
self.assertEqual(a, "block")
self.assertIn("sisi unit continue", msg)
self.assertEqual(C.load(self.contract_path)["status"], "paused") # not resumed, not touched
def test_a_paused_unit_silences_only_the_session_bound_to_it_and_only_while_valid(self):
self.open_unit()
self.put(SRC, "def greet():\n return 'yo'\n")
self.assertEqual(self.sisi("unit", "pause", "waiting for the reviewer", env={"SISI_SESSION_ID": "me"}).returncode, 0)
self.assertEqual(self.stop(), ("allow", None))
# the unit is broken after the pause (a vacuous check): the pause no longer hides anything
c = C.load(self.contract_path)
c["checks"] = [dict(real("c1"), cmd="true")]
C.save(self.contract_path, c)
self.put(SRC, "def greet():\n return 'hey'\n")
a, msg = self.stop()
self.assertEqual(a, "block")
self.assertIn("cannot fail", msg)
def test_with_no_unit_at_all_a_source_change_is_still_sent_back_for_a_contract(self):
self.put(SRC, "def greet():\n return 'yo'\n")
a, msg = self.stop()
self.assertEqual(a, "block")
self.assertIn("a contract for this isolated change", msg)
def test_the_session_that_holds_the_unit_is_judged_as_before(self):
self.open_unit(good_contract(checks=[dict(real("c1"), cmd="false")]))
self.put(SRC, "def greet():\n return 'yo'\n")
a, msg = self.stop()
self.assertEqual(a, "block")
self.assertIn("c1", msg)
if __name__ == "__main__":
unittest.main()