Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

WIP #6712 lane C: convergence kill rounds at sync:retry_deferred / sync:held_settled prime a file edited after its freeze

garrytane5eaf651f1f9
diff --git a/test/fixtures/convergence-fault-kill.ts b/test/fixtures/convergence-fault-kill.ts
index 23371dc79c..6f953bb6fc 100644
--- a/test/fixtures/convergence-fault-kill.ts
+++ b/test/fixtures/convergence-fault-kill.ts
@@ -10,12 +10,17 @@
* edit write `edit.content` to `edit.file` (an uncommitted worktree edit), then continue;
* stall wait until the harness creates the `release` file, or for `ms` (at most 600 s), then continue;
* throw throw an error carrying SQLSTATE `sqlstate` (default P0001), as the driver reports a database error.
+ *
+ * `prime` (#6712) sets up the condition the fault point needs: an uncommitted edit (`prime.edit`) written at the
+ * `prime.nth` hit of `prime.point` (filtered by `prime.path`) in the same process, before any hit of the fault's point
+ * is counted, so a file changed after its freeze reaches the deferral and hold points.
*/
import { existsSync, writeFileSync } from 'node:fs';
import { installFaultHook, type FaultPoint } from '../../src/core/persistence/fault-points.ts';
interface Fault { point: FaultPoint; nth: number; marker: string; operation?: string; path?: string; action?: keyof typeof ACTIONS;
- edit?: { file: string; content: string }; release?: string; ms?: number; sqlstate?: string }
+ edit?: { file: string; content: string }; release?: string; ms?: number; sqlstate?: string;
+ prime?: { point: FaultPoint; nth: number; path?: string; edit: { file: string; content: string } } }
const ACTIONS = {
kill: () => { process.kill(process.pid, 'SIGKILL'); },
@@ -35,8 +40,9 @@ if (!raw) throw new Error('convergence-fault-kill needs GBRAIN_TEST_CONVERGENCE_
const fault = JSON.parse(raw) as Fault;
const action = fault.action ?? 'kill';
if (!(action in ACTIONS)) throw new Error(`convergence-fault-kill: unknown action '${action}' (known: ${Object.keys(ACTIONS).join(', ')}).`);
-let seen = 0;
+let seen = 0, primed = 0;
installFaultHook(async (point, detail) => {
+ if (fault.prime && point === fault.prime.point && (!fault.prime.path || detail.path === fault.prime.path) && ++primed === fault.prime.nth) writeFileSync(fault.prime.edit.file, fault.prime.edit.content);
if (point !== fault.point || (fault.operation && detail.operation !== fault.operation) || (fault.path && detail.path !== fault.path)) return;
if (++seen !== fault.nth) return;
writeFileSync(fault.marker, JSON.stringify({ point, nth: seen, pid: process.pid, requestId: detail.requestId, operation: detail.operation ?? null,
diff --git a/test/sync-convergence.serial.test.ts b/test/sync-convergence.serial.test.ts
index b18e030a4d..f559fb7d4b 100644
--- a/test/sync-convergence.serial.test.ts
+++ b/test/sync-convergence.serial.test.ts
@@ -130,15 +130,17 @@ const ENTITY = 'people/alice-example';
* file-publication pair (`before_publication`/`after_publication`) never fires for it. Per-page seams are counted
* per submit_job request (nth inside the first 60% of a round); `lane:applied` and `sync:before_group_admission`
* fire once per bulk group, and a small round may form one group, so they kill at the first; `sync:mid_checkpoint`
- * fires on every cursor save (the first or second); #6712's `sync:held_settled` and `sync:retry_deferred` fire on the
- * cursor step that holds a failed entry or defers a changed one (the first or second), and only in a round that has one.
+ * fires on every cursor save (the first or second). #6712's `sync:retry_deferred` (the first or second deferral) and
+ * `sync:held_settled` (the hold) need a file that changes after its freeze: their round primes one with an uncommitted
+ * edit at `sync:after_freeze`, which is deferred `DEFER_PER_ENTRY` times and then held `worktree_dirty`; the harness
+ * commits the edit after the round.
*/
const KILL_POINTS = [
{ point: 'publication:before_commit', per: 'page' }, { point: 'publication:after_commit', per: 'page' },
{ point: 'consumer:preparing', per: 'page' }, { point: 'lane:applied', per: 'group' },
{ point: 'sync:before_group_admission', per: 'group' }, { point: 'sync:mid_checkpoint', per: 'save' },
- { point: 'sync:held_settled', per: 'save' }, { point: 'sync:retry_deferred', per: 'save' },
-] as const satisfies ReadonlyArray<{ point: FaultPoint; per: 'page' | 'group' | 'save' }>;
+ { point: 'sync:held_settled', per: 'held' }, { point: 'sync:retry_deferred', per: 'deferred' },
+] as const satisfies ReadonlyArray<{ point: FaultPoint; per: 'page' | 'group' | 'save' | 'held' | 'deferred' }>;
const MAX_RECOVERY_RUNS = 2;
/** Oracle tests are named by the persistence gate's violation class (scripts/persistence/model.ts) they would report. */
const as = (violation: ViolationClass, title: string): string => `[${violation}] ${title}`;
@@ -310,7 +312,8 @@ class LatencyProxy {
// ---------------------------------------------------------------- one brain
interface Fault { point: FaultPoint; nth: number; marker: string; operation?: string; path?: string; action?: 'kill' | 'edit' | 'stall' | 'throw';
- edit?: { file: string; content: string }; release?: string; ms?: number; sqlstate?: string }
+ edit?: { file: string; content: string }; release?: string; ms?: number; sqlstate?: string;
+ prime?: { point: FaultPoint; nth: number; path?: string; edit: { file: string; content: string } } }
interface Run { code: number; out: string; err: string; ms: number }
interface SyncRun { proc: ReturnType<typeof Bun.spawn>; result: Promise<Run> }
@@ -834,8 +837,8 @@ scenario(['a', 'b', 'c'], 'managed sync converges after a seeded kill loop of cl
const plan = Array.from({ length: kinds.length ? KILLS : 0 }, (_, k) => {
const kind = kinds[(k + offset) % kinds.length];
const { point, per } = KILL_POINTS[(k + pointOffset) % KILL_POINTS.length];
- const nth = per === 'page' ? b.between(2, Math.floor(perRound * 0.6)) : per === 'group' ? 1 : b.between(1, 2);
- return { round: k + 1, kind, point, nth, operation: per === 'page' || point === 'lane:applied' ? 'submit_job' : undefined };
+ const nth = per === 'page' ? b.between(2, Math.floor(perRound * 0.6)) : per === 'group' || per === 'held' ? 1 : b.between(1, 2);
+ return { round: k + 1, kind, point, nth, operation: per === 'page' || point === 'lane:applied' ? 'submit_job' : undefined, primed: per === 'held' || per === 'deferred' };
});
b.plan = plan.map(p => `round ${p.round} ${p.kind} ${p.point} #${p.nth}`);
const putTargets = runs('c') ? [...new Set(Array.from({ length: 40 }, () => b.between(0, NOTES - 1)))].slice(0, Math.round(NOTES * 0.05)).map(noteSlug) : [];
@@ -846,9 +849,12 @@ scenario(['a', 'b', 'c'], 'managed sync converges after a seeded kill loop of cl
for (const p of plan) {
const started = performance.now();
const tag = `round-${p.round}`;
- const fault: Fault = { point: p.point, nth: p.nth, marker: b.marker(tag), operation: p.operation };
const first = (p.round * perRound) % NOTES;
const indexes = Array.from({ length: perRound }, (_, i) => (first + i) % NOTES);
+ const edited = p.primed ? indexes[Math.floor(perRound / 2)]! : null;
+ const fault: Fault = { point: p.point, nth: p.nth, marker: b.marker(tag), operation: p.operation,
+ ...(edited !== null ? { prime: { point: 'sync:after_freeze', nth: 1, path: `${noteSlug(edited)}.md`,
+ edit: { file: join(b.repo, `${noteSlug(edited)}.md`), content: noteText(edited, `Round ${p.round} edit`) } } } : {}) };
b.writeNotes(indexes, `Round ${p.round}`, `round ${p.round}`, p.round % 3 === 1 ? [b.bigFile(120 + 20 * p.round, 400 + 40 * p.round, `v${p.round}`)] : []);
let line: string;
if (p.kind === 'client') {
@@ -868,6 +874,11 @@ scenario(['a', 'b', 'c'], 'managed sync converges after a seeded kill loop of cl
if (plan[p.round - 2]?.kind === 'client') afterClientKill.push(tag);
await serve.stop();
}
+ if (edited !== null) {
+ const editStart = performance.now();
+ b.git('add', '--', `${noteSlug(edited)}.md`); b.git('commit', '-qm', `round ${p.round}: the editor commits`, '--', `${noteSlug(edited)}.md`);
+ b.ledger.record({ kind: 'commit', slug: noteSlug(edited), marker: noteMarker(edited, `Round ${p.round} edit`), touches: ['db', 'file'], start: editStart, ack: performance.now() });
+ }
const fired = b.recordFault(tag, `round ${p.round} ${p.kind} ${p.point} #${p.nth}`);
b.note(`round ${p.round} (${p.kind}): ${fired ? `fault fired ${fired}` : 'no fault fired'}; ${line}`);
b.elapsed[`${tag}_ms`] = performance.now() - started;