You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor: per-agent start lock — complete the concurrent-start race hardening from #1809 #1817
#1809 shipped minimal recreate-race hardening: container_remove tolerates NotFound and a 409 name-conflict on the run adopts the winner's container. That converts the loser's 500 into a graceful success, but two concurrent starts can still both enter the recreate sequence (double stop/remove work, interleaved injections).
The full fix is a per-agent start lock serializing start_agent_internal, following the existing Redis SETNX+TTL precedent (agent:data_op:{name} in routers/agent_data.py).
New lock infrastructure on a hot path has its own failure modes (stuck lock blocks starts; TTL sizing; Redis-down behavior; wait-vs-409 contention semantics) — deliberately kept out of a P2 bug fix. See the #1809 plan's decision trail.
Heads-up from #1860 (PR #1912): lifecycle.restart_agent_internal(name, *, stop_timeout=30) now exists as the canonical stop→cold-start helper, consumed by restart_fleet. Its docstring names this issue as the future home of the per-agent start lock — when the lock lands there, the remaining inline copies of the stop→start_agent_internal shape can consolidate onto it in the same pass: routers/system_agent.py (restart/reinitialize), routers/systems.py (restart_system loop), and services/subscription_auto_switch.py (which additionally holds its own #799 process-local lock and uses stop timeout 10 — parameterized via stop_timeout).
Field note from an OSS instance, in case it helps prioritise: the missing start lock has a
side effect beyond the alarming log line.
Observed on a cold boot: two uvicorn workers created a system-scoped MCP key 5 ms apart
(10:41:48.059681Z and .064936Z), the loser logged ERROR … Failed to create system agent: 409 … name already in use plus WARNING: System agent deployment issue, and the winner logged System agent created and started
137 ms later. The system agent was healthy throughout.
Each race mints a duplicate MCP key, and nothing prunes superseded keys. That instance's trinity-system now holds 4 activeagent-trinity-system-key rows (2026-06-08, 2026-07-09, and
two 5 ms apart on 2026-08-08), and every one of them still authenticates. Instance-wide the key
count went 52 → 57 (36 → 37 active) over three days, with duplicate active keys on 13 agents.
So the race is not purely cosmetic: it accumulates valid credentials at one per worker per boot.
Two things would help independently of the lock —
make system-agent key creation idempotent (reuse the existing active key rather than minting), and
deactivate superseded per-agent keys when a new one is minted.
The human risk of the ERROR line is also real: an operator seeing it mid-upgrade will roll back a
healthy deploy. Downgrading the loser's path to INFO/DEBUG once the lock lands would close that.
Activity
fix(agents): adopt a rebuilt base image on agent cold start (#1809) (#…
fix(system-agent): trinity-system adopts a rebuilt base image at the …
webmixgamer commentedon Jul 31, 2026
Heads-up from #1860 (PR #1912):
lifecycle.restart_agent_internal(name, *, stop_timeout=30)now exists as the canonical stop→cold-start helper, consumed byrestart_fleet. Its docstring names this issue as the future home of the per-agent start lock — when the lock lands there, the remaining inline copies of the stop→start_agent_internalshape can consolidate onto it in the same pass:routers/system_agent.py(restart/reinitialize),routers/systems.py(restart_system loop), andservices/subscription_auto_switch.py(which additionally holds its own #799 process-local lock and uses stop timeout 10 — parameterized viastop_timeout).fix: fleet restart adopts rebuilt base images through the canonical l…
AndriiPasternak31 commentedon Aug 11, 2026
Field note from an OSS instance, in case it helps prioritise: the missing start lock has a
side effect beyond the alarming log line.
Observed on a cold boot: two uvicorn workers created a system-scoped MCP key 5 ms apart
(
10:41:48.059681Zand.064936Z), the loser loggedERROR … Failed to create system agent: 409 … name already in useplusWARNING: System agent deployment issue, and the winner loggedSystem agent created and started137 ms later. The system agent was healthy throughout.
Each race mints a duplicate MCP key, and nothing prunes superseded keys. That instance's
trinity-systemnow holds 4 activeagent-trinity-system-keyrows (2026-06-08, 2026-07-09, andtwo 5 ms apart on 2026-08-08), and every one of them still authenticates. Instance-wide the key
count went 52 → 57 (36 → 37 active) over three days, with duplicate active keys on 13 agents.
So the race is not purely cosmetic: it accumulates valid credentials at one per worker per boot.
Two things would help independently of the lock —
The human risk of the ERROR line is also real: an operator seeing it mid-upgrade will roll back a
healthy deploy. Downgrading the loser's path to INFO/DEBUG once the lock lands would close that.
Release: v0.9.0 (#2268)