Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(repair): bind an extractor-facts apply to its preview's source scope

garrytand97a4d39287a
diff --git a/src/core/repair/extractor-facts.ts b/src/core/repair/extractor-facts.ts
index e8a8e9f92c..9ca5277594 100644
--- a/src/core/repair/extractor-facts.ts
+++ b/src/core/repair/extractor-facts.ts
@@ -95,6 +95,8 @@ export interface ExtractorFactsPage {
page_id: number;
request_id: string;
include_ambiguous: boolean;
+ /** The preview's source scope; an apply under another scope refuses. */
+ scope: string[];
facts: ExtractorFactCandidate[];
}
@@ -269,7 +271,7 @@ export const extractorFactsRepair: RepairHandler = {
if (fact.class === 'excluded' || fact.class === 'ambiguous' && !includeAmbiguous) continue;
const key = `${fact.source_id}\u0000${fact.slug}`;
const page = pages.get(key) ?? { source_id: fact.source_id, slug: fact.slug, page_id: pageIds.get(key)!,
- request_id: requestIdFor(hash, fact, 0), include_ambiguous: includeAmbiguous, facts: [] };
+ request_id: requestIdFor(hash, fact, 0), include_ambiguous: includeAmbiguous, scope: scope.source_ids, facts: [] };
page.facts.push(fact);
pages.set(key, page);
}
@@ -289,7 +291,10 @@ export const extractorFactsRepair: RepairHandler = {
'docs/guides/repair.md#explicit-only-repair-kinds');
}
const approved = await loadApprovedSet<ExtractorFactsPage>(engine, { command: 'extractor-facts', hash: opts.expect, previewCommand: command });
- if (approved.items.some(page => page.include_ambiguous !== includeAmbiguous)) throw previewChangedError(opts.expect, command);
+ const scopeKey = JSON.stringify(scope.source_ids);
+ if (approved.items.some(page => page.include_ambiguous !== includeAmbiguous || JSON.stringify(page.scope) !== scopeKey)) {
+ throw previewChangedError(opts.expect, command);
+ }
const done = await finishedPages(engine, opts.expect, approved.items);
const pending = approved.items.filter(page => !done.has(`${page.source_id}\u0000${page.slug}`));
if (!pending.length) await clearApprovedSet(engine, { command: 'extractor-facts', hash: opts.expect });
diff --git a/test/repair-extractor-facts.test.ts b/test/repair-extractor-facts.test.ts
index 4036c2de2e..3502822075 100644
--- a/test/repair-extractor-facts.test.ts
+++ b/test/repair-extractor-facts.test.ts
@@ -403,6 +403,8 @@ for (const backend of testBackends()) {
expect((await refusal(() => repair(engine, home, ['--source', sourceId, '--apply', '--expect', hashOf(preview)]))).code).toBe('preview_changed');
const wide = await repair(engine, home, ['--source', sourceId, '--include-ambiguous']);
expect(wide.results[0].affected).toBe(1);
+ // The hash is bound to the preview's source scope: applying it brain-wide refuses (Codex review).
+ expect((await refusal(() => repair(engine, home, ['--include-ambiguous', '--apply', '--expect', hashOf(wide)]))).code).toBe('preview_changed');
const applied = await repair(engine, home, ['--source', sourceId, '--include-ambiguous', '--apply', '--expect', hashOf(wide)]);
expect(applied.results[0].outcomes).toEqual({ restored: 1 });
expect(await factState(engine, [...ids, superseded])).toEqual([