Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(persistence): a background admission to a worktree in recovery refuses owner_unavailable with the owner-status fix (#6741)
garrytan0970a1374e79
diff --git a/src/core/persistence/admission-origin.ts b/src/core/persistence/admission-origin.tsindex 8d8f8cddde..61f6cd8513 100644--- a/src/core/persistence/admission-origin.ts+++ b/src/core/persistence/admission-origin.ts@@ -16,13 +16,13 @@* background admission refuses `write_capacity_backpressure` before any* receipt exists, so the rest stays free for interactive writes. #6741 C: a* background admission bound to a worktree in recovery refuses- * `recovery_required` the same way (backgroundWorktreeInactive), so a producer+ * `owner_unavailable` the same way (backgroundWorktreeInactive), so a producer* retrying against it burns no permanent request ids. A draining (paused)* owner still admits: its receipts stay pending and its restart replays them.*/import { AsyncLocalStorage } from 'node:async_hooks';import { opError, type OperationError } from '../ops/contract.ts';-import { readFix } from '../ops/op-fix.ts';+import type { Action } from '../agent-output.ts';import type { SqlEngine } from './model.ts';import { CAPACITY_VERIFY } from './capacity-verify.ts';@@ -79,10 +79,12 @@ export function backgroundPaused(scopeKey: string, resource: 'lifetime_ids' | 'tverify: CAPACITY_VERIFY, docs: 'docs/guides/concurrent-writes.md#quota-near-exhaustion' } });}-/** #6741 C: the refusal of a background admission to a worktree in recovery; nothing was submitted and no request id was used. */-export function backgroundWorktreeInactive(sourceId: string, state: string): OperationError {- return opError('recovery_required', `Background writes to source ${sourceId} are paused: its worktree is ${state}.`,- `Nothing was submitted and no request id was used. Background work for source ${sourceId} resumes once its writer is active again; gbrain sources writer status --source ${sourceId} shows what it is waiting on.`,- { fix: readFix(`Shows source ${sourceId}'s worktree state and the recovery it is waiting on, read-only.`,- { argv: ['gbrain', 'sources', 'writer', 'status', '--source', sourceId, '--json'] }) });+/**+ * #6741 C: the refusal of a background admission to a worktree in recovery; nothing was submitted and no request id+ * was used. `owner_unavailable` with the owner-status read fix, as facts-maintenance refuses a non-active fact writer.+ */+export function backgroundWorktreeInactive(sourceId: string, state: string, ownerStatusFix: Action): OperationError {+ return opError('owner_unavailable', `Background writes to source ${sourceId} are paused: its worktree is ${state}.`,+ `Nothing was submitted and no request id was used. Background work for source ${sourceId} resumes once its writer is active again; writer status shows what it is waiting on.`,+ { fix: ownerStatusFix });}diff --git a/src/core/persistence/journal.ts b/src/core/persistence/journal.tsindex 03f4cf9a30..b1ddcda863 100644--- a/src/core/persistence/journal.ts+++ b/src/core/persistence/journal.ts@@ -524,7 +524,7 @@ async function assertWorktreeAdmission(tx: BrainEngine, input: WriteAdmission):const refresh = typeof state?.refresh === 'string' ? JSON.parse(state.refresh) as { id: string; state: string; source_ids: string[] } : state?.refresh ?? null;if (refresh) await assertWorktreeNotRefreshing(tx, input, refresh);// #6741 C: a background producer never takes a permanent request id against a worktree in recovery (a draining owner still replays).- if (worktree?.state === 'recovering' && resolveAdmissionOrigin(input.origin) === 'background') throw backgroundWorktreeInactive(input.sourceId, worktree.state);+ if (worktree?.state === 'recovering' && resolveAdmissionOrigin(input.origin) === 'background') throw backgroundWorktreeInactive(input.sourceId, worktree.state, ownerStatusFix(input.sourceId));if (!state?.bound) throw opError('source_changed', 'The source binding changed during admission.',`Source ${input.sourceId}'s worktree binding changed (a claim, transfer or lifecycle change) while this write was being admitted, so nothing was accepted. Check the owner with the command in fix, then submit the write again; reusing the same request_id is safe because nothing was recorded.`,{ fix: ownerStatusFix(input.sourceId) });diff --git a/test/purge-deleted-parks.test.ts b/test/purge-deleted-parks.test.tsindex 28cb4dd0b5..ada28df1b6 100644--- a/test/purge-deleted-parks.test.ts+++ b/test/purge-deleted-parks.test.ts@@ -176,13 +176,13 @@ describe('#6741 C: the managed purge spends no request ids it cannot use', () =>});describe('#6741 C: background admissions refuse before any receipt against a worktree in recovery', () => {- test('a background put_page is refused recovery_required and takes no request id', async () => {+ test('a background put_page is refused owner_unavailable with the owner-status read fix and takes no request id', async () => {await setWorktree('recovering');const before = await lifetimeIds();const requests = (await engine.executeRaw('SELECT 1 FROM persistence_requests')).length;await expect(withEnv(env(), () => submitPageMutation(ctxFor('background'), { operation: 'put_page',params: { slug: 'notes/background', content: '---\ntitle: Background\ntype: note\n---\nMaintenance output.', request_id: randomUUID() } })))- .rejects.toMatchObject({ code: 'recovery_required' });+ .rejects.toMatchObject({ code: 'owner_unavailable', fix: { argv: ['gbrain', 'sources', 'writer', 'status', '--source', SOURCE, '--json'] } });expect(await lifetimeIds()).toBe(before);expect((await engine.executeRaw('SELECT 1 FROM persistence_requests')).length).toBe(requests);}, 120_000);