Skip to content

Commit d9523dc

Browse files
authored
Merge pull request #129 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 8bf63ac + b732d65 commit d9523dc

7 files changed

Lines changed: 56 additions & 7 deletions

File tree

‎CHANGELOG.md‎

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

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

5058
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
@@ -315,7 +315,7 @@ of the box). The audit does not redact; a redaction policy is the installation's
315315
| `llm.transcript.audit.retention` | `365d` | Written as a conversation's `expires_at`; the purge is the installation's. |
316316
| `llm.transcript.audit.grace` | `1d` | How long a closed working record waits for its integrity check before it expires unreleased. |
317317
| `llm.transcript.audit.sweep.ms` | `60000` | The sweep that repairs lost events and stopped runs; `0` disables it. |
318-
| `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` encrypts without verifying the server's certificate (libpq's `sslmode=require`), `false` is `sslmode=disable`. A query waits at most `timeout.ms`. |
318+
| `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` encrypts without verifying the server's certificate (libpq's `sslmode=require`), `false` is `sslmode=disable`. `timeout.ms` bounds a connection attempt, a query on the client and, on the server, a statement (`statement_timeout`). |
319319

320320
The credential is never configured here. `ANTHROPIC_API_KEY` (or whatever the SDK resolves: an
321321
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.mjs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,11 @@ export async function postgresAuditStore(prop, { importer = (name) => import(nam
812812
ssl: ssl ? { rejectUnauthorized: false } : false,
813813
max: 4,
814814
connectionTimeoutMillis: timeoutMs,
815-
query_timeout: timeoutMs
815+
query_timeout: timeoutMs,
816+
// the server-side bound on a statement too: a database that stalls (a paused container, a lock
817+
// held) frees the function's mailbox after the timeout instead of holding it for the outage's
818+
// length, as the live drive of 2026-11-17 showed a stopped one does by itself
819+
statement_timeout: timeoutMs
816820
});
817821
// the pool reports an idle client's lost connection as an event; without a listener Node would stop
818822
pool.on('error', (error) => log.warn(`transcript audit store - ${error.name}: ${error.message}`));

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
stores, the `transcript.audit` function with one instance behind two local events (the write after every
55
compare-and-set, the check behind a closing write), the sweep, PostgreSQL on `pg` (a dev dependency),
66
`schema/postgres.sql` and `purge.sql` byte-identical with the Python pack, the `dev/` scripts on Colima with pgweb,
7-
28 tests and a live test; verified live on the container. Open: the engines' `x-graph-id` and
8-
`x-node` (step 3); the `order-assistant` drive through this helper (step 4). The engines' memory tracks the design
7+
28 tests and a live test; verified live on the container. The engines' headers (mercury-composable #641,
8+
mercury #414) MERGED 2026-11-17. **Step 4 DRIVEN 2026-11-17 through this helper:** a full `order-assistant` conversation
9+
on Haiku 4.5 with a refused decision, and the resume of a conversation the Python helper had started - this helper read
10+
the Python-written version 2 record, took the third turn, wrote the same rows and released the record; every turn in
11+
PostgreSQL with the graph and the node (the report: mercury-composable `docs/test-reports/transcript-audit-live-drive.md`).
12+
Follow-up here: a server-side `statement_timeout` beside the client's `query_timeout`, and pgweb's restart policy (PR #129,
13+
pending). Open: that PR's merge; then RFC-0012's promotion is Eric's call. The engines' memory tracks the design
914
under `transcript-audit-store` (RFC-0012, settled 2026-11-17; the schema page is mercury-composable #639).
1015
→ serves: vision-mercury-nodejs
1116
<!-- id: bp-transcript-audit-nodejs | created: 2026-11-17 | last_used: 2026-11-17 | uses: 1 | tier: working | origin: 2026-11-17-082942 -->
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Session (2026-11-17T09:27:53.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 #128 with `llm.transcript.store=redis` and `llm.transcript.audit=postgres`, behind the Java
11+
Playground's `order-assistant` on Haiku 4.5: a full conversation with a refused decision, and the resume of a
12+
conversation the Python helper had started - this helper loaded the Python-written version 2 record, took the third
13+
turn (2.3 s), wrote it and released the record, the three turn rows under two trace ids indistinguishable from a
14+
single-pack run; every conversation row with `order-assistant` / `assist` from the engine's headers.
15+
- **What the drive found.** A *paused* database stalled the Python helper's pooled statement for the outage's length
16+
while a *stopped* one failed within the connection timeout as designed; for parity this pool sets
17+
`statement_timeout: timeoutMs` beside the client's `query_timeout` (the tests pin it; README row; CHANGELOG Changed).
18+
pgweb did not outlive its database's restart: `dev/postgres-up.sh` runs it with `--restart on-failure`.
19+
- Gates: `npm test` green.
20+
21+
## Context for Next Session
22+
23+
- **PR #129 OPENED 2026-11-17** on `fix/audit-statement-timeout`, in lockstep with the Python pack; Eric's review pending.
24+
25+
## Memory References
26+
27+
- Referenced: transcript-audit-store-nodejs (the store this change bounds), bp-transcript-audit-nodejs (edited: step 4
28+
driven, the follow-up)
29+
- Created: (none)
30+
- Superseded: (none)

‎test/transcript-audit.test.mjs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,14 +637,15 @@ test('the postgres store is built from its connection keys', async () => {
637637
assert.equal(await audit(), store, 'built once');
638638
assert.deepEqual(seen.options, {
639639
host: 'postgres.internal', port: 5433, database: 'audit', user: 'transcript_writer', password: 'test-only-password',
640-
ssl: false, max: 4, connectionTimeoutMillis: 2500, query_timeout: 2500
640+
ssl: false, max: 4, connectionTimeoutMillis: 2500, query_timeout: 2500, statement_timeout: 2500
641641
});
642642
assert.equal(typeof seen.error, 'function', 'a lost connection must not stop the process');
643643
// the defaults: localhost, the mercury database, TLS on, no credential in a file
644644
await defaultAudit(settings({ 'llm.transcript.audit': 'postgres' }), { importer: async () => fakeModule, log: silent })();
645645
assert.deepEqual(seen.options, {
646646
host: '127.0.0.1', port: 5432, database: 'mercury', user: undefined, password: undefined,
647-
ssl: { rejectUnauthorized: false }, max: 4, connectionTimeoutMillis: 5000, query_timeout: 5000
647+
ssl: { rejectUnauthorized: false }, max: 4, connectionTimeoutMillis: 5000, query_timeout: 5000,
648+
statement_timeout: 5000
648649
});
649650
});
650651

0 commit comments

Comments
 (0)