Fix critical lock-expiry window found in Codex second pass

- poller.py: start lock_refresher() IMMEDIATELY after acquiring the lock,
  before the startup jitter and restart-storm deferral. Those sleeps can
  together exceed LOCK_TTL (restart defer is up to POLL_SWEEP_INTERVAL), so
  with the refresher started afterward the lock could expire mid-deferral and
  a second poller could begin sweeping concurrently — the exact hardware-storm
  risk this design prevents.
- hwgate.py: clamp POLL_CONCURRENCY to 1 unless POLL_ALLOW_UNSAFE_CONCURRENCY
  is set (fragile SAS hardware; >1 can drop expanders). Warn either way.
- build.sh: keep backward-compatible — a non-target first arg is treated as
  the commit message (./build.sh "msg" still works), known targets select
  web|poller|all.
This commit is contained in:
2026-06-16 16:26:36 +00:00
parent 7878e17e55
commit 226f73851c
3 changed files with 30 additions and 12 deletions

View File

@@ -27,11 +27,23 @@ def _semaphore() -> asyncio.Semaphore:
global _sem
if _sem is None:
n = max(1, int(os.environ.get("POLL_CONCURRENCY", "1")))
# Serialized (1) is the safe default. Concurrent hardware I/O can drop
# fragile SAS expanders, so >1 is clamped unless explicitly overridden.
if n > 1:
logger.warning(
"POLL_CONCURRENCY=%d (>1) — hardware ops will run concurrently; "
"only do this on backplanes known to tolerate it", n,
override = os.environ.get("POLL_ALLOW_UNSAFE_CONCURRENCY", "").lower() in (
"1", "true", "yes",
)
if override:
logger.warning(
"POLL_CONCURRENCY=%d with unsafe override — concurrent "
"hardware I/O enabled; backplane must tolerate it", n,
)
else:
logger.warning(
"POLL_CONCURRENCY=%d ignored (clamped to 1 for hardware "
"safety); set POLL_ALLOW_UNSAFE_CONCURRENCY=1 to override", n,
)
n = 1
_sem = asyncio.Semaphore(n)
return _sem