Implementation:1ay1 Agentty Lock Ordering Types
| Knowledge Sources | |
|---|---|
| Domains | Concurrency, Type_System |
| Last Updated | 2026-10-28 12:00 GMT |
Overview
Lock ordering ranks as types the compiler checks, so two locks can only nest in rank order and deadlocks are unrepresentable.
Description
The agentty::lock_levels module defines the order agentty's locks are taken in, as TYPES. Every `maya::guarded<T, Rank>` names its rank. Taking it needs a capability proving every lock the thread holds ranks LOWER. A function that takes a lock ranked R declares `const maya::below<R>&`, and its callers must be able to produce one — so a call made from inside a lock ranked >= R does not compile, wherever it is in the call graph.
Ranks (outermost first): mcp_connecting(10), copilot_auto(12), auth_refresh(15), cred_file(17), rag_index(20), memory_store(25), thread_log(28), file_lane(30), worker_slot(35), writer_state(40), settings_cache(40). Most locks are leaves (default): their body takes nothing. A value read far more often than it changes uses `maya::snapshot` (no lock, no rank).
Usage
Import this when you need to: declare a lock rank, declare a capability parameter (`below<R>`) for a function that takes locks, or reference lock ranks in function signatures.
Code Reference
Source Location
- Repository: 1ay1_Agentty
- File: include/agentty/util/lock_levels.hpp
- Lines: 1-97
Signature
namespace agentty::lock_levels {
using mcp_connecting = maya::rank<10, "mcp.connecting">;
using copilot_auto = maya::rank<12, "copilot.auto_session">;
using auth_refresh = maya::rank<15, "auth.refresh">;
using cred_file = maya::rank<17, "auth.cred_file">;
using rag_index = maya::rank<20, "rag.index">;
using memory_store = maya::rank<25, "memory.store">;
using thread_log = maya::rank<28, "persistence.thread_log">;
using file_lane = maya::rank<30, "persistence.file_lane">;
using worker_slot = maya::rank<35, "worker_slot">;
using writer_state = maya::rank<40, "persistence.writer_state">;
using settings_cache = maya::rank<40, "settings_cache.state">;
// Parameter types:
using below_mcp_connecting = maya::below<mcp_connecting>;
using below_auth_refresh = maya::below<auth_refresh>;
using below_cred_file = maya::below<cred_file>;
using below_file_lane = maya::below<file_lane>;
using below_leaf = maya::below<maya::leaf>;
// ... etc for every rank
}
namespace agentty {
using maya::unlocked;
using maya::held;
using maya::below;
namespace locks = lock_levels;
}
Import
#include "agentty/util/lock_levels.hpp"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| Rank | maya::rank<N, tag> | Yes | Compile-time lock ordering level |
Outputs
| Name | Type | Description |
|---|---|---|
| below<R> | capability | "my caller holds only ranks < R" — parameter for functions taking locks |
| unlocked | capability | "the thread holds nothing" |
Usage Examples
Declare a Function That Takes a Lock
#include "agentty/util/lock_levels.hpp"
// This function takes the auth_refresh lock, so it requires a capability
// proving the caller holds only ranks BELOW auth_refresh:
void refresh_token(const agentty::locks::below_auth_refresh& cap,
const std::string& provider);
// Caller inside a file_lane section (rank 30 > 15) — COMPILE ERROR:
// void caller(const agentty::held<agentty::locks::file_lane>& h) {
// refresh_token(h, "anthropic"); // won't compile: file_lane >= auth_refresh
// }
// Caller holding nothing — OK:
void caller(agentty::unlocked u) {
refresh_token(u, "anthropic");
}