Atomically claim a one-time strict block for this session. Returns True only on the FIRST call for a given session id (O_EXCL create wins once); every later call — or any error — returns False, so a session is blocked at most once and an agent can never be stranded. Best-effort GC of mar
(session_id: str)
| 1328 | |
| 1329 | |
| 1330 | def _mark_session_denied(session_id: str) -> bool: |
| 1331 | """Atomically claim a one-time strict block for this session. Returns True only |
| 1332 | on the FIRST call for a given session id (O_EXCL create wins once); every later |
| 1333 | call — or any error — returns False, so a session is blocked at most once and an |
| 1334 | agent can never be stranded. Best-effort GC of markers older than 24h.""" |
| 1335 | from graphify.paths import out_path |
| 1336 | sid = re.sub(r"[^A-Za-z0-9_-]", "_", str(session_id))[:64] |
| 1337 | if not sid: |
| 1338 | return False |
| 1339 | try: |
| 1340 | d = out_path("cache", "hook_sessions") |
| 1341 | d.mkdir(parents=True, exist_ok=True) |
| 1342 | fd = os.open(str(d / f"{sid}.denied"), os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o644) |
| 1343 | os.close(fd) |
| 1344 | _gc_hook_session_markers(d) |
| 1345 | return True |
| 1346 | except FileExistsError: |
| 1347 | return False |
| 1348 | except Exception: |
| 1349 | return False |
| 1350 | |
| 1351 | |
| 1352 | _SEARCH_COMMANDS = frozenset({ |
no test coverage detected