Skip to content

Commit c60a43b

Browse files
authored
Merge pull request #62 from Accenture/fix/audit-statement-timeout
fix(llm-helper): a server-side statement_timeout on the audit store's pool; pgweb restarted on failure
2 parents ddbc2d1 + f491977 commit c60a43b

7 files changed

Lines changed: 59 additions & 7 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@
4444
**Upgrade note:** a `-D` value that relied on a literal `${...}` is now resolved, as a file value always was; an
4545
unresolved reference without a default is no value, as in a file.
4646

47+
2. **The transcript audit store's PostgreSQL pool sets a server-side `statement_timeout` from
48+
`llm.transcript.audit.postgres.timeout.ms`.** The live drive of 2026-11-17 (mercury-composable
49+
`docs/test-reports/transcript-audit-live-drive.md`) showed a stopped database failing a write by type within the
50+
connection timeout, as designed, but a paused one - a TCP black hole - holding the pooled connection's statement, and
51+
with it the audit function's mailbox, for the outage's length. The statement now times out on the server after the
52+
same `timeout.ms`, so a stalled database behaves like a stopped one: a logged failure, repaired by the sweep. In
53+
lockstep with the Node pack. **Upgrade note:** none.
54+
4755
## Version 4.12.30, 11/16/2026
4856

4957
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

‎extensions/llm-helper/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ installation's, applied on read.
310310
| `llm.transcript.audit.retention` | `365d` | Written as a conversation's `expires_at`; the purge is the installation's. |
311311
| `llm.transcript.audit.grace` | `1d` | How long a closed working record waits for its integrity check before it expires unreleased. |
312312
| `llm.transcript.audit.sweep.ms` | `60000` | The sweep that repairs lost events and stopped runs; `0` disables it. |
313-
| `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`. |
313+
| `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`). |
314314

315315
The credential is never configured here. `ANTHROPIC_API_KEY` (or whatever the SDK resolves: an
316316
auth token, or a profile) comes from the environment for the Claude API; the AWS credential chain,

‎extensions/llm-helper/dev/postgres-up.sh‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ docker run -d --name mercury-transcripts -p 5432:5432 \
2222
-v "${here}/../schema/postgres.sql:/docker-entrypoint-initdb.d/transcript.sql:ro" \
2323
postgres:17-alpine
2424

25-
docker run -d --name mercury-transcripts-browser -p 8081:8081 \
25+
# restarted on failure: the browser exits when its database goes away, and does not come back by itself
26+
docker run -d --name mercury-transcripts-browser -p 8081:8081 --restart on-failure \
2627
sosedoff/pgweb --url "postgres://mercury:${POSTGRES_PASSWORD}@host.docker.internal:5432/mercury?sslmode=disable"
2728

2829
echo "PostgreSQL: 127.0.0.1:5432, database mercury, user mercury (the schema applies at first start)"

‎extensions/llm-helper/llm_helper.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,8 @@ def _postgres_audit_store() -> PostgresAuditStore:
16011601
from psycopg_pool import AsyncConnectionPool # the [postgres] extra; checked above
16021602

