6 Commits

Author SHA1 Message Date
Teknium
06f48b59e6 fix(caching): keep-alive accounting writes through the agent's storage handle
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.
2026-11-18 03:40:34 -08:00
yoniebans
be3d6affc8 refactor(state)!: remove the old session store
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.
2026-11-17 19:10:57 +01:00
yoniebans
0ad4d10151 refactor(persistence/sqlite): filter live delegations by state='running' only
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.
2026-11-17 17:49:49 +01:00
yoniebans
df48af627d feat(persistence): accept the prompt-cache clock in the SQLite usage.main receipt
The worker receipt's usage.main accepts prompt_cache_clock. The owner stamps its durable context generation (the archived-row count at commit) into a clock that decodes to a JSON object and re-encodes it compactly, inside the receipt transaction; any other text is stored as sent. The stamp is main's stamp_cache_generation, held beside the other receipt context operations.
2026-11-17 17:49:49 +01:00
yoniebans
045b4d7f74 feat(persistence/sqlite): completion delivery state on the delegation ledger
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.
2026-11-17 17:49:48 +01:00
yoniebans
70d8972759 feat(persistence/sqlite): the session authority and worker families
The SQLite implementation of the session authority, binding, coordination and worker contracts. The two families import each other, so they land in one commit.
2026-11-17 17:49:46 +01:00