Repository navigation
Description
Summary
The SETNX single-flight lock idiom is hand-rolled in seven places with seven divergent behaviours, and the bug class #1919 fixed in restart_fleet (extending/releasing a lock you no longer own) is live elsewhere — worst in system_seed_service, whose _release_lock does an unconditional, tokenless r.delete(_PROVISION_LOCK_KEY) (src/backend/services/system_seed_service.py:476-482): it deletes a successor's lock, the severest form of the class. Mitigated today only by first-run-only usage + the existence backstop.
The seven sites
| Site | Shape |
|---|---|
routers/ops.py |
SETNX+token, ownership-checked gate + CAD release (hardened by #1919 — shares redis_breaker_util.lock_token_matches) |
services/agent_service/ephemeral.py:119-131,210-218 |
byte-identical to pre-#1919 ops.py, incl. the dead .encode() branch — first adoption candidate for the shared helper |
services/skill_service.py:509-545 |
token + check-and-delete, TTL 1800 |
routers/sessions.py:180-186,309-383 |
async client, Lua CAS release, context manager — most mature |
services/monitoring_service.py:957-1006 |
leader lease, own-lease-only refresh (#1464) |
services/operator_queue_service.py:278-306 |
verbatim copy of monitoring (#1632) |
services/system_seed_service.py:463-482 |
no token at all; unconditional delete on release |
Proposal
- Fix
system_seed_service._release_lockto a token + compare-and-delete release (smallest slice, ships alone if needed). - Consolidate onto an ownership-checked
SingleFlightLockprimitive inredis_breaker_util(acquire/refresh_if_owned/release_if_owned; fail-open preserved; bug: fleet-restart lock — lease refresh isn't ownership-checked, and acquisition sits outside the try/finally (#1912 review follow-up) #1919'slock_token_matchesis the first shared piece). Adopt inops.py+ephemeral.pyfirst; leader-lease sites (monitoring/operator_queue) may stay on their own-lease idiom or adopt a leader variant. - Do NOT regress the deliberate per-site properties: fail-open on Redis down, sessions' Lua CAS, leader-lease semantics.
Context
Found by the #1919 strategy review (#1919); the 6-month-regret scenario named there is someone hitting copy #8 of this bug and writing private helper #2. Related precedent: #1464 (own-lease refresh), #1560 (single enumeration point pattern).
Acceptance Criteria
-
system_seed_servicerelease is ownership-checked (token + compare-and-delete) - A shared
SingleFlightLock(or equivalent) exists inredis_breaker_utilwith acquire / refresh_if_owned / release_if_owned, fail-open -
ops.pyandephemeral.pyconsume it (behavior-preserving; bug: fleet-restart lock — lease refresh isn't ownership-checked, and acquisition sits outside the try/finally (#1912 review follow-up) #1919's tests stay green) - Per-site deliberate properties preserved (documented above)
Activity
fix: ownership-checked fleet-restart lease with loss detection + acqu…
docs(#1920): the #2215 pass lock adopts SingleFlightLock too
fix(#1920): consolidate hand-rolled Redis single-flight locks onto ow…
Release: v0.9.0 (#2268)
test(1920): allowlist the #447 recovery leader lease
3 remaining items
fix(dispatch): carry inter-agent chain depth through loops, schedule …
fix(auth): count change attempts with INCR + EXPIRE NX, not SET NX (#…
feat(auth): change the admin password in the app, and keep it across …
chore(evaluations): follow-ups from rebasing onto dev
chore(evaluations): follow-ups from rebasing onto dev
chore(evaluations): follow-ups from rebasing onto dev
chore(evaluations): follow-ups from rebasing onto dev
chore(evaluations): follow-ups from rebasing onto dev
chore(evaluations): follow-ups from rebasing onto dev
chore(evaluations): follow-ups from rebasing onto dev
chore(evaluations): follow-ups from rebasing onto dev
test: allowlist the per-pair wake budget's once-per-window alert mark…
fix(agents): wake-on-ending turns stand at the delegator's depth; per…
fix(audit): release the terminate audit claim when the audit write fa…
fix(audit): record a terminate that ended the turn when another write…