Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

P8: conflict dataset adapter gets a harmful-action reducer so review kinds can qualify

garrytan56a4dbbe260f
diff --git a/src/core/ai/decide/datasets-conflict.ts b/src/core/ai/decide/datasets-conflict.ts
index 0a7c9642a7..e0eea9e5e5 100644
--- a/src/core/ai/decide/datasets-conflict.ts
+++ b/src/core/ai/decide/datasets-conflict.ts
@@ -4,7 +4,9 @@
* The adapter builds the production request shape: state = the new fact
* (class `facts`), one `choice` question per candidate (duplicate | supersede
* | independent). Conflict is not a harmful-direction slot (v1 only writes
- * proposals), so it has no harmful-action reducer.
+ * proposals). Its harmful-action reducer serves the review lane's acting call
+ * sites: `gbrain decide qualify --slot conflict --call-site review_withdraw`
+ * bounds the precision of the withdrawals it would propose.
*
* `gbrain decide dataset --slot conflict --from facts-fixtures <path>` reads
* labelled fact pairs, one JSON object per line:
@@ -66,6 +68,14 @@ export function registerConflictDatasets(): void {
},
calibrationValue: duplicateValue,
calibrateExtra: calibrateProposalFloor,
+ // The acting call sites (review_withdraw, review_duplicate_*) act on a duplicate at or above the threshold;
+ // qualification counts each such action correct exactly when the pair is labelled duplicate.
+ harmfulActions(family, values, policy) {
+ return family.flatMap((it) => {
+ const p = values[it.id];
+ return p === null || p === undefined || p < policy.threshold ? [] : [{ item: it, correct: it.label === true }];
+ });
+ },
});
registerDatasetBuilder('facts-fixtures', async (path, opts) => parseConflictPairs(await Bun.file(path).text(), opts));
}
diff --git a/test/decide/conflict.test.ts b/test/decide/conflict.test.ts
index 90126c0b11..d1acd97706 100644
--- a/test/decide/conflict.test.ts
+++ b/test/decide/conflict.test.ts
@@ -113,7 +113,11 @@ describe('request shape and dataset', () => {
const req = adapter.request([...families(items).values()][0]!);
expect(req.state.fact).toMatchObject({ text: 'Alice is CTO of Acme', class: 'facts' });
expect(req.questions.map((q) => q.inputs?.candidate?.text)).toEqual(['Alice is VP Eng at Acme', 'Alice is the CTO at Acme']);
- expect(adapter.harmfulActions).toBeUndefined();
+ // The review lane's acting call sites qualify on it: an action at or above the threshold is correct only on a duplicate label.
+ const [a1, a2] = items;
+ const p = { threshold: 0.9, margin: 0, minKeep: 0 };
+ expect(adapter.harmfulActions!([a1!, a2!], { a1: 0.95, a2: 0.95 }, p).map((a) => [a.item.id, a.correct])).toEqual([['a1', false], ['a2', true]]);
+ expect(adapter.harmfulActions!([a1!, a2!], { a1: 0.5, a2: null }, p)).toEqual([]);
});
});