16031603
prefix = "llm.transcript.audit.postgres."
1604-
timeout_s = _whole_number(prefix + "timeout.ms", _prop(prefix + "timeout.ms", "5000"), 1) / 1000
1604+
timeout_ms = _whole_number(prefix + "timeout.ms", _prop(prefix + "timeout.ms", "5000"), 1)
1605+
timeout_s = timeout_ms / 1000
16051606
ssl = str(_prop(prefix + "ssl", "true")).lower() == "true"
16061607
settings: dict[str, Any] = {
16071608
"host": str(_prop(prefix + "host", "127.0.0.1")),
@@ -1611,6 +1612,10 @@ def _postgres_audit_store() -> PostgresAuditStore:
16111612
"password": _prop(prefix + "password") or None,
16121613
"sslmode": "require" if ssl else "disable",
16131614
"connect_timeout": max(1, round(timeout_s)),
1615+
# the server-side bound on a statement: a database that stalls (a paused container, a lock
1616+
# held) frees the function's mailbox after the timeout instead of holding it for the
1617+
# outage's length, as the live drive of 2026-11-17 showed a stopped one does by itself
1618+
"options": f"-c statement_timeout={timeout_ms}",
16141619
}
16151620
pool = AsyncConnectionPool(
16161621
kwargs={key: value for key, value in settings.items() if value is not None},

‎memory/open-threads/thread-bp-transcript-audit-python.md‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
turn's facts, the store protocol's audit half on the memory and Redis stores, the `transcript.audit` function with
44
one instance behind two local events (the write after every compare-and-set, the check behind a closing write), the
55
sweep, PostgreSQL on psycopg 3 (the `postgres` extra), `schema/postgres.sql` and `purge.sql`, the `dev/` scripts on
6-
Colima with pgweb, 28 tests and a live test. Verified live on the container. Open: the schema page in
7-
mercury-composable (PR #639); the Node twin (mercury-nodejs) with the byte-identical schema files; the engines' `x-graph-id` and
8-
`x-node` (step 3); the `order-assistant` drive with an injected write failure (step 4). The engines' memory tracks the
6+
Colima with pgweb, 28 tests and a live test. Verified live on the container. The schema page (mercury-composable
7+
#639), the Node twin (mercury-nodejs #126) and the engines' headers (#641, mercury #414) MERGED 2026-11-17. **Step 4
8+
DRIVEN 2026-11-17 through this helper:** three `order-assistant` conversations on Haiku 4.5 (one with PostgreSQL paused,
9+
one stopped - the writes failed by type, the sweep repaired the open record 46 s after the restart) and the first two
10+
turns of a conversation the Node helper then resumed from this helper's record; every turn in PostgreSQL with the
11+
graph and the node, the Redis record released after each check (the report: mercury-composable
12+
`docs/test-reports/transcript-audit-live-drive.md`, PR #642). Follow-up here: a server-side `statement_timeout` and
13+
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
914
design under `transcript-audit-store` (RFC-0012, settled 2026-11-17).
1015
→ serves: vision-mercury-python
1116
<!-- id: bp-transcript-audit-python | created: 2026-11-17 | last_used: 2026-11-17 | uses: 1 | tier: working | origin: 2026-11-17-080036 -->
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Session (2026-11-17T09:27:07.000Z)
2+
3+
**Agent:** Claude Code
4+
**Title:** The audit store's live drive through this helper (RFC-0012 step 4), and its two follow-ups: a server-side
5+
statement timeout and pgweb's restart policy
6+
7+
## What We Did
8+
9+
- **The drive (2026-11-17, the report in mercury-composable `docs/test-reports/transcript-audit-live-drive.md`).** This
10+
helper on main after #61 with `llm.transcript.store=redis` and `llm.transcript.audit=postgres`, behind the Java
11+
Playground's `order-assistant` on Haiku 4.5: three conversations and the first half of a fourth, every turn in
12+
PostgreSQL with `order-assistant` / `assist` from the engine's headers, one correlation id and two trace ids each, the
13+
Redis record released after each check; PostgreSQL stopped during a question failed two writes by type
14+
(`AdminShutdown sqlstate=57P01`, `PoolTimeout`) and the sweep repaired the open record 46 s after the restart; the
15+
Node helper resumed a conversation from this helper's version 2 record and wrote the same rows.
16+
- **What the drive found here.** A *paused* database (a TCP black hole) stalled the pooled connection's statement, and
17+
with it the audit function's mailbox, for the outage's length, while a *stopped* one failed within the connection
18+
timeout as designed: `_postgres_audit_store` now passes `options=-c statement_timeout=<timeout.ms>`, so a stalled
19+
database frees the mailbox after the same timeout (the tests pin the option; README row; CHANGELOG Changed). And
20+
pgweb did not outlive its database's restart: `dev/postgres-up.sh` runs it with `--restart on-failure`.
21+
- Gates: ruff clean, basedpyright 0 errors, pytest green.
22+
23+
## Context for Next Session
24+
25+
- **PR #62 OPENED 2026-11-17** on `fix/audit-statement-timeout`, in lockstep with the Node pack; Eric's review pending.
26+
27+
## Memory References
28+
29+
- Referenced: transcript-audit-store-python (the store this change bounds), bp-transcript-audit-python (edited: step 4
30+
driven, the follow-up)
31+
- Created: (none)
32+
- Superseded: (none)

‎tests/test_transcript_audit.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ def test_the_postgres_store_is_built_from_its_connection_keys(
705705
"password": "test-only-password",
706706
"sslmode": "disable",
707707
"connect_timeout": 2,
708+
"options": "-c statement_timeout=2500",
708709
}
709710
assert (pool.min_size, pool.max_size, pool.timeout) == (1, 4, 2.5)
710711
assert store._timeout_s == 2.5
@@ -717,7 +718,7 @@ def test_the_postgres_store_is_built_from_its_connection_keys(
717718
pool = helper.get_audit_store()._pool
718719
assert pool.kwargs == {
719720
"host": "127.0.0.1", "port": 5432, "dbname": "mercury", "sslmode": "require",
720-
"connect_timeout": 5,
721+
"connect_timeout": 5, "options": "-c statement_timeout=5000",
721722
} # fmt: skip
722723

723724

0 commit comments

Comments
 (0)