Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(c2): Codex review round 2 — Windows colon refusal keeps database-only exemptions (#5032)
garrytane30058cdf258
diff --git a/src/core/persistence/page-mutations.ts b/src/core/persistence/page-mutations.tsindex f2b73ce502..73413e04e5 100644--- a/src/core/persistence/page-mutations.ts+++ b/src/core/persistence/page-mutations.ts@@ -21,6 +21,7 @@ import { normalizeSubagentPageInput } from './page-input.ts';import { assertKnowledgePublicationAllowed } from '../shared-skills/knowledge-guard.ts';import { isUnboundSourcePage, readUnboundWritePolicy, unboundSourceError } from './unbound-source.ts';import { colonSlugWindowsRefusal, isWindowsColonTarget } from './native-file-target.ts';+import { publishesDatabaseOnly } from './page-prepare.ts';import { isConnectorSourceKind } from './connector-identity.ts';export async function requestPrincipalForContext(ctx: OperationContext): Promise<Principal> {@@ -183,8 +184,9 @@ export async function submitPageMutation(ctx: OperationContext,}// #5032: this host publishes the canonical file, and on Windows a ':' in its// name cannot be stored; refuse before admission. Database-only writes pass.- if (writeThrough && binding?.owner_host_id === localHostId() && isWindowsColonTarget(snapshot?.page.source_path ?? `${slug}.md`)- && !(snapshot && !snapshot.page.source_path && await isUnboundSourcePage(ctx.engine, sourceId, slug))) {+ if (writeThrough && binding?.owner_host_id === localHostId() && binding.local_path && isWindowsColonTarget(snapshot?.page.source_path ?? `${slug}.md`)+ && !(snapshot && !snapshot.page.source_path && await isUnboundSourcePage(ctx.engine, sourceId, slug))+ && !publishesDatabaseOnly(join(binding.local_path, binding.relative_path), slug, snapshot)) {throw colonSlugWindowsRefusal(slug, sourceId);}const row = await admitWrite(ctx.engine, { principal, operation: input.operation, sourceId, sourceIncarnation: source.incarnation,diff --git a/src/core/persistence/page-prepare.ts b/src/core/persistence/page-prepare.tsindex db123cc621..806ca8bdad 100644--- a/src/core/persistence/page-prepare.ts+++ b/src/core/persistence/page-prepare.ts@@ -71,6 +71,14 @@ function putProvenance(row: WriteRequest, snapshot: PageSnapshot | null, parsed:function isNeverFiledDerivedPage(slug: string, page: { source_path?: string | null; source_uri?: string | null }): boolean {return !page.source_path && !page.source_uri && DERIVE_PHASE_DB_ONLY_DEFAULTS.some(prefix => slug.startsWith(prefix));}+/**+ * A live page whose canonical file is absent publishes to the database only+ * when its slug is a declared db_only path or a never-filed derive-phase page.+ */+export function publishesDatabaseOnly(root: string, slug: string, snapshot: PageSnapshot | null): boolean {+ if (!snapshot || snapshot.page.deleted_at) return false;+ return isSourceDbOnlySlug(root, slug, 'refuse') || isNeverFiledDerivedPage(slug, snapshot.page);+}export async function prepareFileTarget(engine: BrainEngine, row: Pick<WriteRequest, 'source_id' | 'worktree_id' | 'slug'>, snapshot: PageSnapshot | null,content: string | null, hostId?: string, options: { allowMissing?: boolean; capture?: { path: string; hash: string } } = {}): Promise<PreparedMutation['file']> {if (!row.worktree_id) return undefined;@@ -86,7 +94,10 @@ export async function prepareFileTarget(engine: BrainEngine, row: Pick<WriteRequconst mode = snapshot?.page.source_path ? await scannerSlugRootMode(engine, row.source_id, root) : undefined;const candidate = resolveSourceLocalFilePath(root, snapshot?.page.source_path, row.slug, mode)?? (capturedPath ? join(root, capturedPath) : join(root, `${row.slug}.md`));- if (isWindowsColonTarget(relative(root, candidate))) throw colonSlugWindowsRefusal(row.slug, row.source_id);+ if (isWindowsColonTarget(relative(root, candidate))) {+ if (!options.allowMissing && publishesDatabaseOnly(root, row.slug, snapshot)) return undefined;+ throw colonSlugWindowsRefusal(row.slug, row.source_id);+ }const path = nativeFileTarget(root, candidate);if (!isWriteTargetContained(path, root)) throw new OperationError('source_changed', 'The canonical file target is outside its registered source.');const before = existsSync(path) ? readFileSync(path) : null;@@ -94,12 +105,11 @@ export async function prepareFileTarget(engine: BrainEngine, row: Pick<WriteRequ// A declared db_only page has no canonical file by design and publishes to// the database only. gbrain.yml is consulted only here, where the write// would otherwise refuse, so an invalid config can only change the refusal.- if (isSourceDbOnlySlug(root, row.slug, 'refuse')) return undefined;// Derive-phase output (atoms/, concepts/, ...) is database-only by design and// deliberately never declared in gbrain.yml. A page there that never recorded a// canonical file publishes to the database only; a recorded file that went// missing still refuses below.- if (isNeverFiledDerivedPage(row.slug, snapshot.page)) return undefined;+ if (publishesDatabaseOnly(root, row.slug, snapshot)) return undefined;throw new OperationError('source_changed', 'The canonical file was removed outside coordinated publication.','Import the local deletion or recover the canonical file before editing this page.');}diff --git a/test/colon-slug-windows-5032.test.ts b/test/colon-slug-windows-5032.test.tsindex fd06924308..af7b860edf 100644--- a/test/colon-slug-windows-5032.test.ts+++ b/test/colon-slug-windows-5032.test.ts@@ -22,6 +22,7 @@ import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:import { tmpdir } from 'node:os';import { join } from 'node:path';import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import { importFromContent } from '../src/core/import-file.ts';import type { BrainEngine } from '../src/core/engine.ts';import { operations, OperationError, type OperationContext } from '../src/core/operations.ts';import { claimWorktree } from '../src/core/persistence/ownership.ts';@@ -110,6 +111,18 @@ describe('#5032 put_page with a colon slug', () => {expect((await engine.getPage('calendar:abc', { sourceId }))?.compiled_truth).toContain('A calendar event.');}), 60_000);+ test('Windows: a live database-only page (derive-phase path, no file) keeps updating', async () => withEnv({ GBRAIN_HOME: home }, async () => {+ const engine = engines[0];+ const root = join(home, `dbonly-${randomUUID()}`); mkdirSync(root);+ const sourceId = await addSource(engine, root);+ const seeded = await importFromContent(engine, 'atoms/cal:abc', CONTENT, { sourceId, noEmbed: true });+ expect(seeded.status).toBe('imported');+ await asWindows(() => putPage.handler(ctxOf(engine, sourceId), {+ slug: 'atoms/cal:abc', content: CONTENT.replace('A calendar event.', 'An updated event.'), force: true,+ }));+ expect((await engine.getPage('atoms/cal:abc', { sourceId }))?.compiled_truth).toContain('An updated event.');+ }), 60_000);+test('Windows: publication refuses a colon file target admitted elsewhere', async () => withEnv({ GBRAIN_HOME: home }, async () => {const engine = engines[0];const root = join(home, `pub-${randomUUID()}`); mkdirSync(root);