CONTRACT · SPEC V0.1
Contract (spec v0.1)
Normative actor schema, unpadded base64url sqlcommenter transport, size limits, and language-neutral conformance fixtures.
The engine repository owns the normative spec/ directory, versioned independently with SemVer starting at 0.1.0. Every adapter declares which spec version it implements and verifies compliance against shared JSON conformance fixtures.
Actor & context schema
{
"type": "ai_agent",
"id": "billing-agent",
"onBehalfOf": { "type": "user", "id": "usr_42" },
"tenant": "org_acme"
}
typeMUST be one ofuser,api_key,ai_agent,service, orsystem.idMUST be present.onBehalfOfMAY hold one nested actor, one level deep (for delegated actions such as an AI agent acting for a user).tenantMAY be present.- IDs only by default. Names, emails, and IP addresses SHOULD NOT be sent because SQL comments appear in
pg_stat_activity, server logs, andpg_stat_statements.contextMAY carryrequestIdandsource; IP and user agent are opt-in. - 512-byte cap. Serialized actor plus context JSON MUST NOT exceed 512 bytes.
SQL transport format
-- Per statement: trailing sqlcommenter tag (default)
UPDATE invoice SET status = $1 WHERE id = $2 /*auditstream='eyJ0eXBlIjoidXNlciIsImlkIjoidXNyXzQyIn0'*/
-- Per transaction: set_config fallback
SELECT set_config('auditstream.actor', '{"type":"user","id":"usr_42"}', true);
Transport guarantees
- Injection-proof encoding: The comment value MUST be unpadded base64url. Because base64url contains only
A-Z,a-z,0-9,-, and_, it can never contain*/or break out of the SQL comment. - Trailing position: The comment MUST be the last comment in the statement and MAY share a comment with other
sqlcommenterkeys such astraceparent. - No named prepared statements with per-actor comments: Each distinct comment string produces a new prepared statement that
node-postgresnever evicts, so driver wrappers strip statement names when appending a tag. - Spoofing resistance: Comment-like text inside SQL string literals was tested twice and ignored in both cases.