Ryan Gu
cc295509b4
fix(tirith): half-open the circuit breaker instead of latching it open
...
After _CRASH_LIMIT consecutive spawn/execution failures the breaker opened and
never closed again: check_command_security returns early while _circuit_open
is set, so the reset below it was unreachable for the rest of the process. A
transient failure (a slow disk during install, a binary being replaced) meant
every later command silently skipped scanning until restart — a security
control that fails open permanently, not temporarily.
The breaker now half-opens after _CIRCUIT_RETRY_S: exactly one caller claims
the probe slot and runs a real scan. Claiming re-arms _circuit_open_at under
_breaker_lock first, so concurrent callers see a fresh TTL and stay on the
fail-open path — single-flight, one probe per TTL window. The lock guards only
the claim (a TTL comparison and a timestamp write); it is never held across
the subprocess, so it cannot reintroduce the #41400 hang. Crash counting stays
lock-free, matching the mcp_tool.py error counters.
Any completed scan closes the breaker. exit 0/1/2 are all verdicts —
allow/block/warn — and all three prove the binary is healthy, so recovery no
longer depends on the next command happening to be clean. That also fixes the
streak never resetting on block/warn.
time.monotonic() throughout, matching the MCP breaker: a wall-clock jump
backwards must not strand the breaker open past its TTL.
Rebased onto current main; the file was reformatted upstream in the tools/
compaction wave, so the change is re-expressed in the current structure
(_verdict / _EXIT_ACTIONS). The latch itself is unchanged upstream.
(cherry picked from commit 2ff4ee6c745060e9aaf4f4ee2d04ac68ba55b2e8)
2026-09-18 09:59:54 -07:00
..
2026-09-16 17:09:50 -07:00
2026-09-18 09:24:54 -07:00
2026-09-18 09:54:45 -07:00
2026-09-17 09:02:55 -07:00
2026-09-03 09:44:26 -07:00
2026-09-03 17:13:22 -07:00
2026-09-15 04:12:13 -07:00
2026-09-17 20:38:43 +05:30
2026-09-11 19:39:12 -07:00
2026-09-17 09:04:38 -07:00
2026-09-03 13:49:57 -07:00
2026-09-15 21:46:37 -07:00
2026-09-03 13:49:57 -07:00
2026-09-17 09:04:38 -07:00
2026-09-03 09:44:26 -07:00
2026-09-17 00:34:50 -05:00
2026-09-17 21:17:26 +05:30
2026-09-16 17:19:58 -07:00
2026-09-18 09:19:04 -07:00
2026-09-16 22:25:33 -07:00
2026-09-16 22:25:33 -07:00
2026-09-18 09:19:04 -07:00
2026-09-03 17:13:22 -07:00
2026-09-12 01:35:05 -07:00
2026-09-16 16:59:03 -07:00
2026-09-04 00:15:16 -07:00
2026-09-03 13:49:57 -07:00
2026-09-18 09:19:04 -07:00
2026-09-15 06:16:38 -07:00
2026-09-15 06:16:38 -07:00
2026-09-11 19:39:12 -07:00
2026-09-03 14:16:54 -07:00
2026-09-13 12:35:36 -07:00
2026-09-16 16:57:03 -07:00
2026-09-03 14:16:54 -07:00
2026-09-03 14:16:54 -07:00
2026-09-15 06:16:38 -07:00
2026-09-03 14:16:54 -07:00
2026-09-10 10:35:07 -07:00
2026-09-17 09:02:55 -07:00
2026-09-16 17:12:11 -07:00
2026-09-17 09:02:55 -07:00
2026-09-15 04:56:01 -07:00
2026-09-13 05:09:43 -07:00
2026-09-16 14:34:22 -07:00
2026-09-16 21:15:09 +05:30
2026-09-03 17:13:22 -07:00
2026-09-16 17:47:50 -07:00
2026-09-04 00:15:16 -07:00
2026-09-16 17:14:28 -07:00
2026-09-15 19:09:29 -07:00
2026-09-15 03:45:41 -07:00
2026-09-15 03:45:41 -07:00
2026-09-11 19:39:12 -07:00
2026-09-15 04:13:47 -07:00
2026-09-03 09:44:26 -07:00
2026-09-15 03:56:17 -07:00
2026-09-15 18:41:46 -07:00
2026-09-16 16:56:46 -07:00
2026-09-08 02:26:05 +05:30
2026-09-15 04:12:13 -07:00
2026-09-18 09:52:36 -07:00
2026-09-10 10:23:12 -07:00
2026-09-06 12:02:43 -07:00
2026-09-13 21:05:42 -07:00
2026-09-15 18:40:52 -07:00
2026-09-18 09:29:44 -07:00
2026-09-03 17:13:22 -07:00
2026-09-15 03:45:41 -07:00
2026-09-03 17:13:22 -07:00
2026-09-03 17:13:22 -07:00
2026-09-11 15:29:15 -07:00
2026-09-03 17:13:22 -07:00
2026-09-09 11:46:36 -07:00
2026-09-04 00:15:16 -07:00
2026-09-03 17:13:22 -07:00
2026-09-18 09:54:45 -07:00
2026-09-03 13:33:47 -07:00
2026-09-18 09:54:45 -07:00
2026-09-18 09:54:45 -07:00
2026-09-15 03:57:24 -07:00
2026-09-03 13:10:52 -07:00
2026-09-15 03:57:24 -07:00
2026-09-17 21:17:26 +05:30
2026-09-16 17:19:31 -07:00
2026-09-03 17:13:22 -07:00
2026-09-12 21:55:07 -07:00
2026-09-16 16:59:03 -07:00
2026-09-13 21:03:11 -07:00
2026-09-16 16:42:47 -07:00
2026-09-16 16:42:47 -07:00
2026-09-11 19:39:12 -07:00
2026-09-16 17:21:14 -07:00
2026-09-18 09:29:44 -07:00
2026-09-18 09:32:02 -07:00
2026-09-12 12:32:55 -07:00
2026-09-17 00:11:27 -07:00
2026-09-10 02:21:16 +05:30
2026-09-16 14:34:59 -07:00
2026-09-18 09:20:07 -07:00
2026-09-15 19:00:42 -07:00
2026-09-15 04:54:30 -07:00
2026-09-18 09:45:32 -07:00
2026-09-18 09:45:32 -07:00
2026-09-03 17:13:22 -07:00
2026-09-10 02:21:16 +05:30
2026-09-18 09:58:12 -07:00
2026-09-15 19:04:29 -07:00
2026-09-13 05:09:43 -07:00
2026-09-17 08:51:30 -07:00
2026-09-16 16:52:05 -07:00
2026-09-15 04:12:13 -07:00
2026-09-17 19:06:29 -04:00
2026-09-16 21:15:37 +05:30
2026-09-12 01:35:05 -07:00
2026-09-13 15:41:01 -07:00
2026-09-07 22:47:33 +05:30
2026-09-15 04:55:14 -07:00
2026-09-11 15:27:23 -07:00
2026-09-18 09:45:32 -07:00
2026-09-17 21:18:03 +05:30
2026-09-17 08:51:30 -07:00
2026-09-16 00:32:15 -07:00
2026-09-09 12:19:13 +05:30
2026-09-04 00:15:16 -07:00
2026-09-04 00:15:16 -07:00
2026-09-03 17:13:22 -07:00
2026-09-13 20:46:22 -07:00
2026-09-12 21:13:40 -07:00
2026-09-04 00:15:16 -07:00
2026-09-16 17:01:30 -07:00
2026-09-03 17:13:22 -07:00
2026-09-11 19:58:07 -07:00
2026-09-18 01:43:35 +05:30
2026-09-16 00:32:15 -07:00
2026-09-17 08:52:27 -07:00
2026-09-03 09:44:26 -07:00
2026-09-12 22:09:19 -07:00
2026-09-04 00:15:16 -07:00
2026-09-18 09:23:48 -07:00
2026-09-04 00:15:16 -07:00
2026-09-03 17:13:22 -07:00
2026-09-04 00:15:16 -07:00
2026-09-17 08:53:48 -07:00
2026-09-15 18:39:09 -07:00
2026-09-16 17:55:07 -07:00
2026-09-11 11:54:49 -07:00
2026-09-11 15:26:46 -07:00
2026-09-15 03:58:05 -07:00
2026-09-18 09:35:16 -07:00
2026-09-15 19:03:33 -07:00
2026-09-04 08:15:22 -07:00
2026-09-17 08:47:01 -07:00
2026-09-03 13:33:47 -07:00
2026-09-17 08:47:01 -07:00
2026-09-09 12:19:13 +05:30
2026-09-15 19:03:33 -07:00
2026-09-03 17:13:22 -07:00
2026-09-15 19:01:39 -07:00
2026-09-13 05:09:43 -07:00
2026-09-15 14:15:59 +05:30
2026-09-07 05:59:43 -07:00
2026-09-11 11:54:49 -07:00
2026-09-15 14:15:59 +05:30
2026-09-16 17:43:11 -07:00
2026-09-12 21:50:30 -07:00
2026-09-06 07:17:03 -07:00
2026-09-11 11:54:49 -07:00
2026-09-04 00:15:16 -07:00
2026-09-06 07:17:03 -07:00
2026-09-16 00:32:15 -07:00
2026-09-16 17:23:44 -07:00
2026-09-03 13:27:01 -07:00
2026-09-15 18:33:15 -07:00
2026-09-16 17:05:08 -07:00
2026-09-03 17:13:22 -07:00
2026-09-03 09:44:26 -07:00
2026-09-15 03:46:29 -07:00
2026-09-18 09:54:45 -07:00
2026-09-15 18:58:30 -07:00
2026-09-05 19:01:22 +05:30
2026-09-18 09:35:16 -07:00
2026-09-03 13:24:04 -07:00
2026-09-15 10:48:49 +05:30
2026-09-15 02:22:22 -05:00
2026-09-18 09:54:45 -07:00
2026-09-10 11:48:01 -07:00
2026-09-14 16:16:08 -07:00
2026-09-18 09:59:54 -07:00
2026-09-03 09:44:26 -07:00
2026-09-11 15:26:46 -07:00
2026-09-11 15:44:00 -07:00
2026-09-13 05:09:43 -07:00
2026-09-15 03:41:43 -07:00
2026-09-13 21:04:08 -07:00
2026-09-18 09:24:54 -07:00
2026-09-18 09:24:54 -07:00
2026-09-12 10:00:08 +05:30
2026-09-03 13:17:25 -07:00
2026-09-13 05:07:50 -07:00
2026-09-13 05:09:43 -07:00
2026-09-16 17:21:37 -07:00
2026-09-15 05:36:37 -07:00
2026-09-15 18:25:17 -07:00
2026-09-03 13:20:22 -07:00
2026-09-18 09:47:06 -07:00
2026-09-03 09:44:26 -07:00
2026-09-13 05:32:38 -07:00
2026-09-03 13:20:22 -07:00
2026-09-03 13:20:22 -07:00
2026-09-03 09:44:26 -07:00
2026-09-18 09:28:39 -07:00
2026-09-03 13:20:22 -07:00
2026-09-18 09:47:06 -07:00
2026-09-16 17:12:11 -07:00
2026-09-13 12:35:36 -07:00
2026-09-17 09:02:55 -07:00
2026-09-13 09:18:54 -07:00
2026-09-17 09:02:55 -07:00
2026-09-13 05:07:50 -07:00
2026-09-11 19:14:24 -07:00
2026-09-03 13:30:31 -07:00
2026-09-13 14:39:29 -07:00
2026-09-03 13:24:36 -07:00
2026-09-03 13:24:36 -07:00
2026-09-13 05:07:11 -07:00
2026-09-15 18:42:38 -07:00
2026-09-15 18:43:05 -07:00
2026-09-05 18:46:16 +05:30
2026-09-16 17:43:40 -07:00
2026-09-03 17:13:22 -07:00
2026-09-18 09:19:04 -07:00
2026-09-13 12:35:36 -07:00
2026-09-13 05:07:50 -07:00
2026-09-03 17:13:22 -07:00