feat: decision-plane wiring — ER-pair decision.match tie-break (@siax/0pt-decision)
CI (SIAX Cloud) / integration (push) Has been skipped
masterplan-lock / check (push) Successful in 4s
CI (SIAX Cloud) / security (push) Successful in 15s
Security Scan (SIAX Cloud) / security (push) Successful in 15s
masterplan-lock / check (pull_request) Successful in 11s
CI (SIAX Cloud) / security (pull_request) Successful in 14s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 16s
CI (SIAX Cloud) / integration (pull_request) Successful in 25s
CI (SIAX Cloud) / quality (push) Failing after 32s
CI (SIAX Cloud) / quality (pull_request) Failing after 33s

- packages/decision: erMatchDecision (0pt.er.pair_match mot siax-decision :4600)
- comparePair async + borderline-band (±0.05 av review_threshold) → decision.match
  (D1 advisory) — deterministisk status GÄLLER om decision abstainar
- OPT_DECISION_ER_ENABLED=1-gate (off tills kalibrering)
- tests async-anpassade (await generateCandidates/rejects.toThrowError)
- typecheck: 13 fel = pre-existing extraction-route (main-paritet), 0 nya fel
- tester: 1108 passed | 184 skipped
This commit is contained in:
Claude Code
2026-09-23 00:15:27 +02:00
parent 04e58c5d3c
commit fc1a62bb81
7 changed files with 125 additions and 23 deletions
+21 -5
View File
@@ -9,6 +9,7 @@
* an adapter to this canonical decision engine.
*/
import crypto from "crypto";
import { erMatchDecision, erDecisionEnabled } from "../../packages/decision/src/index.js";
import type { N0dClient, N0dJob } from "../clients/n0d-client";
import { SiaxError } from "../platform/errors";
import { isResourceRef } from "../platform/resource-ref";
@@ -88,7 +89,7 @@ export class EntityResolutionService {
this.hardRules.push(rule);
}
generateCandidates(req: ErCandidateRequest): ErCandidateResult {
async generateCandidates(req: ErCandidateRequest): Promise<ErCandidateResult> {
if (!req.tenant_id?.trim()) throw new SiaxError("INVALID_REQUEST", "0pt.er", "tenant_id is required");
if (!req.project_id?.trim()) throw new SiaxError("INVALID_REQUEST", "0pt.er", "project_id is required");
if (req.records.length < 2 || req.records.length > 5_000) {
@@ -144,7 +145,7 @@ export class EntityResolutionService {
for (let i = 0; i < bucket.length; i++) {
for (let j = i + 1; j < bucket.length; j++) {
blockedComparisons += 1;
pairs.push(this.comparePair(bucket[i], bucket[j], req, autoThreshold, reviewThreshold, key));
pairs.push(await this.comparePair(bucket[i], bucket[j], req, autoThreshold, reviewThreshold, key));
}
}
}
@@ -200,14 +201,14 @@ export class EntityResolutionService {
});
}
private comparePair(
private async comparePair(
a: ErRecord,
b: ErRecord,
req: ErCandidateRequest,
autoThreshold: number,
reviewThreshold: number,
blockingKey: string,
): ErCandidatePair {
): Promise<ErCandidatePair> {
for (const rule of this.hardRules) {
const decision = rule.decide(a, b);
if (decision !== "abstain") {
@@ -230,11 +231,22 @@ export class EntityResolutionService {
? 0
: explanation.reduce((sum, item) => sum + item.similarity * item.weight, 0) / weightSum;
const rounded = Math.round(score * 1000) / 1000;
const status: ErCandidateStatus = rounded >= autoThreshold
let status: ErCandidateStatus = rounded >= autoThreshold
? "match"
: rounded >= reviewThreshold
? "pending_review"
: "non_match";
// DECISION-plane (D1 advisory): borderline-band → decision.match tie-break.
// Deterministisk status GÄLLER om decision abstainar (doctor DEC-*:
// decision informerar, ersätter aldrig D0-authority).
if (erDecisionEnabled() && Math.abs(rounded - reviewThreshold) <= DECISION_BORDERLINE_BAND) {
const m = await erMatchDecision({
record_a: a.record_id,
record_b: b.record_id,
similarities: explanation.map((item) => ({ field: item.field, similarity: item.similarity, weight: item.weight })),
});
if (m.decided && m.label) status = m.label as ErCandidateStatus;
}
return {
candidate_id: `erc_${crypto.randomUUID()}`,
record_a: a.record_id,
@@ -314,3 +326,7 @@ function levenshtein(a: string, b: string): number {
}
return prev[n];
}
// --- DECISION-plane wiring (D1 advisory, aldrig gate) -------------------
const DECISION_BORDERLINE_BAND = Number(process.env.DECISION_BORDERLINE_BAND ?? 0.05);