Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(remediation): approved repair steps are interactive writes (#6696 A5)
garrytan5b0b366a17aa
diff --git a/src/core/remediation/repairs.ts b/src/core/remediation/repairs.tsindex 89b344c73a..32d37e22eb 100644--- a/src/core/remediation/repairs.ts+++ b/src/core/remediation/repairs.ts@@ -26,6 +26,7 @@ import { cliRenderContext, renderAction, type RenderedAction } from '../agent-ouimport { readFix } from '../ops/op-fix.ts';import { isStatementTimeoutError } from '../retry-matcher.ts';import { redactConnectionInfo } from '../audit/redact-connection-info.ts';+import { withAdmissionOrigin } from '../persistence/admission-origin.ts';export interface RepairPlanStep {step: number;@@ -184,8 +185,9 @@ export async function runRepairSteps(engine: BrainEngine, steps: RepairPlanStep[if (step.paid && step.embeds === 'effect' && step.est_usd_cost) opts.charge?.(step.est_usd_cost - (step.llm_usd ?? 0));const spentBefore = opts.spentUsd?.() ?? 0;try {- const applied = llm ? await runner.run(step.kind, scope, { maxLlmUsd: opts.remainingUsd() })- : step.paid && step.embeds === 'inline' && opts.stepBudget ? await opts.stepBudget(() => runner.run(step.kind, scope)) : await runner.run(step.kind, scope);+ // #6696 (A5): an approved repair step is the operator's own write, like gbrain repair; an enclosing background scope still wins.+ const applied = await withAdmissionOrigin('interactive', () => llm ? runner.run(step.kind, scope, { maxLlmUsd: opts.remainingUsd() })+ : step.paid && step.embeds === 'inline' && opts.stepBudget ? opts.stepBudget(() => runner.run(step.kind, scope)) : runner.run(step.kind, scope));if (llm) opts.charge?.(Math.max(0, (applied.cost.llm_usd ?? 0) - ((opts.spentUsd?.() ?? 0) - spentBefore)));const failed = applied.failed.length;const failedMessage = failed ? `${failed} item(s) refused and left unchanged (first: ${applied.failed[0]!.item}, ${applied.failed[0]!.reason}); `diff --git a/test/fix-wave-3-recovery-run.test.ts b/test/fix-wave-3-recovery-run.test.tsindex e978c4fd83..f1c96b0c5c 100644--- a/test/fix-wave-3-recovery-run.test.ts+++ b/test/fix-wave-3-recovery-run.test.ts@@ -23,6 +23,7 @@ import type { WriteRequest } from '../src/core/persistence/model.ts';import { parseGoogleSourceConfig, runGoogleSync } from '../src/core/google/google-source.ts';import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';import { admitWrite } from '../src/core/persistence/journal.ts';+import { withAdmissionOrigin } from '../src/core/persistence/admission-origin.ts';import { declarePersistenceProtocol } from '../src/core/persistence/protocol.ts';import { migrateConnectorCheckpoints } from '../src/core/persistence/connector-checkpoint-migration.ts';import { readConnectorSourceStatuses } from '../src/core/persistence/connector-status.ts';@@ -67,7 +68,8 @@ for (const backend of testBackends()) test(`${backend}: post-upgrade to a cleanconst databaseUrl = backend === 'postgres' ? process.env.DATABASE_URL : undefined;await waveBrain(async ({ engine }) => {await withEnv({ CONNECTOR_TEST_TOKEN: 'synthetic-local-fixture' }, async () => {- const connector = await rewalkingConnector(engine);+ // Pre-upgrade history, written before the background pause line existed (#6696); the fixture's ids sit past it.+ const connector = await withAdmissionOrigin('interactive', () => rewalkingConnector(engine));// A page imported before every import recorded its contextual mode.await engine.executeRaw("UPDATE content_chunks SET embedding=$1::text::vector WHERE page_id=(SELECT id FROM pages WHERE source_id='default' AND slug='notes/base')", [VECTOR]);await engine.executeRaw("UPDATE pages SET contextual_retrieval_mode=NULL WHERE source_id='default' AND slug='notes/base'");diff --git a/test/helpers/wave-fixture.ts b/test/helpers/wave-fixture.tsindex a560ec9043..9dd8f2dd03 100644--- a/test/helpers/wave-fixture.ts+++ b/test/helpers/wave-fixture.ts@@ -24,7 +24,7 @@ import { withEnv } from './with-env.ts';export type WaveFindingKind = 'timeline' | 'visibility' | 'safe_index' | 'capacity' | 'parked' | 'self_capture' | 'stale_embedding' | 'old_writer';export const ALL_WAVE_FINDINGS: WaveFindingKind[] = ['timeline', 'visibility', 'safe_index', 'capacity', 'parked', 'self_capture', 'stale_embedding', 'old_writer'];-export const put = (ctx: OperationContext, slug: string, body: string, type = 'note', extra = '') => submitPageMutation(ctx, { operation: 'put_page',+export const put = (ctx: OperationContext, slug: string, body: string, type = 'note', extra = '') => submitPageMutation({ ...ctx, admissionOrigin: 'interactive' }, { operation: 'put_page',params: { slug, request_id: randomUUID(), content: `---\ntype: ${type}\ntitle: ${slug}\n${extra}---\n\n${body}\n` } });async function protocol(engine: BrainEngine, sql: string, params: unknown[] = []) {@@ -50,7 +50,7 @@ export async function seedWaveFindings(brain: ManagedBrain, home: string, kinds:}await disposePersistenceConsumer(engine);if (kinds.includes('capacity')) {- // 85% of a principal's permanent request ids, with room left under the 90% stop for the repairs.+ // 85% of a principal's permanent request ids: past the 80% background pause line (#6696), with room left for the seeding writes and the approved repairs, which are interactive.await engine.setConfig('persistence.limits.principal_lifetime_ids', '1000');await protocol(engine, "UPDATE persistence_counters SET lifetime_ids=850 WHERE key LIKE 'principal:%'");}