Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
persistence: reconcile clears an agreed file's stalled hold; refusals and retry-held name the hold row (#7364)
garrytan3630d04eca04
diff --git a/src/commands/sources-retry-held.ts b/src/commands/sources-retry-held.tsindex 141941da82..94ee945a69 100644--- a/src/commands/sources-retry-held.ts+++ b/src/commands/sources-retry-held.ts@@ -26,7 +26,7 @@ import type { Action } from '../core/agent-output.ts';import { OperationError } from '../core/ops/contract.ts';import { managedBrain, readAllSourceHolds, readHoldRetryKeys, requestHoldRetry, writeHeldRetryPointer } from '../core/connectors/item-holds-store.ts';import { isConnectorSourceKind } from '../core/persistence/connector-identity.ts';-import { outOfAttemptsHold, fenceAutoRepairFor, holdRepairSteps, readGitHoldRetryPaths, readGitSourceHolds, requestGitHoldRetry, type GitHoldRecord } from '../core/persistence/sync-holds.ts';+import { GIT_HOLD_OP, gitHoldFingerprint, outOfAttemptsHold, fenceAutoRepairFor, holdRepairSteps, readGitHoldRetryPaths, readGitSourceHolds, requestGitHoldRetry, type GitHoldRecord } from '../core/persistence/sync-holds.ts';import { readManagedSyncBacklog } from '../core/persistence/sync-drain.ts';import type { FenceAutoRepair } from '../core/fence-repair/hold-fix.ts';import { companyBrainProfile } from '../core/company-brain/policy.ts';@@ -38,7 +38,9 @@ export interface RetryHeldReceipt {kind: 'connector' | 'git';dry_run: boolean;scheduled: number;- items: Array<{ key: string; code: string; reason?: string; action: 'would_retry' | 'retry_scheduled'; next_action: string }>;+ items: Array<{ key: string; code: string; reason?: string; fingerprint?: string; action: 'would_retry' | 'retry_scheduled'; next_action: string }>;+ /** #7364 (git): the hold rows this receipt read (`op_checkpoints` op `sync-hold` of the source's current incarnation), so a refusal that names a hold this listing missed shows which row each one read. */+ hold_rows?: { op: string; source_id: string; incarnation: string; read: number };next_action: string;/** Git sources with held files: the one next step (the sync that re-screens them, or the scheduling command after a dry run). */fix?: Action;@@ -46,7 +48,7 @@ export interface RetryHeldReceipt {unindexed?: { complete: boolean; target: string | null; scanned: number; unindexed: number; slug_taken: number; already_scheduled: number; by_code: Record<string, number>; metafile_skipped: number };}-interface Scheduled { items: Array<{ key: string; code: string; reason?: string; already: boolean }>; sync: string[]; fenceAuto?: FenceAutoRepair }+interface Scheduled { items: Array<{ key: string; code: string; reason?: string; fingerprint?: string; already: boolean }>; sync: string[]; fenceAuto?: FenceAutoRepair }async function scheduleConnectorItems(engine: BrainEngine, sourceId: string, incarnation: string, dryRun: boolean): Promise<Scheduled> {const held = (await readAllSourceHolds(engine, { sourceIds: [sourceId] }))[0]?.held ?? [];@@ -84,7 +86,7 @@ async function scheduleGitFiles(engine: BrainEngine, sourceId: string, incarnaticonst already = new Set(dryRun ? await readGitHoldRetryPaths(engine, sourceId, incarnation) : []);const fenceAuto = await fenceAutoRepairFor(engine, held);return { items: held.map(record => ({ key: record.path, code: record.code, ...(record.meta.reason ? { reason: record.meta.reason } : {}),- already: already.has(record.path) })), sync, ...(fenceAuto ? { fenceAuto } : {}) };+ fingerprint: gitHoldFingerprint(record.source_id, record.incarnation, record.path), already: already.has(record.path) })), sync, ...(fenceAuto ? { fenceAuto } : {}) };}function gitNextStep(sourceId: string, dryRun: boolean, scheduled: Scheduled): { text: string; fix: Action } {@@ -121,9 +123,10 @@ export async function retryHeld(engine: BrainEngine, sourceId: string, opts: { d: step ? step.text: dryRun ? `${count} held item(s) would be scheduled; run: gbrain sources retry-held ${sourceId}`: `${count} held item(s) scheduled; none has run yet. Run them now with: ${sync}, then verify with: gbrain sources status ${sourceId}`;- const items = scheduled.items.map(item => ({ key: item.key, code: item.code, ...(item.reason ? { reason: item.reason } : {}),+ const items = scheduled.items.map(item => ({ key: item.key, code: item.code, ...(item.reason ? { reason: item.reason } : {}), ...(item.fingerprint ? { fingerprint: item.fingerprint } : {}),action: dryRun && !item.already ? 'would_retry' as const : 'retry_scheduled' as const }));- return receiptOf({ source_id: sourceId, kind, dry_run: dryRun, scheduled: dryRun ? 0 : count, ...(step ? { fix: step.fix } : {}) }, items, next,+ const holdRows = kind === 'git' ? { hold_rows: { op: GIT_HOLD_OP, source_id: sourceId, incarnation: source.incarnation, read: count } } : {};+ return receiptOf({ source_id: sourceId, kind, dry_run: dryRun, scheduled: dryRun ? 0 : count, ...holdRows, ...(step ? { fix: step.fix } : {}) }, items, next,dryRun ? 'Run the same command without --dry-run to schedule it.' : `${kind === 'git' ? 'Re-screened' : 'Re-attempted'} on the next ${sync}.`);}diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex 0c1e8a906c..60e7324422 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1154,6 +1154,8 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: '0.60.396.0', text: 'A facts-fence row with no `valid_from` cell now takes the page\'s stated date (frontmatter `event_date`, `date` or `published`, or a dated filename) on every write path: `put_page`, sync and import used to store the write time, and `extract_facts` used the page\'s creation or import time when the page stated no date (#7247). A page that states no date leaves such rows at the time they were recorded. Rows already stored keep their dates.' },// GBRA-133 (soak: an unread origin was reported as never committed). `since` is restamped at the merge slot.{ since: '0.60.397.0', text: 'A `file_drift` hold (side `deleted`, state `file_gone`) for a missing file whose Git history read did not finish now carries `meta.reason` `origin_unknown` and says Git could not show whether a commit held the file, instead of `never_committed` and "Git never committed it". The page is still kept, and the `--held` preview still reads the whole history and names the provenance.' },+ // #7364 (GBRA-133 wave 3). `since` is restamped at the merge slot.+ { since: '0.60.397.0', text: '`gbrain sources reconcile --apply` that commits and leaves the page and its canonical file agreeing now clears that file\'s `preparation_stalled` or `write_interrupted` sync hold (the write owner stalled, not the file), and its result names the cleared row (`cleared_hold`); a file that still differs keeps its hold. A page write refused for a held file now names the hold row it read in its message (`Hold row: source <id>, incarnation <uuid>.`), and `gbrain sources retry-held --json` reports the rows it read (`hold_rows`) and each held file\'s `fingerprint`, so a refusal naming a row the listing does not show can be told apart (#7364).' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/persistence/page-prepare.ts b/src/core/persistence/page-prepare.tsindex f0a8d697a5..a89a060464 100644--- a/src/core/persistence/page-prepare.ts+++ b/src/core/persistence/page-prepare.ts@@ -27,7 +27,7 @@ import { pageIdentityError } from './page-identity.ts';import { contentRefusalError, PAGE_OVER_LIMIT_SUGGESTION } from '../import-screen.ts';import { ContentSanityBlockError } from '../content-sanity.ts';import { assertPageRevision, type PageSnapshot } from '../page-state/types.ts';-import { gitHoldFix, readGitHold } from './sync-holds.ts';+import { GIT_HOLD_OP, gitHoldFingerprint, gitHoldFix, readGitHold } from './sync-holds.ts';import { hostOperatorFix, recordRoute } from './held-reads.ts';import { heldFileMessage } from './verb-errors.ts';import { isWriteTargetContained } from '../path-confine.ts';@@ -392,7 +392,7 @@ async function heldFileRefusal(engine: BrainEngine, row: Pick<WriteRequest, 'souconst effect = kind === 'drift' ? `page ${row.slug} keeps its last good revision and` : `page ${row.slug} does not exist yet and its path`;if (remote) {// Remote callers get the code and the host operator's command, never the held path or key.- const error = opError('source_changed', heldFileMessage(kind, hold.code),+ const error = opError('source_changed', heldFileMessage(kind, hold.code, { sourceId: row.source_id, incarnation: source!.incarnation }),`Sync holds this page's canonical file in source ${row.source_id} (${hold.code}${hold.meta.reason ? `, ${hold.meta.reason}` : ''}) because gbrain cannot import it, `+ `so ${effect} is read-only for put_page until the brain host operator repairs the file; retrying this write refuses the same way. Relay the fix to the user, then submit the intended write with a new request_id. Neither copy was overwritten.`,{ fix: hostOperatorFix([{ source_id: row.source_id, route: recordRoute(hold) }], `The canonical file of page ${row.slug} is held (${hold.code}): only the brain host operator can inspect and repair it.`) });@@ -402,10 +402,11 @@ async function heldFileRefusal(engine: BrainEngine, row: Pick<WriteRequest, 'sou}const fix = gitHoldFix(hold);const where = [hold.meta.line !== undefined ? `line ${hold.meta.line}` : '', hold.meta.key ? `key "${hold.meta.key}"` : ''].filter(Boolean).join(', ');- const error = opError('source_changed', heldFileMessage(kind, hold.code),+ const error = opError('source_changed', heldFileMessage(kind, hold.code, { sourceId: row.source_id, incarnation: source!.incarnation }),`Sync holds ${hold.path} in source ${row.source_id} (${hold.code}${hold.meta.reason ? `, ${hold.meta.reason}` : ''}${where ? ` at ${where}` : ''}) because gbrain cannot import it, `+ `so ${effect} is read-only for put_page until the file is repaired; retrying this write refuses the same way. `- + `Repair the file first (${shellQuote(fix.argv ?? [])}: ${fix.why}), then submit the intended write with a new request_id. Neither copy was overwritten.`, { fix });+ + `Repair the file first (${shellQuote(fix.argv ?? [])}: ${fix.why}), then submit the intended write with a new request_id. Neither copy was overwritten. `+ + `Hold row read: op ${GIT_HOLD_OP}, fingerprint ${gitHoldFingerprint(row.source_id, source!.incarnation, hold.path)}, held since ${hold.held_at}.`, { fix });if (kind === 'drift') error.detail = 'file_database_drift';error.reason = SYNC_HELD;return error;diff --git a/src/core/persistence/reconcile.ts b/src/core/persistence/reconcile.tsindex 436b7560bc..1fb3b4df4d 100644--- a/src/core/persistence/reconcile.ts+++ b/src/core/persistence/reconcile.ts@@ -19,6 +19,8 @@ import { assertReconcileOutputPath, assertReconcileSize, manageReconcileBackups,import type { LocalGrant } from './identity.ts';import { isTerminal, type WriteRequest } from './model.ts';import { serializePageToMarkdown } from '../markdown.ts';+import { liveFileDrift } from './drift-conflicts.ts';+import { clearGitHold, GIT_HOLD_OP, gitHoldFingerprint, outOfAttemptsHold, readGitHold } from './sync-holds.ts';import { readFix, trustedCliRequired } from '../ops/op-fix.ts';import type { Action } from '../agent-output.ts';@@ -151,8 +153,26 @@ export async function runReconcileApply(engine: BrainEngine, params: Record<striconst artifact = validateReconcileArtifact(params.preview);artifact.decisions = reconcileDecisions(artifact.decisions);const requestId = requireUuid(params.request_id as string);- return admitReconcileArtifact(engine, { sourceId, slug, authority, artifact, requestId, keepFileBytes: params.keep_file_bytes === true },- async (row, replayed) => writeResponse(replayed && isTerminal(row) ? row : await waitForWrite(engine, row, await config(engine))));+ return admitReconcileArtifact(engine, { sourceId, slug, authority, artifact, requestId, keepFileBytes: params.keep_file_bytes === true }, async (row, replayed) => {+ const settled = replayed && isTerminal(row) ? row : await waitForWrite(engine, row, await config(engine));+ const cleared = settled.state === 'committed' ? await clearAgreedStallHold(engine, sourceId, slug) : null;+ return { ...writeResponse(settled), ...(cleared ? { cleared_hold: cleared } : {}) };+ });+}++/**+ * #7364: a committed reconcile whose page and canonical file now agree clears that file's out-of-attempts hold+ * (`preparation_stalled`, `write_interrupted`: the write owner stalled, not the file), which no other repair path clears.+ * A file that still differs keeps its hold, and so does a hold written after the one this read.+ */+async function clearAgreedStallHold(engine: BrainEngine, sourceId: string, slug: string): Promise<{ op: string; fingerprint: string; code: string } | null> {+ const live = await liveFileDrift(engine, sourceId, slug);+ if (live.still_present !== false || !live.path) return null;+ const [source] = await engine.executeRaw<{ incarnation: string }>('SELECT incarnation::text AS incarnation FROM sources WHERE id=$1', [sourceId]);+ const hold = source ? await readGitHold(engine, sourceId, source.incarnation, live.path) : null;+ if (!hold || !outOfAttemptsHold(hold.code)) return null;+ const cleared = await engine.transaction(tx => clearGitHold(tx, { sourceId, incarnation: source!.incarnation, path: hold.path, observedAt: hold.observed_at }));+ return cleared ? { op: GIT_HOLD_OP, fingerprint: gitHoldFingerprint(sourceId, source!.incarnation, hold.path), code: hold.code } : null;}/**diff --git a/src/core/persistence/verb-errors.ts b/src/core/persistence/verb-errors.tsindex c1d17a5227..4ae6135a67 100644--- a/src/core/persistence/verb-errors.ts+++ b/src/core/persistence/verb-errors.ts@@ -19,17 +19,19 @@ export function frontmatterSlugConflictMessage(path: string, found: string, expe}/** #5988: the page's canonical file is held by sync; the code says why gbrain cannot import it. Location-free, so receipts may keep it. */-const HELD_FILE = /^(?:The canonical file is held by sync|A file held by sync) \(([a-z_]+)\) (and differs from the page|occupies the canonical page path); the page is read-only for put_page until the file is repaired\.$/;+const HELD_FILE = /^(?:The canonical file is held by sync|A file held by sync) \(([a-z_]+)\) (and differs from the page|occupies the canonical page path); the page is read-only for put_page until the file is repaired\.(?: Hold row: source ([^ ,]+), incarnation ([0-9a-f-]+)\.)?$/;/** #6693: the refusal of a page write whose file holds a committed Git change sync has not imported yet (pending-import.ts). *//** #6858: the receipt prefix of a write `gbrain repair stuck-recovery --keep disk` abandoned: its canonical file was kept as edited on disk. */export const KEEP_DISK_ABANDONED_PREFIX = 'Publication abandoned by gbrain repair stuck-recovery --keep disk';export const PENDING_IMPORT_MESSAGE = 'The canonical file holds a committed Git change that sync has not imported yet.';-export function heldFileMessage(kind: 'drift' | 'occupied', code: string): string {- return kind === 'drift'+/** #7364: `row` names the hold row the refusal read (its source and incarnation, still location-free), so a refusal naming a row that `sources retry-held` does not list shows which. */+export function heldFileMessage(kind: 'drift' | 'occupied', code: string, row?: { sourceId: string; incarnation: string }): string {+ const held = kind === 'drift'? `The canonical file is held by sync (${code}) and differs from the page; the page is read-only for put_page until the file is repaired.`: `A file held by sync (${code}) occupies the canonical page path; the page is read-only for put_page until the file is repaired.`;+ return row ? `${held} Hold row: source ${row.sourceId}, incarnation ${row.incarnation}.` : held;}/** The diagnostic of a held-file refusal message (null for any other message); `sourceId` fills the commands when the caller knows it. */@@ -44,7 +46,8 @@ export function heldFileDiagnostic(message: string | null | undefined, sourceIdsuggestion: `Sync holds this page's file because gbrain cannot import it; gbrain sources status ${sourceId} names the file${held[1] === 'invalid_fence' ? ', fence and reason' : ', line and key'}. `+ 'The page keeps its last good revision and refuses put_page until the file is repaired, so retrying this write refuses the same way. '+ `On the source host, repair the file first (${repair}), `- + 'then submit the intended write with a new request_id. Neither copy was overwritten.' };+ + 'then submit the intended write with a new request_id. Neither copy was overwritten.'+ + (held[3] ? ` The refusal read the sync-hold row of source ${held[3]}, incarnation ${held[4]}; gbrain sources retry-held ${held[3]} --dry-run --json lists the rows it reads (hold_rows).` : '') };}export function writeFailureDiagnostic(code: string, message?: string | null): { reason: string; message: string; suggestion: string } {diff --git a/test/postgres-unit-arms.txt b/test/postgres-unit-arms.txtindex a0ce944710..2b01de4568 100644--- a/test/postgres-unit-arms.txt+++ b/test/postgres-unit-arms.txt@@ -385,6 +385,7 @@ test/purge-sync-tombstone-hold-7130.test.tstest/read-meta-diag.test.tstest/recall-page-fill.test.tstest/receipt-compaction-newest-sync-gbra130.test.ts+test/reconcile-clears-stalled-hold-7364.test.tstest/remediation-manual-only.test.tstest/repair-apply-pending-6543.test.tstest/repair-database-stop-gbra133.test.tsdiff --git a/test/reconcile-clears-stalled-hold-7364.test.ts b/test/reconcile-clears-stalled-hold-7364.test.tsnew file mode 100644index 0000000000..14f113988c--- /dev/null+++ b/test/reconcile-clears-stalled-hold-7364.test.ts@@ -0,0 +1,99 @@+/**+ * #7364: a page write refused because its canonical file "is held by sync (preparation_stalled)" had no sanctioned way+ * out: `sources retry-held` reported no held files, `sources reconcile --apply` reconciled the page, and later writes still+ * named the hold. An out-of-attempts hold (`preparation_stalled`, `write_interrupted`) is about the write owner, not the+ * file, so a committed reconcile whose page and file now agree clears it; a file that still differs keeps it. The+ * refusal and `retry-held` both name the hold row they read, so a refusal naming a row the listing missed is visible.+ * Both explanations the report fits: a write refused before the hold cleared runs once it is retried, and a+ * formatting-only reconcile (the file's bytes still differ, its content agrees) clears the hold.+ */+import { expect, test } from 'bun:test';+import { execFileSync } from 'node:child_process';+import { randomUUID } from 'node:crypto';+import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';+import { join } from 'node:path';+import { retryHeld } from '../src/commands/sources-retry-held.ts';+import type { BrainEngine } from '../src/core/engine.ts';+import { RECOVERY_VERSION } from '../src/core/frontmatter-recovery.ts';+import { operationsByName } from '../src/core/operations.ts';+import type { OperationContext } from '../src/core/ops/contract.ts';+import { liveFileDrift } from '../src/core/persistence/drift-conflicts.ts';+import { registerLocalWriter, withVerifiedLocalRegistration } from '../src/core/persistence/identity.ts';+import { runReconcileApply, runReconcilePreview } from '../src/core/persistence/reconcile.ts';+import { readGitHold, writeGitHold } from '../src/core/persistence/sync-holds.ts';+import { performManagedSync } from '../src/core/persistence/sync-run.ts';+import { managedBrain } from './helpers/managed-brain.ts';+import { requirePostgresTestDatabase, testBackends } from './helpers/test-backends.ts';++const SLUG = 'notes/a', PATH = 'notes/a.md';+const PAGE = '---\ntype: concept\ntitle: a\n---\n\nA note about a.\n';+const git = (root: string, args: string[]) => execFileSync('git', ['-C', root, '-c', 'user.name=Example', '-c', '[email protected]', '-c', 'commit.gpgsign=false', ...args], { encoding: 'utf8' }).trim();+const setup = ({ root }: { root: string }) => {+ git(root, ['init', '-q']); mkdirSync(join(root, 'notes')); writeFileSync(join(root, PATH), PAGE);+ git(root, ['add', '-A']); git(root, ['commit', '-qm', 'pages']);+};++async function stalled(engine: BrainEngine): Promise<string> {+ const [{ incarnation }] = await engine.executeRaw<{ incarnation: string }>("SELECT incarnation::text AS incarnation FROM sources WHERE id='default'");+ await engine.transaction(tx => writeGitHold(tx, { source_id: 'default', incarnation, path: PATH, source_path: PATH, slug: SLUG, page_id: null, code: 'preparation_stalled',+ message: 'The write owner stalled while preparing this file.', upstream_version: null, observed_at: new Date().toISOString(), run_id: null, mode: 'managed', meta: { recovery_version: RECOVERY_VERSION } }));+ return `default:${incarnation}:${PATH}`;+}++const put = async (engine: BrainEngine, ctx: OperationContext, body: string) => operationsByName.put_page!.handler(ctx, { slug: SLUG, content: PAGE.replace('A note about a.', body),+ expected_revision: (await engine.readPageSnapshot(SLUG, { sourceId: 'default' }))!.revision, request_id: randomUUID() });++async function reconcile(engine: BrainEngine, requestId = randomUUID()) {+ return withVerifiedLocalRegistration(engine, await registerLocalWriter(engine, 'cli'), async () => {+ const preview = await runReconcilePreview(engine, { source_id: 'default', slug: SLUG });+ expect(preview.status).toBe('ready');+ return { preview, applied: await runReconcileApply(engine, { source_id: 'default', slug: SLUG, preview: preview.preview, request_id: requestId }), requestId };+ });+}++for (const backend of testBackends()) {+ const databaseUrl = backend === 'postgres' ? requirePostgresTestDatabase() : undefined;++ test(`#7364 [${backend}]: a write refused for a stalled hold names its row; the reconcile that makes page and file agree clears it and the retried write runs`, () => managedBrain(async ({ engine, ctx, root }) => {+ expect((await performManagedSync(engine, { sourceId: 'default', noPull: true, noEmbed: true, noExtract: true })).status).toBe('first_sync');+ const fingerprint = await stalled(engine);+ writeFileSync(join(root, PATH), PAGE.replace('title: a', 'title: a\nfile_field: kept'));+ const refused = await put(engine, ctx, 'An edited note.').then(() => null, error => error);+ expect(refused?.code).toBe('source_changed');+ const incarnation = fingerprint.split(':')[1]!;+ expect(refused.message).toContain('held by sync (preparation_stalled)');+ expect(refused.message).toContain(`Hold row: source default, incarnation ${incarnation}.`);+ expect(refused.suggestion).toContain(`read the sync-hold row of source default, incarnation ${incarnation}`);+ const listed = await retryHeld(engine, 'default', { dryRun: true });+ expect(listed.items.map(item => [item.code, item.fingerprint])).toEqual([['preparation_stalled', fingerprint]]);+ expect(listed.hold_rows).toEqual({ op: 'sync-hold', source_id: 'default', incarnation, read: 1 });++ const { applied, requestId } = await reconcile(engine);+ expect(applied.state).toBe('committed');+ expect(applied.cleared_hold).toEqual({ op: 'sync-hold', fingerprint, code: 'preparation_stalled' });+ expect(await readGitHold(engine, 'default', fingerprint.split(':')[1]!, PATH)).toBeNull();+ // The refused write's error predates the clearing: retried, it runs.+ expect(await put(engine, ctx, 'An edited note.')).toMatchObject({ state: 'committed' });++ // A replayed apply while the file differs again leaves a newer stalled hold in place, and the refusal names it.+ await stalled(engine);+ writeFileSync(join(root, PATH), readFileSync(join(root, PATH), 'utf8').replace('title: a', 'title: a\nother_field: kept'));+ const replayed = await withVerifiedLocalRegistration(engine, await registerLocalWriter(engine, 'cli'), async () =>+ runReconcileApply(engine, { source_id: 'default', slug: SLUG, preview: (await runReconcilePreview(engine, { source_id: 'default', slug: SLUG })).preview, request_id: requestId }).catch(error => error));+ expect(replayed.cleared_hold).toBeUndefined();+ expect(await readGitHold(engine, 'default', fingerprint.split(':')[1]!, PATH)).toMatchObject({ code: 'preparation_stalled' });+ expect(((await put(engine, ctx, 'Another note.').then(() => null, error => error))?.message)).toContain(`Hold row: source default, incarnation ${incarnation}.`);+ }, { databaseUrl, setup }), 120_000);++ test(`#7364 [${backend}]: a formatting-only reconcile (the bytes differ, the content agrees) clears the stalled hold`, () => managedBrain(async ({ engine, root }) => {+ expect((await performManagedSync(engine, { sourceId: 'default', noPull: true, noEmbed: true, noExtract: true })).status).toBe('first_sync');+ const fingerprint = await stalled(engine);+ writeFileSync(join(root, PATH), PAGE.replace('A note about a.', 'A note about a. ').replace('type: concept', 'type: "concept"'));+ const { preview, applied } = await reconcile(engine);+ expect(preview.formatting_only).toBe(true);+ expect(applied.state).toBe('committed');+ expect(applied.cleared_hold).toEqual({ op: 'sync-hold', fingerprint, code: 'preparation_stalled' });+ expect(await liveFileDrift(engine, 'default', SLUG)).toMatchObject({ still_present: false });+ expect(await readGitHold(engine, 'default', fingerprint.split(':')[1]!, PATH)).toBeNull();+ }, { databaseUrl, setup }), 120_000);+}diff --git a/test/sync-hold-surfaces.test.ts b/test/sync-hold-surfaces.test.tsindex e82adbbde3..c3a94d8f82 100644--- a/test/sync-hold-surfaces.test.ts+++ b/test/sync-hold-surfaces.test.ts@@ -226,7 +226,7 @@ describe('a page whose file is held refuses put_page naming the hold', () => {await writeGitHold(engine, hold(sourceId, await incarnationOf(engine, sourceId), 'notes/held.md', { page_id: Number(snapshot.page.id) }));let error: any;try { await prepareFileTarget(engine, row, snapshot, 'Replacement'); } catch (e) { error = e; }- expect(error).toMatchObject({ code: 'source_changed', detail: 'file_database_drift', message: heldFileMessage('drift', 'invalid_frontmatter'),+ expect(error).toMatchObject({ code: 'source_changed', detail: 'file_database_drift', message: heldFileMessage('drift', 'invalid_frontmatter', { sourceId, incarnation: await incarnationOf(engine, sourceId) }),fix: { argv: ['gbrain', 'repair', 'frontmatter', '--source', sourceId, '--include-ambiguous'] } });expect(error.suggestion).toContain('Sync holds notes/held.md in source held-drift (invalid_frontmatter, needs_interpretation at line 2, key "title")');expect(error.suggestion).toContain('read-only for put_page until the file is repaired');@@ -240,7 +240,7 @@ describe('a page whose file is held refuses put_page naming the hold', () => {await writeGitHold(engine, hold(sourceId, await incarnationOf(engine, sourceId), 'notes/held-remote.md', { page_id: Number(snapshot.page.id) }));let error: any;try { await prepareFileTarget(engine, row, snapshot, 'Replacement', undefined, { remote: true }); } catch (e) { error = e; }- expect(error).toMatchObject({ code: 'source_changed', detail: 'file_database_drift', message: heldFileMessage('drift', 'invalid_frontmatter'),+ expect(error).toMatchObject({ code: 'source_changed', detail: 'file_database_drift', message: heldFileMessage('drift', 'invalid_frontmatter', { sourceId, incarnation: await incarnationOf(engine, sourceId) }),fix: { actor: 'host_admin', argv: ['gbrain', 'repair', 'frontmatter', '--source', sourceId] } });const text = JSON.stringify({ message: error.message, suggestion: error.suggestion, fix: error.fix });expect(text).toContain('read-only for put_page until the brain host operator repairs the file');@@ -255,7 +255,7 @@ describe('a page whose file is held refuses put_page naming the hold', () => {await expect(prepareFileTarget(engine, row, null, 'Rendered')).rejects.toMatchObject({ message: 'An unindexed file already occupies the canonical page path.' });await writeGitHold(engine, hold(sourceId, await incarnationOf(engine, sourceId), 'notes/new-held.md'));await expect(prepareFileTarget(engine, row, null, 'Rendered')).rejects.toMatchObject({ code: 'source_changed',- message: heldFileMessage('occupied', 'invalid_frontmatter'), suggestion: expect.stringContaining('does not exist yet') });+ message: heldFileMessage('occupied', 'invalid_frontmatter', { sourceId, incarnation: await incarnationOf(engine, sourceId) }), suggestion: expect.stringContaining('does not exist yet') });});test('receipts keep only the location-free message; the diagnostic maps it to the same reasons with the repair command', () => {@@ -292,7 +292,7 @@ describe('Git holds and writer mode changes (X14)', () => {const suggestion = String(refused!.suggestion);expect(suggestion).toContain('gbrain repair frontmatter --source default');expect(suggestion).toContain('retrying this write refuses the same way');- expect(refused).toMatchObject({ code: 'source_changed', detail: 'file_database_drift', message: heldFileMessage('drift', 'invalid_frontmatter') });+ expect(refused).toMatchObject({ code: 'source_changed', detail: 'file_database_drift', message: heldFileMessage('drift', 'invalid_frontmatter', { sourceId: 'default', incarnation }) });expect(JSON.stringify(refused)).not.toContain('sources reconcile');const gmailIncarnation = await incarnationOf(engine, 'gmail-x');