From bbdde68dc35b37bc6e738618211005d67d128ff3 Mon Sep 17 00:00:00 2001 From: Ryan Weiss <1996129+rymiwe@users.noreply.github.com> Date: Tue, 24 Nov 2026 10:39:54 -0800 Subject: [PATCH 1/2] true-check: skip non-regular *.json in gate-passes without blocking (D11) A FIFO named *.json in the gate dir hung eval and verify: os.open(O_RDONLY|O_NOFOLLOW) blocks on a FIFO before the S_ISREG check runs. Now each entry is lstat'ed first and anything that is not a plain file is skipped with the reason "NAME is not a plain file; skipped". The record open and the consumed.log open add O_NONBLOCK, and fstat re-checks S_ISREG after the open, so a swap after lstat cannot block either. Tests: a FIFO 0.json alone holds with that reason; a FIFO before a valid record still allows, and verify consumes once; a FIFO consumed.log is refused. Both run under a 20 s cap so a hang fails instead of stalling CI. Builder: Grok Bot (Code Cole executor session); underlying model unknown --- bin/true-check | 19 ++++++++++++++++--- tests/test_true_check.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/bin/true-check b/bin/true-check index 8032ca8..a629196 100755 --- a/bin/true-check +++ b/bin/true-check @@ -875,7 +875,8 @@ def safe(st) -> bool: def open_consumed(create: bool) -> int | None: """consumed.log as an fd: never through a symlink, never when group/other-writable. None if absent.""" import stat - flags = os.O_RDWR | os.O_APPEND | os.O_NOFOLLOW | (os.O_CREAT if create else 0) + # O_NONBLOCK: a FIFO here must not block the open; fstat below refuses anything not a plain file. + flags = os.O_RDWR | os.O_APPEND | os.O_NOFOLLOW | os.O_NONBLOCK | (os.O_CREAT if create else 0) try: fd = os.open(consumed_log(), flags, 0o600) except FileNotFoundError: @@ -958,12 +959,24 @@ def gate_pass(subject: dict, gate: str) -> tuple[str | None, str | None]: if not name.endswith(".json"): continue try: - fd = os.open(f, os.O_RDONLY | os.O_NOFOLLOW) + lst = os.lstat(f) + except OSError: + continue # gone + if not stat.S_ISREG(lst.st_mode): + # A FIFO, device, link or dir named *.json: opening a FIFO would block (D11). + why = f"enforced_by {gate}: {name} is not a plain file; skipped" + continue + try: + # O_NONBLOCK: if the entry was swapped for a FIFO after lstat, the open still returns. + fd = os.open(f, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK) except OSError: continue # a link, or gone try: st = os.fstat(fd) - if not stat.S_ISREG(st.st_mode) or not safe(st): + if not stat.S_ISREG(st.st_mode): + why = f"enforced_by {gate}: {name} is not a plain file; skipped" + continue + if not safe(st): continue # a record anyone else could write proves nothing with os.fdopen(os.dup(fd), "rb") as fh: raw = fh.read() diff --git a/tests/test_true_check.py b/tests/test_true_check.py index eaa4000..ae9f9c4 100644 --- a/tests/test_true_check.py +++ b/tests/test_true_check.py @@ -1090,6 +1090,42 @@ def test_d9_consumed_log_link_or_open_is_refused_and_not_followed(self): self.assertEqual(rc, 11) self.assertIn("consumed.log is not a plain file or is writable by others", out["allow_reason"]) + def bounded(self, cmd, subj): + """Run eval or verify with a 20 s cap, so a hang fails the test instead of stalling the suite.""" + sp, rp = self.tmp / "d11-subject.json", self.tmp / "d11-result.json" + sp.write_text(json.dumps(subj)) + args = ["eval", str(sp), "--out", str(rp)] if cmd == "eval" else ["verify", str(rp), str(sp)] + try: + cp = subprocess.run(["python3", str(BIN), *args], text=True, capture_output=True, env=self.env, timeout=20) + except subprocess.TimeoutExpired: + self.fail(f"true-check {cmd} hung on a FIFO in the gate-passes dir (D11)") + return cp.returncode, (json.loads(rp.read_text()) if cmd == "eval" and rp.exists() else None) + + # Paul's cc6d61c probes, D11: a FIFO named *.json must not hang eval or verify + def test_d11_fifo_record_is_skipped_without_hanging(self): + subj = self.approve_row_and_subject() + d = self.tmp / "passes" / "approve-gate" + d.mkdir(parents=True) + d.chmod(0o755) + d.parent.chmod(0o755) + os.mkfifo(d / "0.json", 0o600) + rc, out = self.bounded("eval", subj) + self.assertEqual(rc, 11) + self.assertEqual(out["allow_reason"], "gate row g: enforced_by approve-gate: 0.json is not a plain file; skipped") + self.record(subj, "approve-gate") # pass-*.json sorts after the FIFO + rc, out = self.bounded("eval", subj) + self.assertEqual((rc, out["allowed"]), (0, True), out["allow_reason"]) + self.assertEqual(self.bounded("verify", subj)[0], 0) + self.assertEqual(self.used_lines(), 1) + + def test_d11_fifo_consumed_log_is_refused_without_hanging(self): + subj = self.approve_row_and_subject() + self.record(subj, "approve-gate") + os.mkfifo(self.tmp / "passes" / "consumed.log", 0o600) + rc, out = self.bounded("eval", subj) + self.assertEqual(rc, 11) + self.assertIn("consumed.log is not a plain file", out["allow_reason"]) + def test_record_ts_in_the_future_says_so(self): subj = self.approve_row_and_subject() self.record(subj, "approve-gate", age=-300) From ed9d825b96dc46b575fb3512f7ff6bfccc2b48e8 Mon Sep 17 00:00:00 2001 From: Ryan Weiss <1996129+rymiwe@users.noreply.github.com> Date: Tue, 24 Nov 2026 13:27:54 -0800 Subject: [PATCH 2/2] true-check: label consumed.log O_NONBLOCK as a portability guard The flag is not a Linux fix: POSIX leaves O_RDWR on a FIFO undefined, and on Linux the open already returns without blocking while fstat already refuses a non-file. Comment only; no behavior change. Builder: Grok Bot (Code Cole executor session); underlying model unknown --- bin/true-check | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/true-check b/bin/true-check index a629196..151853f 100755 --- a/bin/true-check +++ b/bin/true-check @@ -875,7 +875,9 @@ def safe(st) -> bool: def open_consumed(create: bool) -> int | None: """consumed.log as an fd: never through a symlink, never when group/other-writable. None if absent.""" import stat - # O_NONBLOCK: a FIFO here must not block the open; fstat below refuses anything not a plain file. + # O_NONBLOCK is a defensive portability guard, not a Linux fix: POSIX leaves + # O_RDWR on a FIFO undefined. On Linux the open already returns without + # blocking, and fstat below already refuses anything that is not a plain file. flags = os.O_RDWR | os.O_APPEND | os.O_NOFOLLOW | os.O_NONBLOCK | (os.O_CREAT if create else 0) try: fd = os.open(consumed_log(), flags, 0o600)