GovernanceGateway.execute() (src/gateway.ts):
- After identity, OWASP scanning, budget reservation, policy evaluation, and approval checks succeed, the gateway calls
this.config.auditLedger.append({ phase: 'pre_execution', ... }). - Only after
append()resolves does the gateway callawait executor(request). - If
auditLedger.append()throwsAuditLedgerUnavailableError(for example, PostgreSQL is unreachable or readonly),executor(request)is never invoked and the reserved workflow budget is released cleanly in thecatchblock.
Database Engine Immutability (001_audit_ledger.sql)
The schema migration at db/migrations/001_audit_ledger.sql enforces append-only semantics directly in PostgreSQL:
- Strict
CHECKconstraints onphase(pre_execution,post_execution,blocked,approval_transition,kill_switch),action_tier(read,propose,write), anddecision(allow,require_approval,deny,executed,failed). - Trigger
trg_audit_ledger_immutable(BEFORE UPDATE OR DELETE ON audit_ledger) invokesreject_audit_ledger_mutation(), raising a PostgreSQL exception (RAISE EXCEPTION 'audit_ledger is append-only: % operations are prohibited', TG_OP;). PostgresAuditLedger.append()runs inside a transaction withLOCK TABLE audit_ledger IN SHARE ROW EXCLUSIVE MODEso sequence numbers (seq) andprev_hash -> entry_hashchains remain strictly linear under concurrent workers.
Hash Chain Computation & Verification
Every record computes itsentry_hash from GENESIS_HASH ('0'.repeat(64)) forward via computeAuditEntryHash (src/audit-ledger.ts):
S3 Object Lock and GCS Retention Lock) with write-only runtime IAM permissions.