Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(persistence): grouped Git completion failures count toward parking (#8606)

garrytan839aa9bc13cc
diff --git a/src/core/persistence/effects.ts b/src/core/persistence/effects.ts
index df9f25e24c..229c075d83 100644
--- a/src/core/persistence/effects.ts
+++ b/src/core/persistence/effects.ts
@@ -1005,7 +1005,7 @@ async function runEffectPass(engine: BrainEngine, config: GBrainConfig, opts: Ef
const roots = new Map<string, unknown>();
const guards = new Map<string, unknown>();
const mirrors = new Map<string, boolean>();
- const recorded: PersistenceEffect[] = [];
+ const recorded: { effect: PersistenceEffect; target?: string }[] = [];
let gates: Map<string, MirrorGate>;
try { gates = await mirrorGates(engine, effects.map(effect => effect.request_id)); }
catch (error) { for (const effect of effects) await recordFailure(engine, effect, error, opts.signal); return; }
@@ -1033,12 +1033,12 @@ async function runEffectPass(engine: BrainEngine, config: GBrainConfig, opts: Ef
if (!binding.local_path) { await completeEffect(engine, effect, { git: 'skipped', reason: 'no_repo_configured' }); continue; }
if (!mirrors.has(effect.source_id)) mirrors.set(effect.source_id, await sourceMirrorReadOnly(engine, effect.source_id));
if (mirrors.get(effect.source_id)) { await completeEffect(engine, effect, { git: 'skipped', reason: 'mirror_read_only' }); continue; }
- if (await singleFileGitTarget(engine, effect, { ...binding, local_path: binding.local_path }, attempt) !== null) recorded.push(effect);
+ if (await singleFileGitTarget(engine, effect, { ...binding, local_path: binding.local_path }, attempt) !== null) recorded.push({ effect, target: attempt.target });
} catch (error) { await recordFailure(engine, effect, error, opts.signal, attempt.target); }
}
if (!recorded.length) return;
try {
- for (const effect of recorded) await faultPoint(EFFECT_FAULT_POINTS.git, { effectId: effect.id, requestId: effect.request_id, sourceId: effect.source_id });
+ for (const { effect } of recorded) await faultPoint(EFFECT_FAULT_POINTS.git, { effectId: effect.id, requestId: effect.request_id, sourceId: effect.source_id });
await engine.executeRaw(`UPDATE persistence_effects e SET
state=CASE WHEN jsonb_array_length(COALESCE(e.data->'parked','[]'::jsonb))>0 THEN 'failed' ELSE 'committed' END,
error_code=CASE WHEN jsonb_array_length(COALESCE(e.data->'parked','[]'::jsonb))>0 THEN 'targets_parked' END,
@@ -1046,8 +1046,8 @@ async function runEffectPass(engine: BrainEngine, config: GBrainConfig, opts: Ef
outcome=$2::text::jsonb,updated_at=now()
FROM jsonb_to_recordset($1::text::jsonb) AS t(id bigint,token uuid)
WHERE e.id=t.id AND e.execution_token=t.token AND e.recovery IS NULL AND ${PERSISTENCE_PROTOCOL_PREDICATE}`,
- [JSON.stringify(recorded.map(effect => ({ id: String(effect.id), token: effect.execution_token }))), JSON.stringify(DURABILITY_NOT_ENABLED)]);
- } catch (error) { for (const effect of recorded) await recordFailure(engine, effect, error, opts.signal); }
+ [JSON.stringify(recorded.map(({ effect }) => ({ id: String(effect.id), token: effect.execution_token }))), JSON.stringify(DURABILITY_NOT_ENABLED)]);
+ } catch (error) { for (const { effect, target } of recorded) await recordFailure(engine, effect, error, opts.signal, target); }
};
// A deferred effect that requeues itself (a page walk advancing its cursor,
// or work unblocked by an earlier effect) is claimable again after the flush.
diff --git a/test/persistence-effect-git-group-failure-8606.test.ts b/test/persistence-effect-git-group-failure-8606.test.ts
new file mode 100644
index 0000000000..8c54c3d7d6
--- /dev/null
+++ b/test/persistence-effect-git-group-failure-8606.test.ts
@@ -0,0 +1,54 @@
+/**
+ * #8606: a single-file Git effect whose grouped completion keeps failing used to retry forever once an earlier
+ * attempt had failed on its target: the grouped completion recorded its failures without the target, so each one
+ * reset the consecutive-failure count to 1 and the five-failure park never came. It now carries the target.
+ */
+import { afterEach, expect, test } from 'bun:test';
+import { randomUUID } from 'node:crypto';
+import { chmodSync } from 'node:fs';
+import { join } from 'node:path';
+import type { BrainEngine } from '../src/core/engine.ts';
+import type { OperationContext } from '../src/core/ops/contract.ts';
+import { submitPageMutation } from '../src/core/persistence/page-mutations.ts';
+import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';
+import { runPersistenceEffects } from '../src/core/persistence/effects.ts';
+import { declarePersistenceProtocol } from '../src/core/persistence/protocol.ts';
+import { localHostId } from '../src/core/persistence/identity.ts';
+import { EFFECT_FAULT_POINTS, installFaultHook } from '../src/core/persistence/fault-points.ts';
+import { managedBrain } from './helpers/managed-brain.ts';
+
+afterEach(() => installFaultHook(undefined));
+
+type GitEffect = { id: number; state: string; error_code: string | null; data: Record<string, unknown> };
+const gitEffect = async (engine: BrainEngine, slug: string) => (await engine.executeRaw<GitEffect>(`SELECT e.id,e.state,e.error_code,e.data
+ FROM persistence_effects e JOIN persistence_requests r ON r.id=e.request_id WHERE e.kind='git' AND r.slug=$1`, [slug]))[0]!;
+
+/** One effect pass with every other effect deferred. */
+async function attempt(engine: BrainEngine, ctx: OperationContext, id: number) {
+ await engine.transaction(async tx => {
+ await declarePersistenceProtocol(tx);
+ await tx.executeRaw("UPDATE persistence_effects SET next_attempt_at=CASE WHEN id=$1 THEN now() ELSE now()+interval '1 hour' END", [id]);
+ });
+ await runPersistenceEffects(engine, ctx.config, { hostId: localHostId(), limit: 1 });
+}
+
+test('a Git effect whose grouped completion keeps failing parks even after an earlier failure on its target', async () => {
+ await managedBrain(async ({ engine, ctx, root }) => {
+ const slug = 'notes/alice-example';
+ await submitPageMutation(ctx, { operation: 'put_page',
+ params: { slug, request_id: randomUUID(), content: `---\ntype: note\ntitle: Alice Example\n---\n\nBody.\n` } });
+ await disposePersistenceConsumer(engine);
+ const effect = await gitEffect(engine, slug);
+ expect(effect.state).toBe('queued');
+ const file = join(root, `${slug}.md`);
+ chmodSync(file, 0o000);
+ try { await attempt(engine, ctx, effect.id); } finally { chmodSync(file, 0o644); }
+ expect(await gitEffect(engine, slug)).toMatchObject({ state: 'queued', data: { target_failures: 1, failing_target: slug } });
+
+ installFaultHook(point => { if (point === EFFECT_FAULT_POINTS.git) throw new Error('grouped Git completion failed'); });
+ for (let i = 0; i < 3; i++) await attempt(engine, ctx, effect.id);
+ expect(await gitEffect(engine, slug)).toMatchObject({ state: 'queued', data: { target_failures: 4, failing_target: slug } });
+ await attempt(engine, ctx, effect.id);
+ expect(await gitEffect(engine, slug)).toMatchObject({ state: 'failed', error_code: 'targets_parked', data: { parked: [{ slug }] } });
+ });
+}, 120_000);