Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(GBRA-130 A-5): a publication lock timeout (55P03) stays transient contention, uncounted; only a statement timeout (57014) is charged
garrytan3e76ff04415a
diff --git a/docs/guides/error-codes.md b/docs/guides/error-codes.mdindex 8125f42695..34c6036436 100644--- a/docs/guides/error-codes.md+++ b/docs/guides/error-codes.md@@ -2826,7 +2826,7 @@ More: [docs/guides/repair.md#projection-owner-resident](../../docs/guides/repair| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable ||---|---|---|---|---|---|---|-| A managed write's publication transaction hit its statement or lock timeout persistence.max_preparation_attempts times (default 2), so the owner finished it failed instead of claiming it again; nothing was committed. | A publication that times out on every attempt (a very large page or fact batch, or a slow lookup inside the 5-second publication transaction) used to be released as database_contention without being counted and claimed again forever, holding every later write on its root. Each timeout now counts one attempt and the write is terminal at the limit, so the rest of the root keeps moving. | Report the request id, the size the receipt names and gbrain sources writer status --source <id> --json; a smaller write (split the page or batch) needs a new request_id. Run: gbrain sources writer status --source '{source_id}' --json | host_admin | `gbrain doctor --json` | 1 | no |+| A managed write's publication transaction hit its statement timeout persistence.max_preparation_attempts times (default 2), so the owner finished it failed instead of claiming it again; nothing was committed. | A publication that times out on every attempt (a very large page or fact batch, or a slow lookup inside the 5-second publication transaction) used to be released as database_contention without being counted and claimed again forever, holding every later write on its root. Each timeout now counts one attempt and the write is terminal at the limit, so the rest of the root keeps moving. | Report the request id, the size the receipt names and gbrain sources writer status --source <id> --json; a smaller write (split the page or batch) needs a new request_id. Run: gbrain sources writer status --source '{source_id}' --json | host_admin | `gbrain doctor --json` | 1 | no |More: [docs/guides/write-refusals.md#publication_timeout](../../docs/guides/write-refusals.md#publication_timeout)diff --git a/src/core/error-registry.ts b/src/core/error-registry.tsindex d1bec57b10..290ca00b2a 100644--- a/src/core/error-registry.ts+++ b/src/core/error-registry.ts@@ -472,7 +472,7 @@ export const CODES = {fix: { argv: ['gbrain', 'sources', 'status', '{source_id}', '--json'], consent: [], actor: 'host_admin', why: 'Read-only: lists the held files of the source with their repair route.', requires_exclusive: false } },preview_changed: { class: 'caller', summary: "The state changed since the approved preview." },publication_timeout: { class: 'server', retryable: false, actor: 'host_admin',- summary: "A managed write's publication transaction hit its statement or lock timeout persistence.max_preparation_attempts times (default 2), so the owner finished it failed instead of claiming it again; nothing was committed.",+ summary: "A managed write's publication transaction hit its statement timeout persistence.max_preparation_attempts times (default 2), so the owner finished it failed instead of claiming it again; nothing was committed.",why: 'A publication that times out on every attempt (a very large page or fact batch, or a slow lookup inside the 5-second publication transaction) used to be released as database_contention without being counted and claimed again forever, holding every later write on its root. Each timeout now counts one attempt and the write is terminal at the limit, so the rest of the root keeps moving.',docs: 'docs/guides/write-refusals.md#publication_timeout',suggestion: 'Report the request id, the size the receipt names and gbrain sources writer status --source <id> --json; a smaller write (split the page or batch) needs a new request_id.',diff --git a/src/core/persistence/coordinator.ts b/src/core/persistence/coordinator.tsindex bee364a0a9..908c02c99d 100644--- a/src/core/persistence/coordinator.ts+++ b/src/core/persistence/coordinator.ts@@ -253,10 +253,12 @@ export async function finishPreparationStalled(engine: BrainEngine, row: WriteRereturn engine.transaction(tx => completeWrite(tx, row, 'failed', {}, failure));}-/** GBRA-130 A-5: the statement (57014) or lock (55P03) timeout that cut off a publication transaction, else null. */+/**+ * GBRA-130 A-5: the statement timeout (57014) that cut off a publication transaction, else null. A lock timeout (55P03)+ * waits on another holder and stays transient contention, uncounted (#5762), like a serialization failure or deadlock.+ */function publicationTimeout(error: unknown): string | null {- const code = String((error as { code?: string } | null)?.code);- return code === '57014' || code === '55P03' ? code : null;+ return String((error as { code?: string } | null)?.code) === '57014' ? '57014' : null;}/*** GBRA-130 A-5: a publication cut off by its timeout charges one attempt (`preparation_attempts`, the #6278 counter). Below@@ -268,7 +270,7 @@ async function chargePublicationTimeout(engine: BrainEngine, row: WriteRequest,const { maxAttempts: limit } = await readPreparationPolicy(engine);if (attempts < limit) return null;return withAttempt({ code: 'publication_timeout',- message: `The publication transaction of this ${row.operation} write timed out (${sqlstate === '57014' ? 'statement timeout' : 'lock timeout'}) ${attempts} time(s), the limit of persistence.max_preparation_attempts (${limit}); nothing was committed and it is not claimed again. Report the request id with its size (${row.intent_bytes} intent bytes) and gbrain sources writer status --source ${row.source_id} --json; a smaller write needs a new request_id.`,+ message: `The publication transaction of this ${row.operation} write timed out (statement timeout) ${attempts} time(s), the limit of persistence.max_preparation_attempts (${limit}); nothing was committed and it is not claimed again. Report the request id with its size (${row.intent_bytes} intent bytes) and gbrain sources writer status --source ${row.source_id} --json; a smaller write needs a new request_id.`,detail: { origin: 'publication_timeout', sqlstate, attempts, limit, intent_bytes: Number(row.intent_bytes) } as unknown as PublicationFailureDetail }, stage);}diff --git a/test/publication-timeout-charge-gbra130.test.ts b/test/publication-timeout-charge-gbra130.test.tsindex fbb8099569..2d1216d3d0 100644--- a/test/publication-timeout-charge-gbra130.test.ts+++ b/test/publication-timeout-charge-gbra130.test.ts@@ -1,7 +1,8 @@/**- * GBRA-130 A-5 (#6712 PR 4b): a publication whose transaction always hits its statement timeout (57014) or lock timeout- * (55P03) was released as `database_contention` without charging an attempt and claimed again without limit; as the- * oldest unresolved row of its worktree it held every later write on that root (FIFO).+ * GBRA-130 A-5 (#6712 PR 4b): a publication whose transaction always hits its statement timeout (57014) was released as+ * `database_contention` without charging an attempt and claimed again without limit; as the oldest unresolved row of+ * its worktree it held every later write on that root (FIFO). A lock timeout (55P03) waits on another holder and stays+ * transient, uncounted (#5762): that arm pins it.** Protects (red before: the timed-out write stays queued/running with `database_contention` and the write behind it* does not commit):@@ -72,7 +73,19 @@ for (const backend of testBackends()) describe(`[${backend}] GBRA-130 A-5: a pubafterEach(async () => { installFaultHook(undefined); await disposePersistenceConsumer(engine); });for (const [arm, sourceId] of [['database-only page', 'default'], ['worktree-backed page', managed]] as const) {- for (const code of ['57014', '55P03'] as const) test(`${arm}: a ${code} at every publication ends failed/publication_timeout at the attempt limit, and the next write commits`, async () => {+ test(`${arm}: a 55P03 lock timeout at publication stays transient contention, uncounted, and commits once the lock frees`, async () => {+ const slug = `a5/lock-${randomUUID().slice(0, 8)}`;+ const requestId = randomUUID();+ let timedOut = 0;+ installFaultHook(async (point, detail) => {+ if (detail.requestId === requestId && point === 'publication:before_commit' && timedOut < 3) { timedOut++; throw timeout('55P03'); }+ });+ await put(sourceId, slug, requestId).catch(() => null);+ const done = await settled(requestId);+ expect(timedOut).toBe(3);+ expect(done).toMatchObject({ state: 'committed', preparation_attempts: 0 });+ }, 60_000);+ for (const code of ['57014'] as const) test(`${arm}: a ${code} at every publication ends failed/publication_timeout at the attempt limit, and the next write commits`, async () => {const slug = `a5/t${code.toLowerCase()}-${randomUUID().slice(0, 8)}`;const requestId = randomUUID();let timedOut = 0;