Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(persistence): background_pause_pct reads as a percent (#6696 A5)

garrytan4cf10ec821bb
diff --git a/docs/guides/error-codes.md b/docs/guides/error-codes.md
index 06ade0f67e..2b7b3094e0 100644
--- a/docs/guides/error-codes.md
+++ b/docs/guides/error-codes.md
@@ -3287,7 +3287,7 @@ More: [docs/guides/write-refusals.md#worktree_dirty](../../docs/guides/write-ref
| Meaning | Why | Next step | Who acts · consent | Verify | Exit | Retryable |
|---|---|---|---|---|---|---|
-| A background producer (maintenance, conversation facts, an autopilot phase or an autopilot catch-up sync) stopped admitting writes because a cumulative write cap is past `persistence.capacity.background_pause_pct` (0.8); interactive writes keep the rest. Nothing was submitted and no receipt was written. | Near a cumulative cap the remaining request ids and receipt bytes are kept for the user's own writes (remember, put_page, edit_page, operator sync, approved repair). Request ids are never freed, so past the line on ids only the brain host's config raise resumes background work; receipt bytes also free as receipts compact. | Only the brain host's operator can resolve this. Tell the user the message and run `gbrain doctor --json` on the brain host. Run: gbrain doctor --only persistence_capacity --json | agent | `gbrain doctor --json` | 12 | no |
+| A background producer (maintenance, conversation facts, an autopilot phase or an autopilot catch-up sync) stopped admitting writes because a cumulative write cap is past `persistence.capacity.background_pause_pct` (default 80); interactive writes keep the rest. Nothing was submitted and no receipt was written. | Near a cumulative cap the remaining request ids and receipt bytes are kept for the user's own writes (remember, put_page, edit_page, operator sync, approved repair). Request ids are never freed, so past the line on ids only the brain host's config raise resumes background work; receipt bytes also free as receipts compact. | Only the brain host's operator can resolve this. Tell the user the message and run `gbrain doctor --json` on the brain host. Run: gbrain doctor --only persistence_capacity --json | agent | `gbrain doctor --json` | 12 | no |
More: [docs/guides/write-refusals.md#write_capacity_backpressure](../../docs/guides/write-refusals.md#write_capacity_backpressure)
diff --git a/src/core/error-registry.ts b/src/core/error-registry.ts
index 8951efa79a..5a94396727 100644
--- a/src/core/error-registry.ts
+++ b/src/core/error-registry.ts
@@ -491,7 +491,7 @@ export const CODES = {
verification_failed: { class: 'server', summary: "Source content or relationships changed during verification." },
withdrawal_capacity: { class: 'caller', summary: "Withdrawal capacity." },
withdrawal_provenance: { class: 'server', summary: "The withdrawal target manifest is invalid." },
- write_capacity_backpressure: { class: 'host_only', retryable: false, summary: "A background producer (maintenance, conversation facts, an autopilot phase or an autopilot catch-up sync) stopped admitting writes because a cumulative write cap is past `persistence.capacity.background_pause_pct` (0.8); interactive writes keep the rest. Nothing was submitted and no receipt was written.", why: "Near a cumulative cap the remaining request ids and receipt bytes are kept for the user's own writes (remember, put_page, edit_page, operator sync, approved repair). Request ids are never freed, so past the line on ids only the brain host's config raise resumes background work; receipt bytes also free as receipts compact.", docs: 'docs/guides/write-refusals.md#write_capacity_backpressure', fix: { argv: ['gbrain', 'doctor', '--only', 'persistence_capacity', '--json'], consent: [], actor: 'agent', why: "Names the cap past the pause line, its days left and the reversible config raise, read-only.", requires_exclusive: false }, exit: 12 },
+ write_capacity_backpressure: { class: 'host_only', retryable: false, summary: "A background producer (maintenance, conversation facts, an autopilot phase or an autopilot catch-up sync) stopped admitting writes because a cumulative write cap is past `persistence.capacity.background_pause_pct` (default 80); interactive writes keep the rest. Nothing was submitted and no receipt was written.", why: "Near a cumulative cap the remaining request ids and receipt bytes are kept for the user's own writes (remember, put_page, edit_page, operator sync, approved repair). Request ids are never freed, so past the line on ids only the brain host's config raise resumes background work; receipt bytes also free as receipts compact.", docs: 'docs/guides/write-refusals.md#write_capacity_backpressure', fix: { argv: ['gbrain', 'doctor', '--only', 'persistence_capacity', '--json'], consent: [], actor: 'agent', why: "Names the cap past the pause line, its days left and the reversible config raise, read-only.", requires_exclusive: false }, exit: 12 },
write_capacity_low: { class: 'host_only', retryable: false, summary: "A cumulative write cap is at or past 80% or runs out within `persistence.capacity.warn_days` (30) days at its 7-day rate; writes still work.", why: "Request ids are permanent and receipt bytes free only as receipts compact, so the cap is raised before admission refuses.", docs: 'docs/guides/write-refusals.md#write_capacity_low', fix: { argv: ['gbrain', 'doctor', '--only', 'persistence_capacity', '--json'], consent: [], actor: 'agent', why: "Reads the forecast and the one-year config value, read-only.", requires_exclusive: false } },
write_claim_lost: { class: 'retryable', summary: "Execution claim changed before publication." },
write_gate_rejected: { class: 'caller', summary: "The write gate refused external instruction-like content because the operator set `write_gate.external_mode` to `reject`.", why: "Text from an untrusted source that reads like an instruction to an agent (an override, a standing rule, an exfiltration or credential request) is refused instead of held under that setting, so nothing was written. The same content refuses on every retry.", reasons: ['override', 'standing_instruction', 'exfiltration', 'credential', 'detector_error'], suggestion: 'Tell the user the content was refused; whether to accept it or switch `write_gate.external_mode` back to `quarantine` is their decision.' },
diff --git a/src/core/persistence/admission-origin.ts b/src/core/persistence/admission-origin.ts
index 0538d02778..f29f5397cc 100644
--- a/src/core/persistence/admission-origin.ts
+++ b/src/core/persistence/admission-origin.ts
@@ -12,7 +12,7 @@
* `ctx.remote`: an autopilot phase writes with `remote: true` too.
*
* Near a cumulative cap (`persistence.capacity.background_pause_pct`, default
- * 0.8, of a principal's or the brain's request ids or receipt bytes) a
+ * 80 percent, of a principal's or the brain's request ids or receipt bytes) a
* background admission refuses `write_capacity_backpressure` before any
* receipt exists, so the rest stays free for interactive writes.
*/
@@ -45,11 +45,12 @@ export function isAdmissionOrigin(value: unknown): value is AdmissionOrigin {
return value === 'interactive' || value === 'background';
}
-/** The pause line as a share of each cumulative cap (0 < share <= 1). */
+/** The pause line as a share of each cumulative cap (0 < share <= 1); the setting is a percent (80), and a share (0.8) reads the same. */
export async function readBackgroundPauseShare(engine: SqlEngine): Promise<number> {
const [row] = await engine.executeRaw<{ value: string }>('SELECT value FROM config WHERE key=$1', [BACKGROUND_PAUSE_KEY]);
const value = row ? Number(row.value) : DEFAULT_BACKGROUND_PAUSE_SHARE;
- return Number.isFinite(value) && value > 0 && value <= 1 ? value : DEFAULT_BACKGROUND_PAUSE_SHARE;
+ if (!Number.isFinite(value) || value <= 0 || value > 100) return DEFAULT_BACKGROUND_PAUSE_SHARE;
+ return value > 1 ? value / 100 : value;
}
/**
diff --git a/test/persistence-background-pause.test.ts b/test/persistence-background-pause.test.ts
index cf0f93a645..699bea01f2 100644
--- a/test/persistence-background-pause.test.ts
+++ b/test/persistence-background-pause.test.ts
@@ -13,7 +13,7 @@ import { join } from 'node:path';
import type { BrainEngine } from '../src/core/engine.ts';
import { submissionAuthority } from '../src/core/persistence/authority.ts';
import { admitWriteGroupInTransaction } from '../src/core/persistence/journal.ts';
-import { BACKGROUND_PAUSE_KEY, BACKGROUND_PRODUCERS, resolveAdmissionOrigin, withAdmissionOrigin } from '../src/core/persistence/admission-origin.ts';
+import { BACKGROUND_PAUSE_KEY, BACKGROUND_PRODUCERS, readBackgroundPauseShare, resolveAdmissionOrigin, withAdmissionOrigin } from '../src/core/persistence/admission-origin.ts';
import { checkPersistenceCapacity } from '../src/commands/doctor/checks/persistence-capacity.ts';
import { CODES } from '../src/core/error-registry.ts';
import { freshBrainFactory, requestFixture } from './helpers/persistence-request-fixture.ts';
@@ -50,6 +50,14 @@ for (const kind of testBackends()) {
await withEnv({ GBRAIN_HOME: scratch, DATABASE_URL: undefined, GBRAIN_DATABASE_URL: undefined }, () => fn(engine));
}, 120_000);
+ check('the pause line reads as a percent, a share reads the same, and an invalid value keeps the default', async engine => {
+ expect(await readBackgroundPauseShare(engine)).toBe(0.8);
+ for (const [value, share] of [['90', 0.9], ['0.6', 0.6], ['100', 1], ['1', 1], ['0', 0.8], ['250', 0.8], ['abc', 0.8]] as const) {
+ await engine.setConfig(BACKGROUND_PAUSE_KEY, value);
+ expect(await readBackgroundPauseShare(engine)).toBe(share);
+ }
+ });
+
check('a background admission past the line refuses with no receipt; an interactive one is admitted', async engine => {
const requests = await requestFixture(engine);
for (let i = 0; i < 3; i++) await requests.admit(`p${i}`);