rootsign.init() configures one agent for the whole process and builds the client that stores its records. Two jobs need more control: recording for several agents from one process, and writing records inside a database transaction you own. For both, pass the agent’s ID and an ingest client to rootsign.session() yourself. Everything inside the session, @rootsign.trace() and wrap_tools() included, then uses them. This page uses the PostgreSQL backend.
Arguments you pass always win over init(). A session given both agent_id= and client= needs no init() at all.
Record for several agents in one process
1
Register each agent once
register_agent() stores an agent and returns it. Registration is a one-time setup step, so run it once and keep the IDs. This script saves them to agents.json:register.py
2
Open a session per agent
Pass each agent’s ID, and a client, to
rootsign.session(). ManagedLocalIngestClient is the client init() uses on PostgreSQL: it commits each record as it is written.agents.py
3
Verify each session
The clear errors for registering an agent twice and for an unknown agent ID were added after RootSign 0.3.1. In 0.3.1 and earlier, a second
register_agent() failed with a raw IntegrityError, and a session for an unknown agent ran with every record refused.Write records inside your own transaction
LocalIngestClient(db=...) writes into an AsyncSession you own, and you decide when to commit:
own_transaction.py
- Nothing is visible until you commit. Another connection,
rootsign verifyincluded, sees no records from the session until then. - A rollback discards the whole session. Roll back instead of committing, and
rootsign verify <session_id>printsError: no session <session_id> in the databaseand exits3. - Calls cannot be held for approval. A held call’s pending record would stay uncommitted, so nobody could see it to approve it.
require_approval=Truewith this client raisesHiTLUnsupportedBackendErrorbefore anything is written. UseManagedLocalIngestClientfor held calls.
The approval error with your own transaction was added after RootSign 0.3.1. In 0.3.1 and earlier, the held call waited for an approval nobody could see, then failed with
ActionNotFoundError.Which client to use
Related
Python API
session(), its arguments and what it raises.Run on PostgreSQL
Start the database, create the tables and switch the backend.