Skip to content

feat(llm-helper): the transcript audit store - the Node twin of the Python pack's build (RFC-0012) - #126

Merged
acn-ericlaw merged 2 commits into
mainfrom
feat/transcript-audit-store
Nov 17, 2026
Merged

acn-ericlaw merged 2 commits into
mainfrom
feat/transcript-audit-store

Conversation

@acn-ericlaw

Copy link
Copy Markdown
Contributor

What

RFC-0012 build plan step 2: the Node twin of mercury-python #59, field for field.

  • Record version 2. transcript(fields) fills the Python dataclass's defaults; recordJson writes v: 2 in the Python key order with each turn's facts (trace id and path, correlation id, the model call's UTC bounds, status, stop reason, request id, usage, messages: [first request message, response]), the first turn's system prompt, catalog, correlation id and the loop's x-graph-id / x-node, and the closing retention, all inside the compare-and-set; recordFrom still reads version 1. The 66 shared loop vectors pass unchanged.
  • transcript.audit, a private composable function with ONE instance, registered at boot when llm.transcript.audit: postgres is configured. After every accepted turn llm.chat sends {conversation, turn} through a local PostOffice.send; a closing turn adds {conversation, check: true} behind it. The function reads the record and writes the rows the store lacks in one transaction; the check releases a closed record to its retention only after the audit holds every turn, and marks it; an open record is only filled. Until the check, a closed record waits with llm.transcript.audit.grace (1d). A sweep (llm.transcript.audit.sweep.ms, 60 s, one replica per interval on Redis) sends a check for every record whose audited mark lags. A failed write is logged by type and SQLSTATE, never by content, and never refuses a turn.
  • The stores. The working stores gain the audit half (audited, markAudited, release, unaudited, sweepLock): Redis keeps audited as a third hash field the compare-and-set never touches, set by a Lua that never resurrects a released record; the sweep reads two fields per record over scanIterator pages. PostgresAuditStore on pg.Pool (the new dev dependency, like the SDK and redis); $n placeholders, JSON as text cast to jsonb, stamps as text cast to timestamptz - the same statements as the Python pack. MemoryAuditStore holds the reference semantics for tests and parity.
  • Files. extensions/llm-helper/schema/postgres.sql and purge.sql, byte-identical with the Python pack; dev/postgres-up.sh (postgres:17-alpine + pgweb on 8081), postgres-down.sh, audit-purge.sh; the audit keys in application.yml (the database user and password from the environment, since a -D value is never substituted); README "The audit store"; CHANGELOG Unreleased Added 1.
  • Tests. The helper's fakes move to test/fixtures/llm-helper-fakes.mjs, shared by both helper test files; test/transcript-audit.test.mjs has the Python file's 28 cases one for one plus the live test gated on LLM_TRANSCRIPT_AUDIT_TEST_URL. npm test: 498 tests, 433 passed, 0 failed, 65 skipped. Verified live on Colima: the live test green on the container, the purge dry run, the containers removed.

Why

The two helpers must write the same rows from the same record, since a Node helper and a Python helper on one Redis serve the same conversations (the loop contract's requirement, ADR-0033). This is the lockstep step of RFC-0012's build plan, holding to the Python build's precisions recorded in the design spec's section 14 (constant JSON shapes for request and response; a closed record's mark set by its check after the release; any closed record waiting with the grace; the statement order and the text casts). The one Node-specific decision: ssl: true maps to { rejectUnauthorized: false }, the twin of libpq's sslmode=require, so a managed database's private CA works out of the box, documented in the README.

Next: the -D environment-variable substitution in all four runtimes (Eric's request), then the engines' two headers and the order-assistant drive.

🤖 Generated with Claude Code

Co-Authored-By: Claude Fable 5.1 noreply@anthropic.com

acn-ericlaw and others added 2 commits November 17, 2026 16:29
…ython pack's build (RFC-0012)

Record version 2 carries each turn's facts inside the compare-and-set; llm.chat sends a write event
after every accepted turn and the integrity check behind a closing turn to transcript.audit, a private
function with one instance that fills what PostgreSQL lacks and releases the working record only after
the check; a sweep repairs lost events and stopped runs. pg as a dev dependency, the schema and purge
files byte-identical with the Python pack, the development setup on Colima with pgweb, 28 tests and a
live test; the helper's test fakes shared through a fixture.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…twin built, PR #126 opened

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@acn-ericlaw
acn-ericlaw merged commit 9d2d397 into main Nov 17, 2026
5 checks passed
acn-ericlaw added a commit that referenced this pull request Nov 17, 2026
… as landed

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@acn-ericlaw
acn-ericlaw deleted the feat/transcript-audit-store branch November 18, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant