Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: pre-landing review fixes

garrytanddd54a9743c4
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9713659e32..23e3eedd79 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@ When a managed source's folder was a plain directory, or a `git init` with no co
- The strict-pass receipt-wait test runs in about 6 seconds instead of sleeping past a 30-second wait: the managed sync receipt waits now live in one module with a test seam. It covers both strict passes.
- A direct test covers the NULL-vector clause of the no-op embedding check.
+
## [0.60.493.0] - 2026-10-29
**`search` now finds a saved fact by its words the way the facts keyword index does, and a newer correction comes back ahead of the fact it corrects (`search.saved_facts_supersede`, on by default). In a keyless replay of 816 harness `search` calls, the author's correction ranked above the retracted post in 27 of 27 reads of the corrections case, against 1 of 27 on 0.60.492.0.**
diff --git a/src/core/persistence/git-conversion.ts b/src/core/persistence/git-conversion.ts
index dec0425154..a12c64dbef 100644
--- a/src/core/persistence/git-conversion.ts
+++ b/src/core/persistence/git-conversion.ts
@@ -61,6 +61,7 @@ import { DURABILITY_NOT_ENABLED_REASON, gitDurabilityPolicy } from './git-durabi
import { currentVerifiedLocalWriter, localHostId } from './identity.ts';
import { acquireWorktree, getWorktreeBinding, readManagedMode } from './ownership.ts';
import { inspectDurabilityCheckout } from './git-durability-administration.ts';
+import { classifyGitCheckout } from '../git-checkout.ts';
import { resolveManagedSyncContext, type ManagedSyncContext } from './sync-discovery.ts';
import { readShadowLevel } from './sync-pass.ts';
import { isPrivacyClass, type PrivacyClass } from './git-declared.ts';
@@ -197,33 +198,37 @@ export async function assertConversionCaller(engine: BrainEngine, sourceId: stri
/**
* #7885: a root with no Git checkout, or one whose branch has no commit yet, has nothing to convert into. The plan refuses
- * before it reads anything, and the source keeps working as it is (the database is its record).
+ * before it reads anything, and the source keeps working as it is (the database is its record). A root it cannot read
+ * (gone, unmounted, not a directory) is left to the context resolution, which owns those refusals.
*/
async function assertConversionCheckout(sourceId: string, root: string): Promise<void> {
- try { await inspectDurabilityCheckout(root); }
+ if (classifyGitCheckout(root) === 'unknown') return;
+ let code: 'git_checkout_required' | 'git_branch_unborn';
+ try { await inspectDurabilityCheckout(root); return; }
catch (error) {
- if (!(error instanceof OperationError) || (error.code !== 'git_checkout_required' && error.code !== 'git_branch_unborn')) {
- if (error instanceof OperationError && error.code === 'git_detached_head') return;
- throw error;
- }
- const code = error.code === 'git_checkout_required' ? 'git_checkout_required' as const : 'git_branch_unborn' as const;
- const state = code === 'git_checkout_required' ? 'is not inside a Git checkout' : 'is a Git checkout with no commit yet';
- const why = 'A git-canonical source commits every page to Git on top of the checkout\'s branch, so its root needs a Git checkout with a first commit.';
- throw opError(code, `Source ${sourceId}'s root ${root} ${state}, so it has nothing to convert into; nothing was read or written. The source stays usable as it is, with the database as its record.`,
- 'Keep the source as it is, or make its root a Git repository with a first commit on the brain host (git init, git add -A, git commit), then preview again.',
- { why, docs: DOCS, fix: { argv: ['gbrain', 'sources', 'canonical', sourceId, '--to', 'git', '--dry-run', '--json'], consent: [], actor: 'user', requires_exclusive: false,
- why: 'Previews the conversion again once the root has a first commit; read-only.',
- user_message: `Source ${sourceId} has no Git history to convert into. It keeps working as it is. Should its folder become a Git repository with a first commit so it can be converted?` } });
+ if (!(error instanceof OperationError)) throw error;
+ if (error.code === 'git_detached_head') return;
+ if (error.code !== 'git_checkout_required' && error.code !== 'git_branch_unborn') throw error;
+ code = error.code === 'git_checkout_required' ? 'git_checkout_required' : 'git_branch_unborn';
}
+ const state = code === 'git_checkout_required' ? 'is not inside a Git checkout' : 'is a Git checkout with no commit yet';
+ const why = 'A git-canonical source commits every page to Git on top of the checkout\'s branch, so its root needs a Git checkout with a first commit.';
+ throw opError(code, `Source ${sourceId}'s root ${root} ${state}, so it has nothing to convert into; nothing was read or written. The source stays usable as it is, with the database as its record.`,
+ 'Keep the source as it is, or make its root a Git repository with a first commit on the brain host (git init, git add -A, git commit), then preview again.',
+ { why, docs: DOCS, fix: { argv: ['gbrain', 'sources', 'canonical', sourceId, '--to', 'git', '--dry-run', '--json'], consent: [], actor: 'user', requires_exclusive: false,
+ why: 'Previews the conversion again once the root has a first commit; read-only.',
+ user_message: `Source ${sourceId} has no Git history to convert into. It keeps working as it is. Should its folder become a Git repository with a first commit so it can be converted?` } });
}
+
+
/** The context a strict pass reads, for a source whose row does not say so yet. */
const strictContext = (context: ManagedSyncContext): ManagedSyncContext => ({ ...context, source: { ...context.source, config: { ...context.source.config, canonical: 'git' } } });
/** The read-only plan of `--to git`; its preview is what the CLI prints and the apply binds to. */
export async function planGitConversion(engine: BrainEngine, sourceId: string): Promise<GitConversionPlan> {
const binding = await getWorktreeBinding(engine, sourceId);
- if (binding?.local_path) await assertConversionCheckout(sourceId, resolve(binding.local_path, binding.relative_path));
+ if (binding?.local_path && binding.owner_host_id === localHostId() && binding.state === 'active') await assertConversionCheckout(sourceId, resolve(binding.local_path, binding.relative_path));
const context = await resolveManagedSyncContext(engine, { sourceId, noPull: true, dryRun: true });
const pages: GitGapPage[] = [];
const equal = new Map<string, PageRevision>();
@@ -564,7 +569,7 @@ export async function applyGitConversion(engine: BrainEngine, sourceId: string,
const push = final.reason === 'nothing_to_push' ? progress.push! : final;
report({ push });
let after = (await planGitConversion(engine, sourceId)).preview, closing = 0;
- for (; after.remaining > 0 && after.remaining === after.git_wins.count && closing < CLOSING_PASSES; closing++) {
+ for (; after.strict && after.remaining > 0 && after.remaining === after.git_wins.count && closing < CLOSING_PASSES; closing++) {
passOrThrow(sourceId, 'strict_pass_closing', await pass('strict_pass_closing', after.git_wins.count), progress);
after = (await planGitConversion(engine, sourceId)).preview;
}
diff --git a/src/core/persistence/sync-receipt-wait.ts b/src/core/persistence/sync-receipt-wait.ts
index 0b36b8e87f..044ab06eac 100644
--- a/src/core/persistence/sync-receipt-wait.ts
+++ b/src/core/persistence/sync-receipt-wait.ts
@@ -1,9 +1,10 @@
/**
* How long a managed sync pass waits on its own admitted write: a single pass stops `writer_pending` after `pass` (`held`
- * while this process's consumer still holds the write, #6712 item 7), and a drain re-enters after `drain`. One place with a
- * test seam (#7886), so a test can outlast a wait in milliseconds instead of sleeping past 30 s.
+ * while this process's consumer still holds the write, #6712 item 7; `checkpoint` for a sync checkpoint, #5762), and a drain
+ * re-enters after `drain`. One place with a test seam (#7886), so a test can outlast a wait in milliseconds instead of
+ * sleeping past 30 s.
*/
-const DEFAULTS = { pass: 5000, held: 30_000, drain: 30_000 };
+const DEFAULTS = { pass: 5000, checkpoint: 8000, held: 30_000, drain: 30_000 };
let waits = DEFAULTS;
export const syncReceiptWait = (): typeof DEFAULTS => waits;
diff --git a/src/core/persistence/sync-run.ts b/src/core/persistence/sync-run.ts
index 188ee6a796..cff5fba84b 100644
--- a/src/core/persistence/sync-run.ts
+++ b/src/core/persistence/sync-run.ts
@@ -1532,7 +1532,7 @@ async function runManagedSync(engine: BrainEngine, opts: SyncOpts, slice: { maxP
// #5762: a checkpoint's validation runs under the coordinator's 5 s statement timeout, so its wait outlasts that
// budget; a timed-out checkpoint then reports its terminal refusal and hint in this run instead of the next.
// #5984: a drain re-enters anyway, so it waits longer per page instead of paying a full re-entry; the stop signal bounds every wait (awaitWrite).
- const waited = await awaitWrite(engine, row, config, opts.drainStartedAt ? { waitMs: syncReceiptWait().drain, signal } : { waitMs: pending.intent.kind === 'managed_sync_checkpoint' ? 8000 : syncReceiptWait().pass, signal, ...whileHeld });
+ const waited = await awaitWrite(engine, row, config, opts.drainStartedAt ? { waitMs: syncReceiptWait().drain, signal } : { waitMs: pending.intent.kind === 'managed_sync_checkpoint' ? syncReceiptWait().checkpoint : syncReceiptWait().pass, signal, ...whileHeld });
const done = waited.row;
assertSyncDispatchActive();
if (!isTerminalWriteState(done.state)) {
diff --git a/test/git-canonical-conversion-no-checkout-7885.test.ts b/test/git-canonical-conversion-no-checkout-7885.test.ts
index 9f59506f89..282aade76c 100644
--- a/test/git-canonical-conversion-no-checkout-7885.test.ts
+++ b/test/git-canonical-conversion-no-checkout-7885.test.ts
@@ -5,7 +5,7 @@
*/
import { describe, expect, test } from 'bun:test';
import { execFileSync } from 'node:child_process';
-import { mkdirSync, writeFileSync } from 'node:fs';
+import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { operationsByName } from '../src/core/operations.ts';
import { planGitConversion } from '../src/core/persistence/git-conversion.ts';
@@ -28,6 +28,13 @@ async function cli(engine: Parameters<typeof runSourcesCanonical>[0], args: stri
return JSON.parse(out.at(-1)!);
}
+const detached = ({ root }: { root: string }) => {
+ plain({ root });
+ const git = (...args: string[]) => execFileSync('git', ['-C', root, '-c', 'commit.gpgsign=false', ...args], { stdio: 'ignore' });
+ git('init', '-q'); git('config', 'user.name', 'Example Writer'); git('config', 'user.email', '[email protected]');
+ git('add', '-A'); git('commit', '-qm', 'notes'); git('checkout', '-q', '--detach');
+};
+
for (const backend of testBackends()) describe(`[${backend}] #7885: --to git on a managed source without a Git checkout`, () => {
const databaseUrl = backend === 'postgres' ? requirePostgresTestDatabase() : undefined;
@@ -44,4 +51,20 @@ for (const backend of testBackends()) describe(`[${backend}] #7885: --to git on
expect(written.status).toBe('created_or_updated');
}, { databaseUrl, setup }), 120_000);
}
+
+ // Value: protects=a root on a detached HEAD is not refused as checkout-less, so the preview still plans; fails_when=assertConversionCheckout rethrows git_detached_head or maps it to a checkout refusal; why_new=the two refusal cases never reach the detached-HEAD early return; seam=none; no_claim=the apply on a detached HEAD (pushes are the durability check's concern)
+ test('a detached HEAD is not a missing checkout: the preview plans instead of refusing', () => managedBrain(async ({ engine }) => {
+ const { preview } = await planGitConversion(engine, 'default');
+ expect(preview.source_id).toBe('default');
+ }, { databaseUrl, setup: detached }), 120_000);
+
+ // Value: protects=a root that is gone (unmounted, moved) is never refused as checkout-less, whose fix would git init an empty repository there; fails_when=assertConversionCheckout maps an unreadable root to git_checkout_required; why_new=the refusal tests all have a readable root; seam=none; no_claim=which refusal the context resolution gives
+ test('a root that is gone is not refused as a missing checkout: the context resolution owns it', () => managedBrain(async ({ engine, root }) => {
+ rmSync(root, { recursive: true, force: true });
+ try {
+ const refused = await planGitConversion(engine, 'default').then(() => null, (error: { code?: string }) => error);
+ expect(refused).not.toBeNull();
+ expect(refused!.code).not.toBe('git_checkout_required');
+ } finally { mkdirSync(root, { recursive: true }); }
+ }, { databaseUrl, setup: plain }), 120_000);
});