Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(#6340): hold origin-identity faults and deletes too, mark page-fault holds overtaken, detect deleted pages as moved, keep --retry-failed rediscovery for content refusals; tests that asserted the stop now assert the hold

garrytanae0a8f0bf4b7
diff --git a/docs/guides/error-codes.md b/docs/guides/error-codes.md
index dc0671fc28..22f384cb84 100644
--- a/docs/guides/error-codes.md
+++ b/docs/guides/error-codes.md
@@ -548,7 +548,7 @@ More: [docs/guides/write-refusals.md#concurrent_write](../../docs/guides/write-r
|---|---|---|---|---|---|---|
| The managed sync drain lost its database connection three times in a row without committing a page in between, so it stopped where the cursor stands; nothing is recorded against the source. | A pooler drop (ECONNABORTED, ECONNRESET, ETIMEDOUT, EPIPE) is a transport fault, not a page fault: the drain reconnects and retries at 5, 15 and 45 seconds, and the frozen manifest and cursor stay as they are. Three consecutive drops with no progress mean the database is unreachable from here for now. | Check the database URL and pooler (gbrain doctor --json), then rerun the same gbrain sync; it resumes at the stored cursor without re-freezing the manifest. | agent | `repeat the read that failed` | 1 | yes |
-More: [docs/guides/sync-unblock-runbook.md#connection](../../docs/guides/sync-unblock-runbook.md#connection)
+More: [docs/guides/write-refusals.md#drain-connection-lost](../../docs/guides/write-refusals.md#drain-connection-lost)
### connector_account_changed
diff --git a/src/core/error-catalogue.ts b/src/core/error-catalogue.ts
index 2f83ecaec3..a8e99d3f74 100644
--- a/src/core/error-catalogue.ts
+++ b/src/core/error-catalogue.ts
@@ -75,7 +75,7 @@ export const ERROR_CATALOGUE = {
sync_drain_preparation_abandoned: { code: 'preparation_abandoned', docs: 'docs/guides/write-refusals.md#drain-preparation-abandoned' },
sync_drain_preparation_systemic: { code: 'preparation_systemic', docs: 'docs/guides/write-refusals.md#preparation_systemic' },
sync_drain_write_capacity: { code: 'queue_capacity', docs: 'docs/guides/write-refusals.md#drain-write-capacity' },
- sync_drain_connection_lost: { code: 'connection_lost', docs: 'docs/guides/sync-unblock-runbook.md#connection' },
+ sync_drain_connection_lost: { code: 'connection_lost', docs: 'docs/guides/write-refusals.md#drain-connection-lost' },
} as const satisfies Record<string, CatalogueEntry>;
export type CatalogueName = keyof typeof ERROR_CATALOGUE;
diff --git a/src/core/error-registry.ts b/src/core/error-registry.ts
index 03364d39d5..7e13a2850d 100644
--- a/src/core/error-registry.ts
+++ b/src/core/error-registry.ts
@@ -108,7 +108,7 @@ export const CODES = {
connection_lost: { class: 'retryable', retryable: true, actor: 'agent',
summary: "The managed sync drain lost its database connection three times in a row without committing a page in between, so it stopped where the cursor stands; nothing is recorded against the source.",
why: "A pooler drop (ECONNABORTED, ECONNRESET, ETIMEDOUT, EPIPE) is a transport fault, not a page fault: the drain reconnects and retries at 5, 15 and 45 seconds, and the frozen manifest and cursor stay as they are. Three consecutive drops with no progress mean the database is unreachable from here for now.",
- docs: 'docs/guides/sync-unblock-runbook.md#connection',
+ docs: 'docs/guides/write-refusals.md#drain-connection-lost',
suggestion: 'Check the database URL and pooler (gbrain doctor --json), then rerun the same gbrain sync; it resumes at the stored cursor without re-freezing the manifest.' },
connector_account_changed: { class: 'caller', summary: "The connector credential resolves to a different account than the source is pinned to." },
connector_fence_below_timeline: { class: 'caller', summary: "A stored page carries a fence the connector render cannot preserve." },
diff --git a/src/core/persistence/sync-page-fault.ts b/src/core/persistence/sync-page-fault.ts
index 96b26fe7b8..2270e7ee6e 100644
--- a/src/core/persistence/sync-page-fault.ts
+++ b/src/core/persistence/sync-page-fault.ts
@@ -84,11 +84,14 @@ export async function pageChangeProof(engine: Pick<BrainEngine, 'executeRaw'>, i
return { request_id: writer.request_id, operation: writer.operation, revision: page.revision };
}
-/** The page's live revision (null when it no longer exists), for a hold that records what it observed. */
+/**
+ * The page's current revision, soft-deleted pages included (a deletion advances the revision, and a new-file entry whose slug
+ * a page now occupies has moved too); null when no row exists. For a hold that records what it observed.
+ */
export async function liveRevision(engine: Pick<BrainEngine, 'executeRaw'>, sourceId: string, page: { pageId: number | null; slug: string }): Promise<string | null> {
const [row] = page.pageId === null
- ? await engine.executeRaw<{ revision: string | null }>('SELECT knowledge_revision::text AS revision FROM pages WHERE source_id=$1 AND slug=$2 AND deleted_at IS NULL', [sourceId, page.slug])
- : await engine.executeRaw<{ revision: string | null }>('SELECT knowledge_revision::text AS revision FROM pages WHERE id=$1 AND source_id=$2 AND deleted_at IS NULL', [page.pageId, sourceId]);
+ ? await engine.executeRaw<{ revision: string | null }>('SELECT knowledge_revision::text AS revision FROM pages WHERE source_id=$1 AND slug=$2', [sourceId, page.slug])
+ : await engine.executeRaw<{ revision: string | null }>('SELECT knowledge_revision::text AS revision FROM pages WHERE id=$1 AND source_id=$2', [page.pageId, sourceId]);
return row?.revision ?? null;
}
diff --git a/src/core/persistence/sync-run.ts b/src/core/persistence/sync-run.ts
index 0d20d2deb6..be219f7339 100644
--- a/src/core/persistence/sync-run.ts
+++ b/src/core/persistence/sync-run.ts
@@ -70,8 +70,8 @@ export interface ManagedSyncWriteDiagnostic {
interface Pending { requestId: string; slug: string; pageId: number | null; intent: SyncIntent; rebound?: true;
/** #5988: re-frozen in place from a failed content refusal; a second refusal of the same bytes stays blocked. */
converted?: true; }
-/** #5988: the frozen entry is held instead of admitted. */
-interface Held { hold: HeldEntry }
+/** #5988: the frozen entry is held instead of admitted. #6340 `overtaken`: another cursor of the source imported the entry's page meanwhile (#5522), so the checkpoint accepts a source already at this target. */
+interface Held { hold: HeldEntry; overtaken?: true }
interface Cursor extends SyncDiscovery { runId: string; index: number; authority: SyncAuthority; pending?: Pending; done?: boolean; companyReceiptId?: string;
processingOptions?: SyncProcessingOptions; syncOptions?: SyncCursorOptions; overtaken?: true;
counts: { added: number; modified: number; deleted: number; chunks: number; renamed?: number;
@@ -352,9 +352,20 @@ async function freezeEntry(engine: BrainEngine, cursor: Cursor, key: string, ass
const originScope = syncOriginScope(cursor);
// #5522: another cursor of this source may have imported this new file since enumeration.
// #5984 G3: the page snapshot is read beside the origin check (they are independent reads of committed state).
- const [occupant, snapshot] = await Promise.all([alreadyImportedAtOrigin(engine, cursor, entry, originScope),
- engine.readPageSnapshot(entry.slug!, { sourceId: cursor.sourceId, includeDeleted: true })]);
+ // #6340: page faults (the database page moved under the manifest) hold the entry, imports and deletes alike, when holds
+ // are on; `sync.holds=fail` and company-brain cursors keep the refusals.
+ const holdsOn = !!run.screen && !cursor.companyPlan;
+ const [occupant, snapshot] = await Promise.all([alreadyImportedAtOrigin(engine, cursor, entry, originScope).catch(error => {
+ if (!holdsOn || !(error instanceof OperationError) || error.code !== 'page_identity_changed') throw error;
+ return { originFault: error };
+ }), engine.readPageSnapshot(entry.slug!, { sourceId: cursor.sourceId, includeDeleted: true })]);
assertActive();
+ if (occupant && 'originFault' in occupant) {
+ const proof = await pageChangeProof(engine, { sourceId: cursor.sourceId, incarnation: cursor.incarnation, pageId: entry.pageId ?? null, expectedRevision: entry.revision ?? null });
+ assertActive();
+ return { hold: pageChangedHold(entry, entry.slug!, snapshot?.page.id ?? entry.pageId ?? null, { content: null, blobOid: undefined, expected_revision: entry.revision ?? null },
+ { proof, revision: snapshot?.revision ?? null, why: `the page recorded at ${entry.sourcePath} no longer identifies the one this sync enumerated (${occupant.originFault.message})` }), overtaken: true };
+ }
let bytes: Buffer | null = null;
try { bytes = readSyncFile(cursor.root, entry.path); }
catch (error) { if (!screening || !isSyncReadBound(error)) throw error; oversize = { size: null }; }
@@ -388,13 +399,15 @@ async function freezeEntry(engine: BrainEngine, cursor: Cursor, key: string, ass
// and company-brain cursors keep the refusal. The hold's intent shape is what the entry would have imported.
const frozenIntent = { content, blobOid: blob?.oid, expected_revision: revision, rawHash };
const moved = entry.renameFrom;
+ // A page another cursor of the source moved may also have been checkpointed by it at this exact target (#5522), so a
+ // page-fault hold marks the cursor overtaken; the checkpoint still refuses any other move of `last_commit`.
const pageHold = async (why: string, observedPageId: number | null, observedRevision: string | null): Promise<Held> => {
const proof = await pageChangeProof(engine, { sourceId: cursor.sourceId, incarnation: cursor.incarnation, pageId, expectedRevision: revision });
assertActive();
- return { hold: pageChangedHold(entry, slug, observedPageId ?? pageId, frozenIntent, { proof, revision: observedRevision, why }) };
+ return { hold: pageChangedHold(entry, slug, observedPageId ?? pageId, frozenIntent, { proof, revision: observedRevision, why }), overtaken: true };
};
if (occupant && (content === null || !await sameContentAtOrigin(engine, cursor, entry, key, snapshot, content, rawHash, lineEndingOnly, run.signal))) {
- if (screening) return pageHold(`another run of this source imported page ${slug} from ${entry.path} with different content`, occupant.page.id, occupant.revision);
+ if (holdsOn) return pageHold(`another run of this source imported page ${slug} from ${entry.path} with different content`, occupant.page.id, occupant.revision);
throw syncRunRefusal('page_identity_changed', 'The imported origin no longer identifies exactly the accepted page.', retry,
`Page ${slug} was imported from ${entry.path} by another run of source ${cursor.sourceId} with different content after this run enumerated it, so the run stopped before admitting it.`);
}
@@ -402,7 +415,7 @@ async function freezeEntry(engine: BrainEngine, cursor: Cursor, key: string, ass
const recorded = moved?.slug === slug ? moved.sourcePath : entry.sourcePath;
const foreignOrigin = snapshot?.page.source_path != null && !sameSyncOrigin(snapshot.page.source_path, recorded, originScope, snapshot.page.slug);
if ((snapshot?.page.id ?? null) !== pageId || (snapshot?.revision ?? null) !== revision || (entry.unownedDeletion ? !foreignOrigin : foreignOrigin)) {
- if (!screening) throw syncRunRefusal('revision_conflict', 'A page changed after this sync cursor was enumerated.', retry,
+ if (!holdsOn) throw syncRunRefusal('revision_conflict', 'A page changed after this sync cursor was enumerated.', retry,
`Page ${slug} in source ${cursor.sourceId} was edited, deleted or re-bound after this sync enumerated ${entry.path}, so the run stopped before admitting it.`);
// The page moved but still holds exactly what this import carries: re-bind the entry to it (the waiver screen passes it).
const rebind = entry.action === 'import' && !moved && !foreignOrigin && snapshot !== null && snapshot.page.deleted_at == null
@@ -411,15 +424,16 @@ async function freezeEntry(engine: BrainEngine, cursor: Cursor, key: string, ass
assertActive();
if (!rebind) return pageHold(`page ${slug} was ${snapshot === null || snapshot.page.deleted_at != null ? 'deleted' : foreignOrigin ? 're-bound to another file' : 'edited'} in the database`,
snapshot?.page.id ?? null, snapshot?.revision ?? null);
- pageId = snapshot!.page.id; revision = snapshot!.revision;
+ // Re-bound like a #5522 occupant: the cursor is marked overtaken, since another cursor may have checkpointed this target.
+ pageId = snapshot!.page.id; revision = snapshot!.revision; occupantRebound = true;
}
if (moved && moved.slug !== slug) {
const previous = await engine.readPageSnapshot(moved.slug, { sourceId: cursor.sourceId, includeDeleted: true });
assertActive();
if (previous?.page.id !== moved.pageId || previous.revision !== moved.revision || previous.page.deleted_at != null ||
previous.page.source_path == null || !sameSyncOrigin(previous.page.source_path, moved.sourcePath, originScope, previous.page.slug)) {
- if (screening) return { hold: pageChangedHold(entry, slug, pageId, frozenIntent, { proof: null, revision: previous?.revision ?? null,
- why: `page ${moved.slug}, which ${entry.path} was renamed from, changed or was deleted in the database` }) };
+ if (holdsOn) return { hold: pageChangedHold(entry, slug, pageId, frozenIntent, { proof: null, revision: previous?.revision ?? null,
+ why: `page ${moved.slug}, which ${entry.path} was renamed from, changed or was deleted in the database` }), overtaken: true };
throw syncRunRefusal('revision_conflict', 'A renamed page changed after this sync cursor was enumerated.', retry,
`Page ${moved.slug}, which ${entry.path} was renamed from, changed or was deleted after this sync enumerated it, so the run stopped before admitting the rename.`);
}
@@ -1165,8 +1179,8 @@ export async function managedSyncCursorKey(engine: BrainEngine, opts: SyncOpts):
}
/**
* `--retry-failed` on an unfinished cursor whose pending request failed (or whose run has a ledger row). #6340: a pending
- * request the run would now hold (a page that moved, a dirty file, a fence) converts in place with the frozen manifest;
- * only a failure no hold covers still rediscovers from HEAD. Null when nothing applies (an unfinished request, no failure).
+ * request that failed on a page fault (a page that moved, a dirty file) converts in place with the frozen manifest; every
+ * other failure keeps the explicit rediscovery from HEAD. Null when nothing applies (an unfinished request, no failure).
*/
async function retryFailedStart(engine: BrainEngine, cursor: Cursor, key: string, input: { opts: SyncOpts; context: ManagedSyncContext; authority: SyncAuthority;
processingOptions: SyncProcessingOptions; syncOptions: SyncCursorOptions; startupConfig: BrainEngine; frozenRun: Parameters<typeof freezeEntry>[4]; runStartedAt: string;
@@ -1180,7 +1194,9 @@ async function retryFailedStart(engine: BrainEngine, cursor: Cursor, key: string
const recorded = await engine.executeRaw("SELECT 1 FROM op_checkpoints WHERE op='managed-sync-failure' AND fingerprint=$1 AND completed_keys->0->>'run_id'=$2", [key, cursor.runId]);
assertActive();
if (!((failed && ['failed', 'conflict', 'cancelled'].includes(failed.state)) || (recorded.length && (failed?.state === 'committed' || !failed)))) return null;
- const screen = failed && cursor.pending ? await loadSyncScreenRun(input.startupConfig, cursor.sourceId, cursor.processingOptions ?? processingOptions, authority.writer.remote) : null;
+ // Only the #6340 page faults convert here (a content refusal under --retry-failed keeps its explicit rediscovery).
+ const pageFault = !!failed && !!cursor.pending && (pinnedWorktreeConflict(failed) || failed.error_code === 'revision_conflict');
+ const screen = pageFault ? await loadSyncScreenRun(input.startupConfig, cursor.sourceId, cursor.processingOptions ?? processingOptions, authority.writer.remote) : null;
const converted = screen ? await convertBlockedCursor(engine, cursor, key, assertActive, { ...input.frozenRun, screen, observedAt: cursor.discoveredAt ?? input.runStartedAt }) : cursor;
assertActive();
if (converted !== cursor) return { cursor: converted };
@@ -1364,7 +1380,7 @@ async function runManagedSync(engine: BrainEngine, opts: SyncOpts, slice: { maxP
phase = 'freeze';
const frozen = await freezeEntry(engine, cursor, key, assertActive, frozenRun);
if ('hold' in frozen) {
- cursor = await saveCursor(engine, key, cursor, advanceHeld(cursor), false, assertActive, heldWrite(cursor, frozen.hold, observedAt));
+ cursor = await saveCursor(engine, key, cursor, { ...advanceHeld(cursor), ...(frozen.overtaken ? { overtaken: true as const } : {}) }, false, assertActive, heldWrite(cursor, frozen.hold, observedAt));
opts.onProgress?.({ phase: 'managed_sync.page_committed', bankedFiles: cursor.index }); assertActive();
if (slice && (cursor.index - sliceFirstIndex >= slice.maxPages || performance.now() - sliceStarted >= slice.maxMs)) return result(cursor, 'partial', 'writer_yield');
continue;
diff --git a/test/persistence-sync-holds.test.ts b/test/persistence-sync-holds.test.ts
index 5e84c591b1..0b0f879c92 100644
--- a/test/persistence-sync-holds.test.ts
+++ b/test/persistence-sync-holds.test.ts
@@ -156,11 +156,14 @@ test('a sliced run that has not reached a held file leaves its hold untouched; a
const partial = await performManagedSync(engine, { sourceId: s.id, noPull: true, noEmbed: true, noExtract: true }, { maxPages: 1, maxMs: 60_000 });
expect(partial).toMatchObject({ status: 'partial', reason: 'writer_yield', holds_pending_screen: true });
expect(await s.holdRows()).toEqual(before);
- // The committed fix is admitted, but newer uncommitted working-tree bytes make its publication refuse: the hold stays.
+ // The committed fix is admitted, but newer uncommitted working-tree bytes make its publication refuse. #6340: the refusal
+ // becomes a `worktree_dirty` hold of the same path (the run finishes; the frontmatter hold is replaced, never cleared).
s.write('notes/z.md', note('Z newer uncommitted edit'));
- const blocked = await s.sync();
- expect(blocked.status).toBe('blocked_by_failures');
- expect(await s.holdRows()).toEqual(before);
+ const held = await s.sync();
+ expect(held).toMatchObject({ status: 'synced', held: [{ path: 'notes/z.md', code: 'worktree_dirty' }] });
+ const code = (rows: Array<{ completed_keys: unknown }>) => rows.map(row => (row.completed_keys as Array<{ code?: string }>)[0]?.code).filter(Boolean);
+ expect(code(before)).toEqual(['invalid_frontmatter']);
+ expect(code(await s.holdRows())).toEqual(['worktree_dirty']);
}), 180_000);
test('renamed to a broken file keeps the old page, a later fix moves it with its id, and a full walk never deletes it meanwhile', () => each(async engine => {
@@ -300,7 +303,9 @@ test('a flagless sync converts a --no-embed cursor with its stored options, and
await t.sync();
t.write('notes/z.md', note('Z committed')); commit(t.root, 'change z');
t.write('notes/z.md', note('Z newer uncommitted edit'));
- expect((await t.sync()).status).toBe('blocked_by_failures');
+ // #6340 holds this refusal when holds are on; `sync.holds=fail` leaves the blocked cursor the loop guard is about.
+ await engine.setConfig('sync.holds', 'fail');
+ try { expect((await t.sync()).status).toBe('blocked_by_failures'); } finally { await engine.executeRaw("DELETE FROM config WHERE key='sync.holds'"); }
await engine.executeRaw("UPDATE persistence_requests SET error_code='invalid_params',error_message='Invalid YAML frontmatter: bad indentation of a mapping entry (3:1)' WHERE source_id=$1 AND state IN ('failed','conflict')", [t.id]);
await engine.executeRaw(`UPDATE op_checkpoints SET completed_keys=jsonb_set(completed_keys,'{0,pending,converted}','true'::jsonb)
WHERE op='managed-sync' AND completed_keys->0->>'sourceId'=$1`, [t.id]);
diff --git a/test/persistence-sync-overtaken-cursor-5522.test.ts b/test/persistence-sync-overtaken-cursor-5522.test.ts
index 6f279ba8e7..539d1d3dd4 100644
--- a/test/persistence-sync-overtaken-cursor-5522.test.ts
+++ b/test/persistence-sync-overtaken-cursor-5522.test.ts
@@ -74,23 +74,29 @@ test('#5522 a resume mixing files another cursor imported and files it did not c
expect(await lastCommit(engine, f.id)).toBe(git(f.root, 'rev-parse', 'HEAD'));
}), 180_000);
-test('#5522 a foreign write to the page at that origin still refuses the resume', async () => each(async engine => {
+// #6340: the refusals below are holds now (`concurrent_write`); the invariant they protect, that the foreign write is never overwritten, is unchanged.
+test('#5522 a foreign write to the page at that origin holds the entry on resume and is never overwritten', async () => each(async engine => {
const f = await fixture(engine, ['a', 'b', 'c']);
await performManagedSync(engine, f.base, { maxPages: 1, maxMs: 60_000 });
await performManagedSync(engine, f.working);
await engine.transaction(tx => withCoordinatedWrite(tx, [f.id], () => tx.executeRaw(
"UPDATE pages SET compiled_truth='A foreign edit after the working-tree import.',content_hash='foreign' WHERE source_id=$1 AND slug='b'", [f.id]), TEST_WRITE_ATTRIBUTION));
- await expect(performManagedSync(engine, f.base)).rejects.toMatchObject({ code: 'page_identity_changed' });
+ const resumed = await performManagedSync(engine, f.base);
+ expect(resumed.status).not.toBe('blocked_by_failures');
+ expect(resumed.held?.map(hold => [hold.path, hold.code])).toEqual([['b.md', 'concurrent_write']]);
expect(await imports(engine, f.id)).toEqual(['a', 'b', 'c']);
expect((await engine.getPage('b', { sourceId: f.id }))?.compiled_truth).toBe('A foreign edit after the working-tree import.');
}), 180_000);
-test('#5522 a page soft-deleted at that origin, or a pinned page deleted and recreated with the same text, is refused', async () => each(async engine => {
+test('#5522 a page soft-deleted at that origin, or a pinned page deleted and recreated with the same text, is held', async () => each(async engine => {
const deleted = await fixture(engine, ['a', 'b']);
await performManagedSync(engine, deleted.base, { maxPages: 1, maxMs: 60_000 });
await performManagedSync(engine, deleted.working);
await engine.transaction(tx => withCoordinatedWrite(tx, [deleted.id], () => tx.softDeletePage('b', { sourceId: deleted.id }), TEST_WRITE_ATTRIBUTION));
- await expect(performManagedSync(engine, deleted.base)).rejects.toMatchObject({ code: 'page_identity_changed' });
+ const held = await performManagedSync(engine, deleted.base);
+ expect(held.status).not.toBe('blocked_by_failures');
+ expect(held.held?.map(hold => [hold.path, hold.code])).toEqual([['b.md', 'concurrent_write']]);
+ expect(await engine.getPage('b', { sourceId: deleted.id })).toBeNull();
// An entry enumerated against an existing page keeps its pinned identity.
const pinned = await fixture(engine, ['a', 'b']);
@@ -104,5 +110,10 @@ test('#5522 a page soft-deleted at that origin, or a pinned page deleted and rec
const after = await engine.getPage('b', { sourceId: pinned.id });
expect(after?.compiled_truth).toContain('Revised observation b');
expect(after?.id !== before?.id || after?.updated_at !== before?.updated_at).toBe(true);
- await expect(performManagedSync(engine, pinned.base)).rejects.toMatchObject({ code: expect.stringMatching(/^(page_identity_changed|revision_conflict)$/) });
+ // The recreated page holds exactly what the pinned entry would import: it is re-bound and passed, nothing is rewritten,
+ // and the checkpoint accepts the target the working-tree run already reached.
+ const resumed = await performManagedSync(engine, pinned.base);
+ expect(resumed).toMatchObject({ status: 'synced', waived: { imports: 1, deletes: 0 } });
+ expect(resumed.held ?? []).toEqual([]);
+ expect((await engine.getPage('b', { sourceId: pinned.id }))?.updated_at).toEqual(after?.updated_at);
}), 180_000);
diff --git a/test/persistence-sync-stdio-owner.test.ts b/test/persistence-sync-stdio-owner.test.ts
index 7143405ed6..14e9f8bf55 100644
--- a/test/persistence-sync-stdio-owner.test.ts
+++ b/test/persistence-sync-stdio-owner.test.ts
@@ -50,6 +50,8 @@ beforeAll(async()=>{
await withEnv(env,async()=>{
await setup.connect(config);await setup.initSchema();
await setup.setConfig('search.mcp_keyword_only','true');
+ // #6340 holds a pinned-worktree conflict when holds are on; `sync.holds=fail` keeps the failure receipt the diagnostics test below is about.
+ await setup.setConfig('sync.holds','fail');
await setup.executeRaw("INSERT INTO sources(id,name,local_path,config) VALUES('workspace','workspace',$1,'{}')",[root]);
const code = 'export function residentExample() { return 4; }\n';
writeFileSync(join(root,'example.ts'),code);
diff --git a/test/sync-drain-connection.test.ts b/test/sync-drain-connection.test.ts
index d65517d3ef..f6f69ecd84 100644
--- a/test/sync-drain-connection.test.ts
+++ b/test/sync-drain-connection.test.ts
@@ -82,7 +82,7 @@ describe('runDrain over a dropping connection', () => {
expect(next).toMatchObject({ command: RESUME, safe_to_loop: true, retry_after_ms: 60_000, code: 'connection_lost', docs: ERROR_CATALOGUE.sync_drain_connection_lost.docs });
expect(next.why).toContain('3 times in a row');
expect(next.why).toContain('without re-freezing');
- expect(ERROR_CATALOGUE.sync_drain_connection_lost).toEqual({ code: 'connection_lost', docs: 'docs/guides/sync-unblock-runbook.md#connection' });
+ expect(ERROR_CATALOGUE.sync_drain_connection_lost).toEqual({ code: 'connection_lost', docs: 'docs/guides/write-refusals.md#drain-connection-lost' });
expect(CODES.connection_lost).toMatchObject({ class: 'retryable', retryable: true });
expect(drainJsonFields(result, RESUME, 's')).toMatchObject({ outcome: 'blocked', next: { command: RESUME, safe_to_loop: true } });
const summary = formatDrainSummary(result, RESUME, 's').join('\n');
diff --git a/test/sync-json-stdout-clean.test.ts b/test/sync-json-stdout-clean.test.ts
index 6d9bedb2b9..04bd487374 100644
--- a/test/sync-json-stdout-clean.test.ts
+++ b/test/sync-json-stdout-clean.test.ts
@@ -201,6 +201,8 @@ describe('#4888: sync --json keeps stdout pure JSON', () => {
execSync('git add -A && git commit -q -m diagnostic-fixture', { cwd: repoPath, stdio: 'pipe' });
writeFileSync(join(repoPath, 'topics/foo.md'), FOO('PRIVATE_DIAGNOSTIC_CONTENT_CANARY'));
rmSync(join(home, 'sync-failures.jsonl'), { force: true });
+ // #6340 holds this refusal when holds are on; `sync.holds=fail` keeps the failure receipt whose JSON this test is about.
+ await engine.setConfig('sync.holds', 'fail');
const { stdout, stderr } = await run(['--retry-failed', '--no-pull', '--no-embed', '--json']);
const out = lines(stdout);
expect(out).toHaveLength(1);
@@ -224,6 +226,7 @@ describe('#4888: sync --json keeps stdout pure JSON', () => {
} finally {
_resetCliExitVerdictForTests(); process.exitCode = 0;
await withEnv({ GBRAIN_HOME: home }, () => disposePersistenceConsumer(engine));
+ await engine.executeRaw("DELETE FROM config WHERE key='sync.holds'");
await engine.executeRaw('UPDATE persistence_brain SET enabled=false WHERE singleton=1');
}
}, 60_000);