Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
projections drain: heal a stale queue row under the page guard instead of looping on it (PR #6400 b)
garrytanb2c6005c8223
diff --git a/docs/guides/repair.md b/docs/guides/repair.mdindex 487466c031..fd661914d2 100644--- a/docs/guides/repair.md+++ b/docs/guides/repair.md@@ -263,6 +263,18 @@ process gets there first. On PGLite a resident process holds the datastore, sothe drain refuses before opening it (also for a mounted PGLite brain selectedwith `--brain`).+A queue row that no longer matches its live page (a legacy or hand-edited+row, or a page recreated under a new source incarnation) is healed under the+page lock instead of being counted again: a stale-revision row is re-keyed to+the page's current revision and rebuilt in the same pass, a row for a page+that is already projected or for a dead incarnation is deleted (`superseded`+in the summary), and only the exact row the drain listed is touched, so a+newer row the page trigger queued meanwhile survives. A page whose content+changes while it is being rebuilt is listed once under `failed` with a+`revision_conflict:` reason, stays queued at its new revision, and is+rebuilt on the next run. The drain continues while a pass rebuilt, removed,+failed or deferred a row and stops on a pass that did nothing.+Verify: `gbrain doctor` shows `text_projection_readiness` ok.<a id="embedding-key-source"></a>diff --git a/src/commands/projections.ts b/src/commands/projections.tsindex 359147b8af..cb6a523800 100644--- a/src/commands/projections.ts+++ b/src/commands/projections.ts@@ -47,6 +47,9 @@ export function projectionFailureNextAction(failure: ProjectionRebuildFailure):if (failure.reason.startsWith('This page kind requires its source importer')) {return `re-import it from its source: \`gbrain sync --source ${failure.source_id}\``;}+ if (failure.reason.startsWith('revision_conflict:')) {+ return 'the page changed while it was being rebuilt; it stays queued at its new revision and `gbrain projections drain` rebuilds it on its next run';+ }return 'run `gbrain doctor`; the page stays queued and `gbrain projections drain` tries it again on its next run';}diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex 8ca6b08d25..d739eb8b2c 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -439,6 +439,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText }{ since: '0.60.169.0', text: '`recall` takes an optional `question` and returns saved facts ranked by relevance to it (facts below the match threshold are left out); calls without it still return the newest facts, every response now says `facts_order`, and a call that passes only `query` carries a `recall_hint` notice. `gbrain recall --question` passes the question instead of reading its value as an entity name. In `query`, the facts of an entity the question names come only from that entity page\'s own source, and the temporal fact reserve (`search.temporal_fact_reserve`, off by default) scores with the same question scorer: whole-word matches, and a long fact\'s word matches count for less.' },// Fix wave 15 G3 (GBRA-79). `since` is provisional (0.60.176.0); the integrator restamps it at the merge slot.{ since: '0.60.176.0', text: '`gbrain extract-conversation-facts` now walks a source\'s pages by slug (a keyset) instead of OFFSET over `updated_at`, so a page is listed, extracted and frozen once per run even while other writers touch pages that share one timestamp; a page the run sees twice is counted as `pages_skipped_duplicate_listing` with no second model call. A batch request the writer refused as malformed (`invalid_params`, the shape a page listed twice produced) is no longer a permanent block: its stored entries are resubmitted on the next run with zero model calls, up to 3 failed requests per page version, and one failed request counts once however many times it listed the page. `list_pages` sorted by `updated_desc` (the default) now breaks timestamp ties by slug, source and id, so ties page deterministically; offset paging is still unstable under writes that change `updated_at`.' },+ { since: '0.60.176.0', text: '`gbrain projections drain` (and the migration drain) no longer loops on one queue row whose revision does not match its page: the row is re-keyed to the page\'s current revision and rebuilt in the same pass, or deleted when the page is already projected or belongs to a dead source incarnation, always as a compare-and-set on the exact row listed so a newer queued row survives. A page whose content changes while it is being rebuilt appears once under `failed` with a `revision_conflict:` reason and stays queued for the next run; `--json` may now list such rows where the command used to hang.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/page-state/projections.ts b/src/core/page-state/projections.tsindex 885e8f1ad8..b79cf22b16 100644--- a/src/core/page-state/projections.ts+++ b/src/core/page-state/projections.ts@@ -374,6 +374,14 @@ export interface ProjectionRebuildOptions {pages?: { sourceId: string; slugs: readonly string[] };/** Receives each failed page; without it a generic stderr line is printed. */onFailure?: (failure: ProjectionRebuildFailure) => void;+ /**+ * Receives each queue row this call consumed without a rebuild: `removed`+ * (a stale row deleted under the page guard) or `deferred` (a page whose+ * revision moved during its install, stamped `updated_at=now()` so a run+ * bounded by `notAfter` does not try it again). Progress, unlike a bare+ * `superseded` no-op.+ */+ onHeal?: (heal: { kind: 'removed' | 'deferred'; source_id: string; slug: string }) => void;}/** Live Markdown and code rows a rebuild can take, and how many of them last failed. */@@ -386,7 +394,20 @@ export async function projectionBacklog(engine: Pick<BrainEngine, 'executeRaw'>)return { pending: Number(row?.pending ?? 0), failed: Number(row?.failed ?? 0), oldest_age_seconds: oldest };}-/** Bounded and keyless. Unsupported media remains queued for its source importer. */+/**+ * Bounded and keyless. Unsupported media remains queued for its source importer.+ *+ * A queue row that no longer matches its live page is healed under the page+ * guard (PR #6400 (b)), with a compare-and-set on the exact+ * (source_incarnation, slug, revision) this call listed, so a newer row the+ * `pages` trigger queued meanwhile survives: a row of a dead incarnation is+ * deleted (never re-keyed onto the live one, which has its own rows); a row+ * whose revision is stale under the live incarnation is deleted when the page+ * is already projected, else re-keyed to the live `knowledge_revision` and+ * rebuilt in the same pass. A row another worker consumed is a no-op+ * (`superseded`). A page whose revision moves during its install is deferred+ * by `updated_at` and reported through `onFailure` once per run.+ */export async function rebuildPendingPageProjections(engine: BrainEngine, limit = 20, opts: ProjectionRebuildOptions = {}): Promise<{ rebuilt: number; superseded: number }> {const now = opts.now ?? Date.now;const startedAt = now();@@ -407,27 +428,45 @@ export async function rebuildPendingPageProjections(engine: BrainEngine, limit =let superseded = 0;for (const [index, job] of jobs.entries()) {if (opts.deadlineMs !== undefined && index > 0 && now() - startedAt >= opts.deadlineMs) break;+ const observed = [job.source_incarnation, job.slug, job.revision];try {const prepared = await engine.transaction(async tx => {await tx.lockPageKeys([{ sourceId: job.source_id, slug: job.slug }]);const pending = await tx.executeRaw(`SELECT 1 FROM page_projection_jobs- WHERE source_incarnation=$1::uuid AND slug=$2 AND revision=$3::uuid`, [job.source_incarnation, job.slug, job.revision]);+ WHERE source_incarnation=$1::uuid AND slug=$2 AND revision=$3::uuid`, observed);if (!pending.length) return null;- return readGuardedProjectionSnapshot(tx, job.slug, job.source_id, { allowUnsealed: true });+ const read = await readGuardedProjectionSnapshot(tx, job.slug, job.source_id, { allowUnsealed: true });+ if (!read) return null;+ const { snapshot } = read;+ if (snapshot.sourceIncarnation === job.source_incarnation && snapshot.revision === job.revision) return read;+ if (snapshot.sourceIncarnation !== job.source_incarnation || snapshot.page.text_projection_revision === snapshot.revision) {+ await tx.executeRaw('DELETE FROM page_projection_jobs WHERE source_incarnation=$1::uuid AND slug=$2 AND revision=$3::uuid', observed);+ return 'removed';+ }+ await tx.executeRaw(`UPDATE page_projection_jobs SET revision=$4::uuid,updated_at=now()+ WHERE source_incarnation=$1::uuid AND slug=$2 AND revision=$3::uuid`, [...observed, snapshot.revision]);+ return read;});- if (!prepared || prepared.snapshot.sourceIncarnation !== job.source_incarnation || prepared.snapshot.revision !== job.revision) { superseded++; continue; }+ if (!prepared) { superseded++; continue; }+ if (prepared === 'removed') { superseded++; opts.onHeal?.({ kind: 'removed', source_id: job.source_id, slug: job.slug }); continue; }const projection = await preparePageProjection(prepared);await installPageProjection(engine, prepared, projection.chunks, { seal: true, preserveEmbeddings: true, code: projection.code });rebuilt++;} catch (error) {if (!(error instanceof PageRevisionConflictError)) {await engine.executeRaw(`UPDATE page_projection_jobs SET reason='rebuild_failed',updated_at=now()- WHERE source_incarnation=$1::uuid AND slug=$2 AND revision=$3::uuid`, [job.source_incarnation, job.slug, job.revision]);+ WHERE source_incarnation=$1::uuid AND slug=$2 AND revision=$3::uuid`, observed);if (opts.onFailure) opts.onFailure({ source_id: job.source_id, slug: job.slug, reason: (error instanceof Error ? error.message : String(error)).split('\n')[0].slice(0, 300) });else process.stderr.write('[gbrain] Projection rebuild failed; work remains queued. Inspect projection readiness and the recorded source path.\n');continue;}- superseded++;+ // The page moved under its install: defer the exact row this call listed+ // (a newer trigger-queued row already carries its own stamp) and report it.+ const deferred = await engine.executeRaw(`UPDATE page_projection_jobs SET updated_at=now()+ WHERE source_incarnation=$1::uuid AND slug=$2 AND revision=$3::uuid RETURNING slug`, observed);+ if (!deferred.length) { superseded++; continue; }+ opts.onHeal?.({ kind: 'deferred', source_id: job.source_id, slug: job.slug });+ opts.onFailure?.({ source_id: job.source_id, slug: job.slug, reason: `revision_conflict: ${error.message.split('\n')[0].slice(0, 280)}` });}}if (rebuilt > 0) {@@ -472,16 +511,21 @@ export async function drainProjections(engine: BrainEngine, opts: { limit?: numblet superseded = 0;let tried = 0;try {+ // Continue while a batch rebuilt, removed, failed or durably deferred a+ // row; stop on a no-op batch. A bare `superseded` row (another worker+ // consumed it) is not progress, so one row can never spin the drain.while (opts.limit === undefined || tried < opts.limit) {- const failuresBefore = failed.length;+ let healed = 0;+ let failedNow = 0;const batch = await rebuildPendingPageProjections(engine, Math.min(DRAIN_BATCH, (opts.limit ?? Infinity) - tried),- { notAfter: runStart, reasons: opts.reasons, onFailure: failure => failed.push(failure) });- const attempted = batch.rebuilt + batch.superseded + failed.length - failuresBefore;- if (attempted === 0) break;+ { notAfter: runStart, reasons: opts.reasons, onHeal: () => { healed++; },+ onFailure: failure => { failed.push(failure); if (!failure.reason.startsWith('revision_conflict:')) failedNow++; } });+ const progressed = batch.rebuilt + healed + failedNow;+ if (progressed === 0) break;rebuilt += batch.rebuilt;superseded += batch.superseded;- tried += attempted;- opts.progress?.tick(attempted, `${rebuilt} rebuilt, ${failed.length} failed`);+ tried += progressed;+ opts.progress?.tick(progressed, `${rebuilt} rebuilt, ${failed.length} failed`);}} finally {opts.progress?.finish();diff --git a/test/e2e/projections-drain-stale-row-6400-postgres.test.ts b/test/e2e/projections-drain-stale-row-6400-postgres.test.tsnew file mode 100644index 0000000000..92cf3ab7ba--- /dev/null+++ b/test/e2e/projections-drain-stale-row-6400-postgres.test.ts@@ -0,0 +1,3 @@+import { registerPostgresTests } from '../helpers/test-backends.ts';++await registerPostgresTests(() => import('../projections-drain-stale-row-6400.test.ts'));diff --git a/test/projections-drain-stale-row-6400.test.ts b/test/projections-drain-stale-row-6400.test.tsnew file mode 100644index 0000000000..08acf654d1--- /dev/null+++ b/test/projections-drain-stale-row-6400.test.ts@@ -0,0 +1,192 @@+/**+ * PR #6400 (b): `gbrain projections drain` looped forever on one queue row+ * whose revision no longer matched the live page, because the rebuild counted+ * an untouched "superseded" row as progress and never consumed it.+ *+ * Protects: a stale-revision row under the live incarnation is re-keyed to the+ * live `knowledge_revision` under the page guard and rebuilt in the same pass+ * (a page already projected has its row deleted instead); the repair is a+ * compare-and-set on the exact (source_incarnation, slug, revision) it+ * observed, so a newer row the `pages` trigger queued meanwhile survives;+ * another worker completing the job and a deleted/recreated page are no-ops;+ * a page that keeps raising PageRevisionConflictError is deferred by+ * `updated_at`, reported once in `failed[]`, and the drain terminates.+ * Fails when: the drain runs past the iteration cap on one stale row, the+ * `--limit 5` run counts the same row five times, a stale repair overwrites+ * a newer queued revision, or a hot page is reported more than once.+ * Seams: an engine proxy around `transaction` (the probe's iteration cap and+ * the concurrent-write races). PGLite always; Postgres when DATABASE_URL is+ * set (test/e2e/projections-drain-stale-row-6400-postgres.test.ts).+ */+import { afterAll, beforeAll, expect, test } from 'bun:test';+import type { BrainEngine } from '../src/core/engine.ts';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import { PageRevisionConflictError } from '../src/core/page-state/types.ts';+import { drainProjections, projectionBacklog, rebuildPendingPageProjections } from '../src/core/page-state/projections.ts';+import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';+import { testBackends } from './helpers/test-backends.ts';++const backends = testBackends();+const engines: BrainEngine[] = [];+let closePostgres: (() => Promise<void>) | undefined;+let sourceSeq = 0;++beforeAll(async () => {+ if (backends.includes('pglite')) { const lite = new PGLiteEngine(); await lite.connect({}); await lite.initSchema(); engines.push(lite); }+ if (backends.includes('postgres')) { const pg = await isolatedPersistencePostgres(process.env.DATABASE_URL!); engines.push(pg.engine); closePostgres = pg.close; }+}, 120_000);+afterAll(async () => {+ for (const engine of engines) if (engine.kind === 'pglite') await engine.disconnect();+ await closePostgres?.();+});++interface JobRow { slug: string; revision: string; reason: string }+const jobs = (engine: BrainEngine, sourceId: string) => engine.executeRaw<JobRow>(+ `SELECT j.slug, j.revision::text AS revision, j.reason FROM page_projection_jobs j JOIN sources s ON s.incarnation=j.source_incarnation WHERE s.id=$1 ORDER BY j.slug`, [sourceId]);+const liveRevision = async (engine: BrainEngine, sourceId: string, slug: string) =>+ (await engine.executeRaw<{ r: string }>('SELECT knowledge_revision::text AS r FROM pages WHERE source_id=$1 AND slug=$2', [sourceId, slug]))[0]!.r;++/** One source with `pages` unprojected pages, each queued at its live revision. */+async function backlog(engine: BrainEngine, pages: number): Promise<string> {+ await engine.executeRaw('DELETE FROM page_projection_jobs');+ const sourceId = `stale-${++sourceSeq}`;+ await engine.executeRaw('INSERT INTO sources(id,name) VALUES($1,$1)', [sourceId]);+ for (let i = 0; i < pages; i++) {+ await engine.putPage(`notes/n-${i}`, { type: 'note', title: `Note ${i}`, compiled_truth: `Example note ${i} about a sample topic.` }, { sourceId });+ }+ await engine.executeRaw('UPDATE pages SET text_projection_revision=NULL WHERE source_id=$1', [sourceId]);+ await engine.executeRaw(`INSERT INTO page_projection_jobs(source_incarnation,slug,revision,reason)+ SELECT s.incarnation,p.slug,p.knowledge_revision,'test_backlog' FROM pages p JOIN sources s ON s.id=p.source_id WHERE p.source_id=$1+ ON CONFLICT(source_incarnation,slug) DO UPDATE SET revision=EXCLUDED.revision,reason=EXCLUDED.reason,updated_at=now()`, [sourceId]);+ return sourceId;+}++/** An engine whose `transaction` runs `before` first (a concurrent writer) and refuses after `cap` calls (the probe's bound). */+function raced(engine: BrainEngine, opts: { cap?: number; before?: (n: number) => Promise<void> } = {}) {+ const transaction = engine.transaction.bind(engine);+ const state = { transactions: 0 };+ const proxy = new Proxy(engine, { get(target, key) {+ if (key === 'transaction') return async <T>(run: (tx: BrainEngine) => Promise<T>) => {+ state.transactions++;+ if (opts.cap !== undefined && state.transactions > opts.cap) throw new Error(`drain iteration cap of ${opts.cap} transactions reached`);+ await opts.before?.(state.transactions);+ return transaction(run);+ };+ const value = Reflect.get(target, key, target); return typeof value === 'function' ? value.bind(target) : value;+ } });+ return { engine: proxy, state };+}++test('an unlimited drain over one stale-revision row re-keys it to the live revision, rebuilds it once and terminates', async () => {+ for (const engine of engines) {+ const sourceId = await backlog(engine, 1);+ await engine.executeRaw('UPDATE page_projection_jobs SET revision=gen_random_uuid()');+ const bounded = raced(engine, { cap: 50 });+ const result = await drainProjections(bounded.engine);+ expect(result).toMatchObject({ rebuilt: 1, superseded: 0, failed: [], remaining: 0, limited: false });+ expect(bounded.state.transactions).toBeLessThan(50);+ expect(await jobs(engine, sourceId)).toEqual([]);+ const [page] = await engine.executeRaw<{ projected: boolean }>('SELECT text_projection_revision=knowledge_revision AS projected FROM pages WHERE source_id=$1', [sourceId]);+ expect(page!.projected).toBe(true);+ }+}, 120_000);++test('--limit 5 over one stale row tries it once, never five times', async () => {+ for (const engine of engines) {+ await backlog(engine, 1);+ await engine.executeRaw('UPDATE page_projection_jobs SET revision=gen_random_uuid()');+ expect(await drainProjections(engine, { limit: 5 })).toEqual({ rebuilt: 1, superseded: 0, failed: [], remaining: 0, limited: false });+ }+}, 120_000);++test('a stale row on a page that is already projected is deleted, not rebuilt', async () => {+ for (const engine of engines) {+ const sourceId = await backlog(engine, 1);+ await engine.executeRaw('UPDATE pages SET text_projection_revision=knowledge_revision WHERE source_id=$1', [sourceId]);+ // The pages trigger clears the queue on a projected page; re-seed the legacy row under a stale revision.+ await engine.executeRaw(`INSERT INTO page_projection_jobs(source_incarnation,slug,revision,reason)+ SELECT s.incarnation,'notes/n-0',gen_random_uuid(),'legacy' FROM sources s WHERE s.id=$1`, [sourceId]);+ const bounded = raced(engine, { cap: 50 });+ expect(await drainProjections(bounded.engine)).toMatchObject({ rebuilt: 0, superseded: 1, failed: [], remaining: 0 });+ expect(await jobs(engine, sourceId)).toEqual([]);+ }+}, 120_000);++test('a stale repair racing a newer canonical write leaves the trigger-queued row intact (compare-and-set)', async () => {+ for (const engine of engines) {+ const sourceId = await backlog(engine, 1);+ await engine.executeRaw('UPDATE page_projection_jobs SET revision=gen_random_uuid()');+ // Between the listing and the guard, a canonical write bumps knowledge_revision: the trigger replaces the queue row.+ const race = raced(engine, { before: async n => {+ if (n === 1) await engine.putPage('notes/n-0', { type: 'note', title: 'Note 0 (edited)', compiled_truth: 'Edited example note about a sample topic.' }, { sourceId });+ } });+ const result = await rebuildPendingPageProjections(race.engine, 100, { notAfter: (await engine.executeRaw<{ t: string }>('SELECT now()::text AS t'))[0]!.t });+ expect(result).toEqual({ rebuilt: 0, superseded: 1 });+ const queued = await jobs(engine, sourceId);+ expect(queued).toEqual([{ slug: 'notes/n-0', revision: await liveRevision(engine, sourceId, 'notes/n-0'), reason: 'canonical_change' }]);+ // The newer row is live work: the next drain rebuilds it.+ expect(await drainProjections(engine)).toMatchObject({ rebuilt: 1, superseded: 0, remaining: 0 });+ }+}, 120_000);++test('another worker completing the job and a deleted-then-recreated page are no-ops that terminate', async () => {+ for (const engine of engines) {+ const sourceId = await backlog(engine, 2);+ await engine.executeRaw("UPDATE page_projection_jobs SET revision=gen_random_uuid() WHERE slug='notes/n-0'");+ const race = raced(engine, { before: async n => {+ // n-0: another worker rebuilds it (the row is consumed) before this worker's guard.+ if (n === 1) expect(await rebuildPendingPageProjections(engine, 100)).toMatchObject({ rebuilt: 2 });+ } });+ expect(await rebuildPendingPageProjections(race.engine, 100)).toEqual({ rebuilt: 0, superseded: 2 });+ expect(await jobs(engine, sourceId)).toEqual([]);++ const recreated = await backlog(engine, 1);+ const incarnation = (await engine.executeRaw<{ i: string }>('SELECT incarnation::text AS i FROM sources WHERE id=$1', [recreated]))[0]!.i;+ const recreate = raced(engine, { before: async n => {+ if (n !== 1) return;+ await engine.executeRaw('DELETE FROM pages WHERE source_id=$1', [recreated]);+ await engine.executeRaw('DELETE FROM sources WHERE id=$1', [recreated]);+ await engine.executeRaw('INSERT INTO sources(id,name) VALUES($1,$1)', [recreated]);+ await engine.putPage('notes/n-0', { type: 'note', title: 'Note 0 again', compiled_truth: 'Recreated example note about a sample topic.' }, { sourceId: recreated });+ } });+ const bounded = raced(recreate.engine, { cap: 50 });+ const result = await drainProjections(bounded.engine);+ expect(result).toMatchObject({ rebuilt: 0, failed: [], limited: false });+ expect((await engine.executeRaw<{ i: string }>('SELECT incarnation::text AS i FROM sources WHERE id=$1', [recreated]))[0]!.i).not.toBe(incarnation);+ // The recreated page's own row (queued after the run start) is the only work left, for the next run.+ expect(await jobs(engine, recreated)).toEqual([{ slug: 'notes/n-0', revision: await liveRevision(engine, recreated, 'notes/n-0'), reason: 'canonical_change' }]);+ expect(await drainProjections(engine)).toMatchObject({ rebuilt: 1, remaining: 0 });+ }+}, 120_000);++test('a page that keeps raising PageRevisionConflictError is deferred, reported once in failed[], and the drain terminates', async () => {+ for (const engine of engines) {+ const sourceId = await backlog(engine, 3);+ const transaction = engine.transaction.bind(engine);+ // Every second read of notes/n-1 is the install's revision check: the page moved under it every time.+ let n1Attempts = 0;+ const conflicting = new Proxy(engine, { get(target, key) {+ if (key === 'transaction') return async <T>(run: (tx: BrainEngine) => Promise<T>) => transaction(async tx => {+ const probe = new Proxy(tx, { get(t, k) {+ if (k === 'readPageSnapshot') return async (slug: string, opts: unknown) => {+ const snapshot = await t.readPageSnapshot(slug, opts as never);+ if (slug === 'notes/n-1' && snapshot && ++n1Attempts % 2 === 0) throw new PageRevisionConflictError(snapshot.revision, 'ffffffff-ffff-4fff-8fff-ffffffffffff');+ return snapshot;+ };+ const value = Reflect.get(t, k, t); return typeof value === 'function' ? value.bind(t) : value;+ } });+ return run(probe as BrainEngine);+ });+ const value = Reflect.get(target, key, target); return typeof value === 'function' ? value.bind(target) : value;+ } });+ const bounded = raced(conflicting, { cap: 60 });+ const before = (await engine.executeRaw<{ at: string }>("SELECT updated_at::text AS at FROM page_projection_jobs WHERE slug='notes/n-1'"))[0]!.at;+ const result = await drainProjections(bounded.engine);+ expect(result).toMatchObject({ rebuilt: 2, superseded: 0, remaining: 1, limited: false });+ expect(result.failed).toEqual([expect.objectContaining({ source_id: sourceId, slug: 'notes/n-1', reason: expect.stringContaining('revision_conflict') })]);+ const [row] = await engine.executeRaw<{ reason: string; at: string }>("SELECT reason, updated_at::text AS at FROM page_projection_jobs WHERE slug='notes/n-1'");+ expect(row!.reason).toBe('test_backlog');+ expect(row!.at).not.toBe(before);+ expect((await projectionBacklog(engine)).failed).toBe(0);+ }+}, 120_000);