The owner stamps each turn with the label its connection announced
(`surface_v1.client`). That label names the connection, not the request: an
app updated between a send and its retry announces another version, and a
reconnect may not have said hello yet. Including it in the digest turned such
a retry into `admission_conflict`.
`retry_input` (beside `admission_fingerprint`) drops the stamp, and an empty
`surface_v1` with it, from the input the admission digest covers. It is used
wherever the store computes that digest: admit, the retired-target retry, and
the two re-keying writes (rehome, automation retarget), plus the in-memory
reference backend, so every backend keeps one definition. The stored payload
keeps the stamp, so the first row's label is the one kept. A payload without
a stamp is digested exactly as before, so existing rows keep their digests.
Any other difference (text, a HUD surface) is still a conflict.
Main's persistence interface makes the agent's store a storage handle with no
queue_token_counts; the warmer's keep-alive accounting called it on
agent._session_db directly and silently lost every refresh's usage. It now goes
through turn_usage.queue_usage, which takes the handle's usage repository (and
the worker store otherwise) with the session id and surface the keep-alive
captured when it was scheduled.
Main's backend holds the writer mutex helpers in one module beside the store; at this level that module is persistence/sqlite/_state/write.py, where _holder.py already imports them from.
F22 (sqlite-backend) added `from hermes_state_write import write_site, writer_mutex_until` to persistence/sqlite/authority/coordination.py while hermes_state_write.py still existed. The replayed removal commit deletes hermes_state_write.py and did not move that import, so at this level every import of the authority package raised ModuleNotFoundError: 25 of the 34 stand-in cases failed with it.
The import now names persistence.sqlite._state.write, the same objects _holder.py uses.
Proof: tests/test_hermes_state_standin.py at 1b486ca4e2: 25 cases fail on ModuleNotFoundError: No module named 'hermes_state_write'; with this change none does (the 6 left are F20's TypeError, fixed next). tests/scripts/test_check_backend_imports.py 30 passed both ways. Import-only check of the module passes; ruff clean.
hermes_state.py becomes the stand-in plugins import, the rest of the legacy store and its test folder go, and the per-process modules the backend imported from main move under persistence/sqlite/_state/. The backend checks PID namespaces and lease holders through process_identity and its WAL setup through sqlite_support, and its error module takes the shared predicates and classification from storage_errors, so neither helper set has a second copy. The backend, sqlite_support.py and the tests that pin those modules reach their final imports, and the backend-import guard allows no file outside persistence/. The modules no caller imports any more go with it: the agent's onboarding rules (now in session_rules) and gateway/session_admission.py.
The stand-in's SessionDB releases its store on close() and, used again afterwards, opens it again with a warning, as the old class reopened its connection, unless the file at its path was replaced or the store is latched corrupt; a read-only one raises. A close during a call releases the store when the call returns. A named source wins over a source list in its session listing and count.
An agent given a writable stand-in SessionDB as session_db= and no persistence= takes the store handle that SessionDB forwards to as its persistence, so its turn flush, token counts, compression and session row writes go through the storage interface, as an agent given the old SessionDB wrote through it.
The backend-import guard also holds the backend's remaining reads of the process or task home, each with its reason, and refuses any other and any import of the stand-in inside persistence/sqlite/.
Plugin context engines get the agent's store as persistence= beside the deprecated session_db=, in each hook whose signature accepts that keyword, including the rebind after /new, /resume and /branch, and the context engine guide and the plugin guide's replacement table name it. A test fails once the running release reaches the stand-in's removal release, listing what goes with the stand-in.
release_unheld_media and collect_unheld_api_images take a store only: their SessionDB branches, which no caller reaches, go with the gateway's own copies of the admission and transcript queries.
_ledger_setup took the process-wide setup lock and the holder's writer lock with bare with blocks, and its deadline covered only the retry loop: a long write elsewhere held the setup, and every ledger verb behind it, with no bound. Both locks are now taken against that deadline, the writer lock through writer_mutex_until as every write takes it, so a held lock refuses the setup with StoreContention, which the existing retry loop and callers already handle. A case holds the writer lock from another thread and asserts the setup refuses within the wait and runs nothing; it hung before the fix.
Reported-by: Greptile
Reported-by: unsupportedpastels
The four turn-lease verbs called self._store.holder() inside their write transaction to find the conversation key. After a profile sweep (close_all_under) cleared the holder's registry ownership, that call reacquired from the registry, which waits on the sweep's teardown, which waits on the write lock the transaction holds: a deadlock. Main's lease writes resolve nothing inside the transaction. Each verb now resolves the holder once before the write and the closure uses that object, so a sweep during the write completes after it. A case starts a profile sweep from inside the write of try_acquire, refresh and release, and asserts both finish; it hung before the fix (stopped by its recorded pid after 150 s) and passes after. The only other in-closure holder calls in the backend are the topic reads' lambdas in gateway/routing.py, which run outside any transaction.
Reported-by: Greptile
Reported-by: unsupportedpastels
The interface's gate may now be a callable over owner memory, answered at the gate's fixed point inside the write, so a drain that began while the write waited on the writer still refuses it, as main's in-transaction guard does. The SQLite backend's three gate points (admit after the queue cap, claim after the epoch fence, bind_api after the epoch fence) now call raise_gate inside the write closure that _execute_write retries, so the callable is answered again on every busy retry. A decided GateRefusal or None behave as before.
Reported-by: kshitijk4poor
The SQLite ledger matches the contract: every in-flight filter on `async_delegations` (prune counts and deletes, the orphan sweep and its reads, the finished read, the in-flight read) and the worker delivery claim test `state='running'` or `state!='running'`, since no writer stores `finalizing`. The abandoned-delegation recovery parity case now expects the one running row recovered.
The compress mutation's rotation publishes a new live segment; the conversation's name now follows it onto that segment (_title_follows_head), as an automatic rotation's does, so the listing and the CLI keep showing it after a manual /compress.
The SQLite mutation's title write goes to the live tip of the addressed row's compression chain and reads the receipt's title there. A committed write adds every row of the lineage, and the row the uniqueness rule freed the name from, to the affected set, so each segment's revision advances. A clear empties every row of the lineage through the same title rules, so the hidden canonical Bot Chat's name refuses.
The backend's begin_runtime_epoch now runs main's owner guard before the bump: while another process holds the profile's gateway.lock, the bump raises AuthorityRefusal('ownership_conflict', field='runtime_epoch') and the owner's epoch stays where it was. A reservation this process holds grants the bump, the flock decides rather than the lock record, and a store with no directory of its own never refuses.
Main's ownership cases run against the backend's runtime.begin_epoch.
The session's newest admission carrying a top-level payload marker: one SELECT per status in the table's CHECK order, each walking the (target, status, seq) index newest first, merged by seq with heapq.merge and stopped at the first row whose decoded payload holds the marker. Every cursor is closed before the read connection goes back.
A SQLite-only test counts the rows read from the cursors: an early match reads two rows of a thirty-two row history, a miss reads all of them, and no cursor is left open at the end of the read context.
prune_delegation_ledger carries main's KEEP_WAITING_UNITS_SQL: the unit row of a resumable or expired subagent record still owed its report is neither deleted by the retention nor counted or deleted by the terminal cap, because the child's give-up is routed through it; the pending cap counts and deletes it like any row, as main's _prune_durable_records does.
record_delegation_completion stores the delivery it is given (pending, or delivered for a unit whose every child waits on a promised automatic resume: recorded, never offered) and refuses another value invalid_params with nothing written. The boot recovery stores each recovery's delivery. The worker gateway's delegation.complete accepts main's optional delivery key, refuses a value outside pending and delivered invalid_params, and writes it to the row as main's _complete does.
The SubagentLedger verbs on the SQLite coordination repository, in a new persistence/sqlite/authority/subagents.py mixed into SQLiteCoordinationRepository. Each verb carries main's statements from tools/delegate_tool_resumable.py and tools/delegate_tool_auto_resume.py with their binding order: the upsert and the limits pass, the checkpoint, the gateway-shutdown mark, the continue claim and hand-back, the note, the expired and manual-claim cancels, the automatic claim, start, confirm and refusal settlement, the give-up with its failed completion row, the supersession of a session's children and the dismissal. Policy and owner identity arrive as parameters.
A write computed from a record the caller read (a run record, a dismissal, an automatic run's start) compares the stored row with that record inside its own write and answers a lost write with nothing written. The parent-supersession check walks the compression chain on the verb's connection. A give-up whose unit row changed since the caller built its completion rolls back and answers route_moved.
recover_abandoned_delegations takes the subagent recoveries and limits and writes them first in its own transaction, each only while the record is still running or claimed by its dead owner.
A verb for a profile whose store was removed answers as a write that did nothing and creates nothing, since the store's opener refuses a missing home. The worktree sweep's pinned read and the owed probe read through their own read-only connection, as main does, and never create or write the store.
With require_settled, request_handoff runs the settled check first inside its own write, before the in-flight check, as main's request_handoff runs its guard: the store's require_idle over the runtime lineage in sorted order, a held turn lease or compression lock refusing session_busy and an unknown or busy execution refusing with its own reason as HandoffUnsettled, anything else re-raised. check_handoff_settled runs the same check in a write transaction for the watcher and writes nothing.
Session maintenance and the authority runtime guards each carried their own copy of _non_continuation_child_sql. Both now import the one in the conversation store's sql_common, which compression and the session reads already use, so a lineage fix reaches pruning, deletion and compression together. The statements built are unchanged byte for byte.
The SQLite implementation of the session authority, binding, coordination and worker contracts. The two families import each other, so they land in one commit.