Skip to main content

AGENT_OPEN_LOCKS

Static AGENT_OPEN_LOCKS 

Source
static AGENT_OPEN_LOCKS: LazyLock<Mutex<HashMap<String, Arc<Mutex<()>>>>>
Expand description

Per-agent-definition async lock serializing agent.open’s “check for a live block / seed resume session / create block / register controller” sequence.

Without this, two concurrent agent.open calls for the same agent (a double-invocation, or two tabs opened for the same agent close together) can both observe “not live yet” before either controller actually registers — CreateBlock dispatch, the layout-action enqueue, and write_agent_config_files all await in between — and both seed the same resume_session_id, spawning two controllers that --resume the identical provider session concurrently. That’s the TOCTOU reagent flagged on PR #2059’s first concurrency-guard attempt (the earlier single-point-in-time agent_live_elsewhere check closed the already-live case but not the still-racing-to-become-live case).

Scope note: this only serializes calls handled by THIS process — like the in-memory CONTROLLER_REGISTRY it guards, it can’t see a genuinely different AgentMux instance/channel racing the same registry entry. Same boundary the live-elsewhere check already accepted.