Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(persistence): capacity errors use the current advice keys (#6696)
garrytan794bc19985a5
diff --git a/src/core/facts/conversation-publication.ts b/src/core/facts/conversation-publication.tsindex f2df71e866..55b1cab9e3 100644--- a/src/core/facts/conversation-publication.ts+++ b/src/core/facts/conversation-publication.ts@@ -279,7 +279,7 @@ export async function assertConversationAdmissionHeadroom(engine: BrainEngine, athrow backgroundPaused(key, r.resource, r.used, limit, pause, journalLimitKey(r.setting),await oneYearCapacity(engine, key, r.resource === 'lifetime_ids' ? 'LifetimeIds' : 'TerminalBytes', r.used, limit), {what: `Conversation fact extraction stopped before admitting ${needed > 1 ? `${needed} planned` : 'the next'} request(s)`,- hint: room > 0 ? `A smaller batch fits: gbrain extract-conversation-facts --source-id ${authority.writer.sourceId} --limit ${room}.` : undefined });+ alternative: room > 0 ? `A smaller batch fits: gbrain extract-conversation-facts --source-id ${authority.writer.sourceId} --limit ${room}.` : undefined });}}diff --git a/src/core/persistence/admission-origin.ts b/src/core/persistence/admission-origin.tsindex 3ed7ace913..0538d02778 100644--- a/src/core/persistence/admission-origin.ts+++ b/src/core/persistence/admission-origin.ts@@ -58,11 +58,11 @@ export async function readBackgroundPauseShare(engine: SqlEngine): Promise<numbe* is the host's config raise; receipt bytes also free as receipts compact.*/export function backgroundPaused(scopeKey: string, resource: 'lifetime_ids' | 'terminal_bytes', used: number, limit: number, share: number,- configKey: string, value: number, context: { what?: string; hint?: string } = {}): OperationError {+ configKey: string, value: number, context: { what?: string; alternative?: string } = {}): OperationError {const raise = `gbrain config set ${configKey} ${value}`;return opError('write_capacity_backpressure',`${context.what ?? 'Background writes are paused'}: ${scopeKey} ${resource} is at ${used} of ${limit}, past the ${Math.round(share * 100)}% pause line (${BACKGROUND_PAUSE_KEY}).`,- `Nothing was submitted; interactive writes keep the rest of ${configKey}. ${context.hint ? `${context.hint} ` : ''}${resource === 'lifetime_ids'+ `Nothing was submitted; interactive writes keep the rest of ${configKey}. ${context.alternative ? `${context.alternative} ` : ''}${resource === 'lifetime_ids'? `Request ids are never freed, so background work resumes only after the brain host runs ${raise} (covers about one more year; undo with gbrain config unset ${configKey}).`: `Background work resumes as retained receipts compact, or at once after the brain host runs ${raise} (covers about one more year; undo with gbrain config unset ${configKey}).`}`,{ reason: resource, detail: configKey.slice('persistence.limits.'.length), docs: 'docs/guides/write-refusals.md#write_capacity_backpressure',diff --git a/src/core/persistence/sync-drain.ts b/src/core/persistence/sync-drain.tsindex d0daf96ebe..48c967ba6e 100644--- a/src/core/persistence/sync-drain.ts+++ b/src/core/persistence/sync-drain.ts@@ -42,8 +42,8 @@ export type DrainStopReason = 'deadline' | 'drain_stalled' | 'database_contentio| 'connection_lost'/** #6696 (A7): a cumulative write cap (or the background pause line) refused the next admission after the preflight passed; resumable once capacity returns. */| 'capacity_paused';-/** #6696 (A7): the refusal that paused the drain (`capacity_paused`); `fix_argv` is the host's config raise. */-export interface DrainCapacityPause { code: string; reason: string | null; detail: string | null; message: string; fix_argv?: string[] }+/** #6696 (A7): the refusal that paused the drain (`capacity_paused`); `fix` is the host's config raise. */+export interface DrainCapacityPause { code: string; reason: string | null; detail: string | null; message: string; fix?: Action }/** A capacity refusal raised by an admission after the run's preflight (the preflight's own refusal stops the command up front). */export function isCapacityPause(error: unknown): boolean {return error instanceof OperationError && ['write_quota_exhausted', 'write_capacity_backpressure', 'write_quota_insufficient'].includes(error.code)@@ -494,7 +494,7 @@ export async function runDrain(input: DrainInput): Promise<SyncResult> {if (isCapacityPause(error)) {const e = error as OperationError;return finish(last ?? NO_PASS_RESULT, 'resumable', 'capacity_paused', { capacity_pause: { code: e.code, reason: e.reason ?? null, detail: e.detail ?? null,- message: e.message, ...(e.fix?.argv ? { fix_argv: e.fix.argv } : {}) } });+ message: e.message, ...(e.fix ? { fix: e.fix } : {}) } });}if (isWriteCapacityWait(error) && !signal?.aborted) {capacity ??= { since: clock(), attempts: 0 };@@ -854,7 +854,7 @@ export function drainNext(result: SyncResult, resumeCommand: string, sourceId: sconst docs = d?.stop_reason ? ERROR_CATALOGUE[STOP_DOCS[d.stop_reason]].docs : undefined;if (outcome === 'resumable' && d?.stop_reason === 'capacity_paused') {const pause = d.capacity_pause;- const raise = pause?.fix_argv?.join(' ');+ const raise = pause?.fix?.argv?.join(' ');return { command: resumeCommand, safe_to_loop: false, retry_after_ms: 0, ...estimate, code: 'capacity_paused',why: `The sync paused: ${pause?.message ?? 'a cumulative write cap refused its next admission'} Nothing failed; the cursor and every accepted write are intact. `+ `${pause?.reason === 'lifetime_ids' ? 'Request ids never free, so ' : ''}${raise ? `the brain host runs ${raise} (reversible)` : 'the brain host raises the cap gbrain doctor --only persistence_capacity --json names'}`diff --git a/test/sync-capacity-preflight.test.ts b/test/sync-capacity-preflight.test.tsindex a257427c17..3856f4bb9e 100644--- a/test/sync-capacity-preflight.test.ts+++ b/test/sync-capacity-preflight.test.ts@@ -42,7 +42,7 @@ describe('capacity_paused in the drain', () => {let passes = 0;const result = await runDrain({ backoffMs: 5, pass: async () => { if (++passes === 1) return base; throw exhausted(); } });expect(result).toMatchObject({ added: 1, drain: { outcome: 'resumable', stop_reason: 'capacity_paused', remaining: 2,- capacity_pause: { code: 'write_quota_exhausted', reason: 'lifetime_ids', fix_argv: ['gbrain', 'config', 'set', 'persistence.limits.principal_lifetime_ids', '100'] } } });+ capacity_pause: { code: 'write_quota_exhausted', reason: 'lifetime_ids', fix: { argv: ['gbrain', 'config', 'set', 'persistence.limits.principal_lifetime_ids', '100'], actor: 'host_admin' } } } });const next = drainNext(result, RESUME, 's')!;expect(next).toMatchObject({ command: RESUME, code: 'capacity_paused', docs: ERROR_CATALOGUE.sync_drain_capacity_paused.docs });expect(next.why).toContain('gbrain config set persistence.limits.principal_lifetime_ids 100');