diff --git a/CHANGELOG.md b/CHANGELOG.md index ceb01f2..526183a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,14 @@ **Upgrade note:** a `-D` value that relied on a literal `${...}` is now resolved, as a file value always was; an unresolved reference without a default is no value, as in a file. +2. **The transcript audit store's PostgreSQL pool sets a server-side `statement_timeout` from + `llm.transcript.audit.postgres.timeout.ms`.** The live drive of 2026-11-17 (mercury-composable + `docs/test-reports/transcript-audit-live-drive.md`) showed a stopped database failing a write by type within the + connection timeout, as designed, but a paused one - a TCP black hole - holding the pooled connection's statement, and + with it the audit function's mailbox, for the outage's length. The statement now times out on the server after the + same `timeout.ms`, so a stalled database behaves like a stopped one: a logged failure, repaired by the sweep. In + lockstep with the Node pack. **Upgrade note:** none. + ## Version 4.12.30, 11/16/2026 The catch-up round with the engines: the pack moves from 4.12.21 to 4.12.30, the number the Java engine released on diff --git a/extensions/llm-helper/README.md b/extensions/llm-helper/README.md index ffda50d..091ed1c 100644 --- a/extensions/llm-helper/README.md +++ b/extensions/llm-helper/README.md @@ -310,7 +310,7 @@ installation's, applied on read. | `llm.transcript.audit.retention` | `365d` | Written as a conversation's `expires_at`; the purge is the installation's. | | `llm.transcript.audit.grace` | `1d` | How long a closed working record waits for its integrity check before it expires unreleased. | | `llm.transcript.audit.sweep.ms` | `60000` | The sweep that repairs lost events and stopped runs; `0` disables it. | -| `llm.transcript.audit.postgres.host`, `.port`, `.database`, `.username`, `.password`, `.ssl`, `.timeout.ms` | `127.0.0.1`, `5432`, `mercury`, none, none, `true`, `5000` | The PostgreSQL connection, the engines' convention under this store's prefix. The shipped `application.yml` sets the user and the password from the environment (`${POSTGRES_USER:mercury}`, `${POSTGRES_PASSWORD}`); `ssl` `true` is `sslmode=require`, `false` `sslmode=disable`. | +| `llm.transcript.audit.postgres.host`, `.port`, `.database`, `.username`, `.password`, `.ssl`, `.timeout.ms` | `127.0.0.1`, `5432`, `mercury`, none, none, `true`, `5000` | The PostgreSQL connection, the engines' convention under this store's prefix. The shipped `application.yml` sets the user and the password from the environment (`${POSTGRES_USER:mercury}`, `${POSTGRES_PASSWORD}`); `ssl` `true` is `sslmode=require`, `false` `sslmode=disable`; `timeout.ms` bounds a connection attempt, a wait for the pool and, on the server, a statement (`statement_timeout`). | The credential is never configured here. `ANTHROPIC_API_KEY` (or whatever the SDK resolves: an auth token, or a profile) comes from the environment for the Claude API; the AWS credential chain, diff --git a/extensions/llm-helper/dev/postgres-up.sh b/extensions/llm-helper/dev/postgres-up.sh index 766fe4e..b4860a8 100755 --- a/extensions/llm-helper/dev/postgres-up.sh +++ b/extensions/llm-helper/dev/postgres-up.sh @@ -22,7 +22,8 @@ docker run -d --name mercury-transcripts -p 5432:5432 \ -v "${here}/../schema/postgres.sql:/docker-entrypoint-initdb.d/transcript.sql:ro" \ postgres:17-alpine -docker run -d --name mercury-transcripts-browser -p 8081:8081 \ +# restarted on failure: the browser exits when its database goes away, and does not come back by itself +docker run -d --name mercury-transcripts-browser -p 8081:8081 --restart on-failure \ sosedoff/pgweb --url "postgres://mercury:${POSTGRES_PASSWORD}@host.docker.internal:5432/mercury?sslmode=disable" echo "PostgreSQL: 127.0.0.1:5432, database mercury, user mercury (the schema applies at first start)" diff --git a/extensions/llm-helper/llm_helper.py b/extensions/llm-helper/llm_helper.py index 09eb064..e7ab218 100644 --- a/extensions/llm-helper/llm_helper.py +++ b/extensions/llm-helper/llm_helper.py @@ -1601,7 +1601,8 @@ def _postgres_audit_store() -> PostgresAuditStore: from psycopg_pool import AsyncConnectionPool # the [postgres] extra; checked above prefix = "llm.transcript.audit.postgres." - timeout_s = _whole_number(prefix + "timeout.ms", _prop(prefix + "timeout.ms", "5000"), 1) / 1000 + timeout_ms = _whole_number(prefix + "timeout.ms", _prop(prefix + "timeout.ms", "5000"), 1) + timeout_s = timeout_ms / 1000 ssl = str(_prop(prefix + "ssl", "true")).lower() == "true" settings: dict[str, Any] = { "host": str(_prop(prefix + "host", "127.0.0.1")), @@ -1611,6 +1612,10 @@ def _postgres_audit_store() -> PostgresAuditStore: "password": _prop(prefix + "password") or None, "sslmode": "require" if ssl else "disable", "connect_timeout": max(1, round(timeout_s)), + # the server-side bound on a statement: a database that stalls (a paused container, a lock + # held) frees the function's mailbox after the timeout instead of holding it for the + # outage's length, as the live drive of 2026-11-17 showed a stopped one does by itself + "options": f"-c statement_timeout={timeout_ms}", } pool = AsyncConnectionPool( kwargs={key: value for key, value in settings.items() if value is not None}, diff --git a/memory/open-threads/thread-bp-transcript-audit-python.md b/memory/open-threads/thread-bp-transcript-audit-python.md index f086bb8..fb170b7 100644 --- a/memory/open-threads/thread-bp-transcript-audit-python.md +++ b/memory/open-threads/thread-bp-transcript-audit-python.md @@ -3,9 +3,14 @@ turn's facts, the store protocol's audit half on the memory and Redis stores, the `transcript.audit` function with one instance behind two local events (the write after every compare-and-set, the check behind a closing write), the sweep, PostgreSQL on psycopg 3 (the `postgres` extra), `schema/postgres.sql` and `purge.sql`, the `dev/` scripts on - Colima with pgweb, 28 tests and a live test. Verified live on the container. Open: the schema page in - mercury-composable (PR #639); the Node twin (mercury-nodejs) with the byte-identical schema files; the engines' `x-graph-id` and - `x-node` (step 3); the `order-assistant` drive with an injected write failure (step 4). The engines' memory tracks the + Colima with pgweb, 28 tests and a live test. Verified live on the container. The schema page (mercury-composable + #639), the Node twin (mercury-nodejs #126) and the engines' headers (#641, mercury #414) MERGED 2026-11-17. **Step 4 + DRIVEN 2026-11-17 through this helper:** three `order-assistant` conversations on Haiku 4.5 (one with PostgreSQL paused, + one stopped - the writes failed by type, the sweep repaired the open record 46 s after the restart) and the first two + turns of a conversation the Node helper then resumed from this helper's record; every turn in PostgreSQL with the + graph and the node, the Redis record released after each check (the report: mercury-composable + `docs/test-reports/transcript-audit-live-drive.md`, PR #642). Follow-up here: a server-side `statement_timeout` and + pgweb's restart policy (PR #62, pending). Open: that PR's merge; then RFC-0012's promotion is Eric's call. The engines' memory tracks the design under `transcript-audit-store` (RFC-0012, settled 2026-11-17). → serves: vision-mercury-python diff --git a/memory/sessions/2026-11-17-092707.md b/memory/sessions/2026-11-17-092707.md new file mode 100644 index 0000000..7a15fb2 --- /dev/null +++ b/memory/sessions/2026-11-17-092707.md @@ -0,0 +1,32 @@ +# Session (2026-11-17T09:27:07.000Z) + +**Agent:** Claude Code +**Title:** The audit store's live drive through this helper (RFC-0012 step 4), and its two follow-ups: a server-side +statement timeout and pgweb's restart policy + +## What We Did + +- **The drive (2026-11-17, the report in mercury-composable `docs/test-reports/transcript-audit-live-drive.md`).** This + helper on main after #61 with `llm.transcript.store=redis` and `llm.transcript.audit=postgres`, behind the Java + Playground's `order-assistant` on Haiku 4.5: three conversations and the first half of a fourth, every turn in + PostgreSQL with `order-assistant` / `assist` from the engine's headers, one correlation id and two trace ids each, the + Redis record released after each check; PostgreSQL stopped during a question failed two writes by type + (`AdminShutdown sqlstate=57P01`, `PoolTimeout`) and the sweep repaired the open record 46 s after the restart; the + Node helper resumed a conversation from this helper's version 2 record and wrote the same rows. +- **What the drive found here.** A *paused* database (a TCP black hole) stalled the pooled connection's statement, and + with it the audit function's mailbox, for the outage's length, while a *stopped* one failed within the connection + timeout as designed: `_postgres_audit_store` now passes `options=-c statement_timeout=`, so a stalled + database frees the mailbox after the same timeout (the tests pin the option; README row; CHANGELOG Changed). And + pgweb did not outlive its database's restart: `dev/postgres-up.sh` runs it with `--restart on-failure`. +- Gates: ruff clean, basedpyright 0 errors, pytest green. + +## Context for Next Session + +- **PR #62 OPENED 2026-11-17** on `fix/audit-statement-timeout`, in lockstep with the Node pack; Eric's review pending. + +## Memory References + +- Referenced: transcript-audit-store-python (the store this change bounds), bp-transcript-audit-python (edited: step 4 + driven, the follow-up) +- Created: (none) +- Superseded: (none) diff --git a/tests/test_transcript_audit.py b/tests/test_transcript_audit.py index dd0916a..830007b 100644 --- a/tests/test_transcript_audit.py +++ b/tests/test_transcript_audit.py @@ -705,6 +705,7 @@ def test_the_postgres_store_is_built_from_its_connection_keys( "password": "test-only-password", "sslmode": "disable", "connect_timeout": 2, + "options": "-c statement_timeout=2500", } assert (pool.min_size, pool.max_size, pool.timeout) == (1, 4, 2.5) assert store._timeout_s == 2.5 @@ -717,7 +718,7 @@ def test_the_postgres_store_is_built_from_its_connection_keys( pool = helper.get_audit_store()._pool assert pool.kwargs == { "host": "127.0.0.1", "port": 5432, "dbname": "mercury", "sslmode": "require", - "connect_timeout": 5, + "connect_timeout": 5, "options": "-c statement_timeout=5000", } # fmt: skip