Expand description
Lock coordinates for the per-agent lockfiles.
Two families, both under the per-state locks root and both held
through objectiveai_sdk::lockfile (contents are always empty —
these locks carry liveness, not data):
- Per-instance:
<state>/locks/agents/instances/<…>— theagent_instance_hierarchyis split on/; every segment but the last becomes a literal subdirectory, the last segment is the lockfile key (the SDK escapes the key; directory segments ride raw). A held instance lock ⇔ a live process owns that agent. - Per-tag:
<state>/locks/agents/tagskeyed by the tag name — held while a spawn is materializing an un-upgraded (GROUPED) tag, released once the spawn claims its minted AIH lock.
No create_dir_all here — the SDK’s acquire functions create the
directory chain themselves.
§In-process gate
objectiveai_sdk::lockfile is a cross-PROCESS mutex that is REENTRANT
in-process (its HELD map refcounts per process), so two concurrent
in-process tasks acquiring the SAME agent key both succeed reentrantly
instead of mutually excluding. AgentLock closes that gap: every agent
lock is taken through try_acquire/wait_acquire here, which lock a
per-key in-process tokio::sync::Mutex (the AgentLockMap on
crate::context::Context) FIRST, then the lockfile — and release the
lockfile claim FIRST, then the in-process guard LAST. The in-process lock
both precedes and succeeds the cross-process one.
Structs§
- Acquired
Family - An acquired lock
Family, partitioned for the registry. - Agent
Lock - A held agent lock: the in-process
Mutexguard PLUS the cross-process lockfileLockClaim. Release order is enforced — lockfile claim first, in-process guard last (the guard field is dropped afterclaimis taken).
Enums§
- Family
- The lock “family” of an agent target — the set of locks a live agent must
hold so that NONE of its tags can be relocated (
tags apply) or have labs detached (laboratories detach) while it is active.
Functions§
- agent_
instance_ lock (lock_dir, key)for anagent_instance_hierarchy.- agent_
tag_ lock (lock_dir, key)for an agent tag.- family_
coords - Resolve a
Familyto its lock coordinates.Group→ a tag lock per group member;Hierarchy→ the AIH instance lock FIRST, then a tag lock per bound tag. - try_
acquire - Acquire an agent lock NON-BLOCKING. Returns
Noneif the key is busy in-process (another task holds the guard) OR held cross-process. On the cross-process miss the in-process guard is dropped before returning, so it never lingers. - try_
acquire_ all - Acquire EVERY coord NON-BLOCKING, all-or-nothing, concurrently.
Noneif any coord is busy (in-process guard taken OR cross-process held) — the ones that were acquired drop here, releasing them. Deadlock-free: every leg is a non-blockingtry, so acquisition order never matters. - try_
acquire_ family - Resolve + acquire a whole
FamilyNON-BLOCKING, all-or-nothing, and partition it for the registry (AIH lock split out from the tag locks).Ok(None)if any member is busy. Used by spawn / deliver, which resolve the family up front and acquire it in one shot. - wait_
acquire - Acquire an agent lock, BLOCKING at both layers: the in-process
Mutexfirst, then the cross-process lockfile.
Type Aliases§
- Agent
Lock Map - Per-key in-process gate for agent locks, keyed by the SAME
(dir, key)the lockfile uses. Lives oncrate::context::Context, shared across clones.