Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(#6712 PR 4b): post-merge dispositions against master v0.60.300.0

garrytanc64799845094
diff --git a/src/core/persistence/sync-status.ts b/src/core/persistence/sync-status.ts
index 1d8de7ce7f..0c51c8954e 100644
--- a/src/core/persistence/sync-status.ts
+++ b/src/core/persistence/sync-status.ts
@@ -598,14 +598,8 @@ export async function unblockSync(engine: BrainEngine, sourceId: string, opts: U
const kinds = CONTENT_REPAIR_KINDS.filter(kind => repairs.has(kind));
const paths = [...repairs.values()].flat().map(hold => hold.path);
const startedAt = Date.now();
- // GBRA-130 A-28: a lane that throws skips its holds (repair_error) instead of aborting the unblock; the re-screens below still run.
- const lane = await resolveRepairScope(engine, sourceId).then(scope => runContentLane(engine, scope, { apply: true, kinds, only: paths, noLlm: opts.noLlm, maxLlmUsd: opts.maxLlmUsd,
- deadline: Date.now() + UNBLOCK_REPAIR_BUDGET_MS, sourceFlag: sourceId, logger: quiet, ...(opts.registry ? { registry: opts.registry } : {}) }))
- .catch((error: unknown) => ({ results: [] as RepairResult[], stopped: kinds.map(kind => ({ kind, reason: 'repair_error',
- message: `gbrain repair ${kind} failed (${String((error as { code?: unknown } | null)?.code ?? 'storage_error')}); run gbrain repair content --source ${sourceId} to see the error.` })) }));
- const repairError = lane.results.length === 0 && lane.stopped.some(s => s.reason === 'repair_error');
- const contentPreview: Action = { argv: ['gbrain', 'repair', 'content', '--source', sourceId], consent: [], actor: 'agent', requires_exclusive: false, verify,
- why: 'The content-repair lane failed during this unblock; its preview (writes nothing) shows the error and the plan for each held file.' };
+ const lane = await runContentLane(engine, await resolveRepairScope(engine, sourceId), { apply: true, kinds, only: paths, noLlm: opts.noLlm, maxLlmUsd: opts.maxLlmUsd,
+ deadline: Date.now() + UNBLOCK_REPAIR_BUDGET_MS, sourceFlag: sourceId, logger: quiet, ...(opts.registry ? { registry: opts.registry } : {}) });
const after = new Map((((await readGitSourceHolds(engine, { sourceIds: [sourceId] }))[0]?.holds ?? [])).map(hold => [hold.path, hold]));
const syncNext: Action = { argv: ['gbrain', 'sync', ...resume], consent: [], actor: 'agent', requires_exclusive: false, verify, why: 'Re-imports the repaired file and clears or re-screens its hold.' };
for (const [kind, records] of repairs) {
@@ -631,7 +625,7 @@ export async function unblockSync(engine: BrainEngine, sourceId: string, opts: U
detail: outcome === 'repaired' ? `repaired by gbrain repair ${kind}${typeof detail?.tier === 'string' ? ` (${detail.tier})` : ''}; scheduled for a re-screen`
: `${outcome} (${reason})${message ? `: ${message}` : !item && stop ? `: ${stop.message}` : ''}`,
repair: { kind, outcome, ...(reason ? { reason } : {}), ...(typeof detail?.tier === 'string' ? { tier: detail.tier } : {}), ...(llmUsd !== undefined ? { llm_usd: llmUsd } : {}),
- ...(receiptOf(detail) ? { receipt: receiptOf(detail) } : {}), next: outcome === 'repaired' ? syncNext : repairError ? contentPreview : outcome === 'skipped' && (!item || stop) ? unblockApply : fix } });
+ ...(receiptOf(detail) ? { receipt: receiptOf(detail) } : {}), next: outcome === 'repaired' ? syncNext : outcome === 'skipped' && (!item || stop) ? unblockApply : fix } });
}
}
}
diff --git a/src/core/repair/legacy-twins.ts b/src/core/repair/legacy-twins.ts
index 9991871303..9034ad7a05 100644
--- a/src/core/repair/legacy-twins.ts
+++ b/src/core/repair/legacy-twins.ts
@@ -59,6 +59,7 @@ import { liveFileDrift } from '../persistence/drift-conflicts.ts';
import { maintenancePreflight, submitMaintenanceIntent } from '../persistence/prepared-maintenance.ts';
import { clearApprovedSet, loadApprovedSet, previewChangedError, previewHash, saveApprovedSet } from '../persistence/preview-approval.ts';
import { readSyncImportProvenance, recordSyncImportProvenance } from '../persistence/sync-holds.ts';
+import { bindOrigin } from '../persistence/origin-guard.ts';
import { mergeTwinInto, twinMergeConflicts } from '../persistence/twin-merge.ts';
import { MASS_RECONCILE_MIN_PAGES, MASS_RECONCILE_RATIO, massReconcileAllowed } from '../sync-reconcile.ts';
import type { GhostOwner } from '../ghost-pages.ts';
@@ -357,7 +358,8 @@ async function applyTwinMerge(tx: BrainEngine, pair: LegacyTwinPair, incarnation
const [twinRow] = await tx.executeRaw<{ source_uri: string | null }>('SELECT source_uri FROM pages WHERE id=$1', [twin.page_id]);
const record = await readSyncImportProvenance(tx, sourceId, incarnation, twin.page_id);
const merged = await mergeTwinInto(tx, { sourceId, incarnation, survivor: legacy, twin });
- await tx.executeRaw('UPDATE pages SET source_path=$2, source_uri=COALESCE(source_uri, $3) WHERE id=$1', [legacy.page_id, pair.path, twinRow?.source_uri ?? null]);
+ await bindOrigin(tx, { sourceId, pageId: legacy.page_id, sourcePath: pair.path });
+ await tx.executeRaw('UPDATE pages SET source_uri=COALESCE(source_uri, $2) WHERE id=$1', [legacy.page_id, twinRow?.source_uri ?? null]);
if (record) {
const [now] = await tx.executeRaw<{ revision: string }>('SELECT knowledge_revision::text AS revision FROM pages WHERE id=$1', [legacy.page_id]);
await recordSyncImportProvenance(tx, { ...record, page_id: legacy.page_id, revision: now!.revision });
diff --git a/test/managed-sync-preparation-stalled-holds.test.ts b/test/managed-sync-preparation-stalled-holds.test.ts
index 6f9855ede1..4eea65888b 100644
--- a/test/managed-sync-preparation-stalled-holds.test.ts
+++ b/test/managed-sync-preparation-stalled-holds.test.ts
@@ -514,6 +514,10 @@ test('breaker: write_interrupted receipts trip it like stalled ones, and the tri
expect(why).not.toContain('5 write(s) of this sync could not finish preparing');
expect((await s.holds()).map(hold => [hold.path, hold.code]).sort()).toEqual([['notes/s0.md', 'preparation_stalled'], ['notes/s1.md', 'write_interrupted'],
['notes/s2.md', 'preparation_stalled'], ['notes/s3.md', 'write_interrupted']]);
+ // #6712 PR 4b retired the blocked-cursor conversion that re-screened these holds: the next pass re-screens both codes itself.
+ installFaultHook(undefined);
+ expect(await s.sync()).toMatchObject({ status: 'first_sync', added: 7, pass: { outcome: 'synced', candidates: 7 } });
+ expect(await s.holds()).toEqual([]);
// Only write_interrupted receipts: the trip names that code alone.
const t = await source(engine, files);
stallPaths(engine, t.id, new Set(Object.keys(files)), 'consumer:prepared', () => 'write_interrupted');
diff --git a/test/pathological/inventory-deferred.test.ts b/test/pathological/inventory-deferred.test.ts
index 9b73c81275..ef2faa9575 100644
--- a/test/pathological/inventory-deferred.test.ts
+++ b/test/pathological/inventory-deferred.test.ts
@@ -9,20 +9,13 @@ import { ISOLATE_SITES } from '../../src/core/item-failure.ts';
/** [row id, owner or disposition, what goes wrong] */
export const DEFERRED: ReadonlyArray<readonly [string, string, string]> = [
- ['A-5', 'GBRA-101 (4b)', 'A publication whose transaction **always** hits 57014 or 55P03 is released as database_contention without charging an attempt'],
- ['A-6', 'GBRA-101 (4b)', 'Managed sync drain'],
- ['A-7', 'GBRA-101 (4b)', 'Managed freeze of one entry'],
['A-8', 'GBRA-129', 'Managed discovery: two pages claim one source_path, or the page at the file\'s slug records another origin'],
- ['A-14', 'GBRA-101 (journal.ts is 4b-touched)', 'Compaction selects the 100 oldest eligible receipts, but it does not filter out each worktree\'s newest committed sync receipt there'],
['A-16', 'next wave (effect variant fixed with C-1)', 'A staging-bytes recovery, or a terminal request that still holds a recovery record, has no preview-bound exit (only the withdrawal-mirror effect variant is fixed)'],
- ['A-17', 'GBRA-101 (4b)', 'Managed discovery'],
['A-19', 'deferred (intentional gate; narrow later)', 'Legacy rename reconcile'],
['A-20', 'GBRA-101 (4b)', 'Managed screen'],
- ['A-28', 'GBRA-101 (4b)', 'gbrain sync unblock --source <id> --apply (the documented operator exit for held files) calls runContentLane for fence and slug-conflict holds with...'],
['A-29', 'deferred (intentional gate; narrow later)', 'One live job (waiting/active/delayed/waiting-children/paused) whose submission_authority is SQL NULL, malformed, or a future version written by a n...'],
['A-32', 'deferred: next wave (test.todo)', 'Legacy un-syncable sweep'],
['A-33', 'deferred: next wave (test.todo)', 'Full sync reconcile delete'],
- ['A-34', 'GBRA-101 (4b)', 'Owner-startup refresh recovery: rows ordered by created_at LIMIT 16 with no rotation'],
['A-35', 'deferred: next wave (test.todo)', 'drainEffects runs the noop-settle loop first'],
['A-37', 'deferred: next wave (test.todo)', 'extract_atoms, unmanaged'],
['A-38', 'deferred: next wave (test.todo)', 'Managed extract_facts on a connector source (always windowed by sourceChangedSince)'],
@@ -38,17 +31,13 @@ export const DEFERRED: ReadonlyArray<readonly [string, string, string]> = [
['A-56', 'deferred: next wave (test.todo)', 'Legacy facts backstop per page: catch { /* per-page enqueue is best-effort */ } with no counter'],
['A-57', 'GBRA-101 (4b)', 'Managed per-file prepare/screen: loadActivePackForEngine(...).catch(() => null)'],
['A-58', 'deferred: next wave (test.todo)', 'Legacy import, file gone from disk branch: clearLegacyHold is outside any try, so a DB error there escapes importOnePath and aborts the whole drain...'],
- ['A-59', 'GBRA-101 (4b)', 'If the movement read fails, writer status shows movement: [], which looks the same as "no movement"'],
['A-61', 'deferred: next wave (test.todo)', 'The comment says "the next settlement retries"'],
['A-62', 'deferred: next wave (test.todo)', 'doctor --remediate --resume with pending_embed_sources from a budget-exhausted checkpoint: one source\'s embed error aborts the run before any job s...'],
['A-63', 'deferred: next wave (test.todo)', 'gbrain repair file-drift --source <id> --all-drifted preview: a plain Error for one slug (fs EACCES/ENAMETOOLONG on the canonical path, a YAML or d...'],
['A-64', 'deferred: next wave (test.todo)', 'Fences\' managed write rethrows codes other than the changed/sync_in_progress set'],
- ['A-66', 'GBRA-101 (4b)', 'In the per-file catch branch, await opts.onFileResult?.(…) sits outside any try, so a throw from sync\'s ledger callback escapes and aborts the whol...'],
['A-67', 'deferred (intentional gate; narrow later)', 'Jobs fail as a whole when any single page or file was refused (#5904, #6273 intent: never report success over unwritten rows)'],
['B-1', 'GBRA-129', 'Two live pages record one source_path'],
['B-2', 'GBRA-101 (4b)', 'One page in the source whose stored source_path is empty, absolute or contains ../'],
- ['B-3', 'GBRA-101 (4b)', 'Two origins for one slug differ only by case or backslash spelling (People/X.md recorded, plus a new people/x.md in the tree)'],
- ['B-4', 'GBRA-101 (4b)', 'A file takes over the page at its slug whose explicit frontmatter id differs'],
['B-8', 'deferred: next wave (test.todo)', 'Rename A→B leaves alias A→B; a later put_page, import, restore or sync creates a live page at A'],
['B-11', 'deferred: next wave (test.todo)', 'NFD and NFC spellings are accepted as two different slugs (probe: validateSlug of people/jose + U+0301 is not equal to the NFC people/josé)'],
['B-13', 'deferred: next wave (test.todo)', 'Frontmatter id is not unique per source'],
diff --git a/test/sync-unblock-repair-error-gbra130.test.ts b/test/sync-unblock-repair-error-gbra130.test.ts
index 8852254e30..789246d569 100644
--- a/test/sync-unblock-repair-error-gbra130.test.ts
+++ b/test/sync-unblock-repair-error-gbra130.test.ts
@@ -1,12 +1,14 @@
/**
* GBRA-130 A-28 (#6712 PR 4b): `sync unblock --apply` ran the content-repair lane for its repair-class holds with no catch,
* so one unexpected throw from a repair kind aborted the whole unblock: no outcome was returned and the re-screens of the
- * other holds (`requestGitHoldRetry`) never ran.
+ * other holds (`requestGitHoldRetry`) never ran. The lane's per-kind catch (GBRA-130 A-46, master #6964,
+ * test/pathological/a46-content-lane-kinds.test.ts) now stops the throwing kind with reason `error`; this probe covers
+ * what that suite does not: the unblock outcome built on top of it.
*
* Protects (red before: unblock --apply rejects with the kind's error and schedules nothing): with the fences kind
- * stubbed to throw `OperationError('storage_error')`, the fence hold is reported `skipped` with reason `repair_error`
- * and `gbrain repair content --source <id>` as its next step, and the other hold (a `preparation_stalled` retry) is
- * still scheduled for its re-screen. Runs on PGLite and, with DATABASE_URL, on Postgres.
+ * stubbed to throw `OperationError('storage_error')`, the fence hold is reported `skipped` with reason `error` and
+ * `gbrain sync unblock --source <id> --apply --json` as its next step, and the other hold (a `preparation_stalled`
+ * retry) is still scheduled for its re-screen. Runs on PGLite and, with DATABASE_URL, on Postgres.
*/
import { describe, expect, test } from 'bun:test';
import { execFileSync } from 'node:child_process';
@@ -37,7 +39,7 @@ const throwingRegistry = REPAIR_REGISTRY.map(spec => spec.kind !== 'fences' ? sp
for (const backend of testBackends()) describe(`[${backend}] GBRA-130 A-28: a repair kind that throws during sync unblock --apply`, () => {
const databaseUrl = backend === 'postgres' ? process.env.DATABASE_URL : undefined;
- test('the fence hold is skipped repair_error with the content-lane preview as next, and the other hold is still scheduled', () => managedBrain(async ({ engine, root }) => {
+ test('the fence hold is skipped error with the unblock apply as next, and the other hold is still scheduled', () => managedBrain(async ({ engine, root }) => {
await withEnv({ OPENAI_API_KEY: undefined, ANTHROPIC_API_KEY: undefined, VOYAGE_API_KEY: undefined }, async () => {
expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');
mkdirSync(join(root, 'people'), { recursive: true });
@@ -51,7 +53,7 @@ for (const backend of testBackends()) describe(`[${backend}] GBRA-130 A-28: a re
observed_at: new Date().toISOString(), run_id: null, mode: 'managed', meta: { recovery_version: 1 } });
const outcome = await unblockSync(engine, 'default', { apply: true, noLlm: true, registry: throwingRegistry });
const fence = outcome.applied.find(entry => entry.path === 'people/model.md');
- expect(fence).toMatchObject({ action: 'repair', repair: { kind: 'fences', outcome: 'skipped', reason: 'repair_error', next: { argv: ['gbrain', 'repair', 'content', '--source', 'default'] } } });
+ expect(fence).toMatchObject({ action: 'repair', repair: { kind: 'fences', outcome: 'skipped', reason: 'error', next: { argv: ['gbrain', 'sync', 'unblock', '--source', 'default', '--apply', '--json'] } } });
expect(outcome.applied.find(entry => entry.path === 'notes/stalled.md')).toMatchObject({ action: 'retry' });
expect(await readGitHoldRetryPaths(engine, 'default', incarnation)).toEqual(['notes/stalled.md']);
});