Skip to main content

tombstone_key_names

Function tombstone_key_names 

Source
pub(super) fn tombstone_key_names(
    conn: &Connection,
    id: &str,
) -> Result<(), StoreError>
Expand description

Every table keyed to an agent id that a deleted db_agents row leaves behind, purged explicitly (docs/specs/SPEC_AGENT_DELETE_2026_09_16.md §5.1). Called with the caller’s connection lock already held, inside the same critical section as the db_agents DELETE. Returns rows removed.

Six of these declare ON DELETE CASCADE on db_agents(id) and do fire on their own — configure_and_migrate sets PRAGMA foreign_keys=ON on the production connection, contrary to §5.1’s premise (and to managed.rs’s “only ever set in tests” comment, which is stale for this store). They are listed anyway: the rest carry no FK at all — db_agent_credentials and the two signing-key tables hold live secret material, so leaving them behind is a security-hygiene gap, not just clutter — and one obviously-complete list beats two half-lists where a reader has to know which half a new table belongs in to tell whether it was handled.

Runs against either physical database. Four of these (db_agent_identity_links, db_agent_credentials, db_agent_native_memory, db_agent_native_memory_versions) are created by BOTH run_object_schema and run_identity_store_schema, and per SPEC_IDENTITY_STORE_SPLIT_2026_08_17.md the identity store holds the live rows — listrecentsessions reads links from identity_store.agent_identity_list_all(), not from the object store’s same-named table. Purging only the object store would leave an agent’s real credentials and account links on disk after a delete that promises to remove them. Tables absent from whichever connection this runs on are skipped, so one list serves both.

db_work_queue.target_agent is deliberately absent: releasing work claimed against a deleted agent is a state change, not a row to drop — open question §8.3 of the spec above. Record the lowercased names id is known by — the keys its legacy name-keyed signing keys may sit under — in db_agent_key_tombstones, before its row is deleted (identity M4a, spec §6.5.4). A template row is skipped: templates are never deleted through here as agents, and their names are shared by design. Idempotent; a missing row records nothing.