feat(decision): Jev ER auto-match shadow (0PT_DECISION_ER_SHADOW)
CI (SIAX Cloud) / integration (push) Has been skipped
masterplan-lock / check (pull_request) Successful in 8s
CI (SIAX Cloud) / security (push) Successful in 24s
CI (SIAX Cloud) / security (pull_request) Successful in 40s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 1m0s
Security Scan (SIAX Cloud) / security (push) Successful in 1m34s
CI (SIAX Cloud) / integration (pull_request) Successful in 1m30s
masterplan-lock / check (push) Successful in 10s
CI (SIAX Cloud) / quality (pull_request) Failing after 24s
CI (SIAX Cloud) / quality (push) Failing after 33s
CI (SIAX Cloud) / integration (push) Has been skipped
masterplan-lock / check (pull_request) Successful in 8s
CI (SIAX Cloud) / security (push) Successful in 24s
CI (SIAX Cloud) / security (pull_request) Successful in 40s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 1m0s
Security Scan (SIAX Cloud) / security (push) Successful in 1m34s
CI (SIAX Cloud) / integration (pull_request) Successful in 1m30s
masterplan-lock / check (push) Successful in 10s
CI (SIAX Cloud) / quality (pull_request) Failing after 24s
CI (SIAX Cloud) / quality (push) Failing after 33s
Shadow-eval av D0 auto-match: D0-tröskeln förblir auktoritet, kvaliteten mäts fire-and-forget mot siax-decision (:4600, decisionId 0pt.er.auto_match). Gate 0PT_DECISION_ER_SHADOW=1 (OFF by default). Fail-closed: gate-off/fel/ABSTAINED påverkar aldrig det deterministiska svaret; decision-planen loggar inbyggt (AUD0). - packages/decision: erAutoMatchShadow + erAutoMatchShadowEnabled - src/er/comparePair: void erAutoMatchShadow(...).catch(() => null) - tests/p0/decision-er-shadow.test.ts: gate-off/on, POST-body, DECIDED/ABSTAINED, fetch-fel, fire-and-forget-wire (16 nya tester)
This commit is contained in:
@@ -60,3 +60,70 @@ export function erDecisionEnabled(): boolean {
|
||||
const v = process.env.OPT_DECISION_ER_ENABLED;
|
||||
return v === "1" || v === "true";
|
||||
}
|
||||
|
||||
// --- Shadow-eval (Jev-everywhere): auto-match-kvalitet mäts, påverkar ALDRIG ---
|
||||
export interface ErAutoMatchShadowInput {
|
||||
tenant_id: string;
|
||||
/** Målentiteten som auto-matchats av D0-tröskeln. */
|
||||
target: { record_id: string; fields?: Record<string, unknown> };
|
||||
/** Kandidaterna (tie-set) som D0 matchade mot målet. */
|
||||
candidates: Array<{ record_id: string; fields?: Record<string, unknown> }>;
|
||||
/** D0-score som triggade auto-matchen (skickas som kontext till beslutsplanet). */
|
||||
score?: number;
|
||||
}
|
||||
|
||||
export interface ErShadowResult {
|
||||
decided: boolean;
|
||||
choice?: string;
|
||||
confidence?: number;
|
||||
model?: string;
|
||||
latencyMs?: number;
|
||||
}
|
||||
|
||||
/** Shadow-gate: 0PT_DECISION_ER_SHADOW=1 (OFF by default — fire-and-forget). */
|
||||
export function erAutoMatchShadowEnabled(): boolean {
|
||||
return process.env["0PT_DECISION_ER_SHADOW"] === "1";
|
||||
}
|
||||
|
||||
/**
|
||||
* Shadow-eval av D0 auto-match: POST /decision/match (decisionId
|
||||
* `0pt.er.auto_match`). D0-tröskeln förblir auktoritet — svaret används endast
|
||||
* för kalibrering (decision-planen loggar inbyggt → AUD0). Fail-closed:
|
||||
* gate-off, nätverksfel, timeout eller ABSTAINED → null / decided:false,
|
||||
* kastar ALDRIG.
|
||||
*/
|
||||
export async function erAutoMatchShadow(
|
||||
input: ErAutoMatchShadowInput,
|
||||
): Promise<ErShadowResult | null> {
|
||||
if (!erAutoMatchShadowEnabled()) return null;
|
||||
try {
|
||||
const res = await fetch(`${DECISION_URL}/decision/match`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", Authorization: `Bearer ${DECISION_TOKEN}` },
|
||||
body: JSON.stringify({
|
||||
decision: "0pt.er.auto_match",
|
||||
left: input.target,
|
||||
right: input.candidates,
|
||||
instructions: "Which candidate is the same entity as the target?",
|
||||
minConfidence: 0.7,
|
||||
context: { tenant_id: input.tenant_id, d0_score: input.score },
|
||||
}),
|
||||
signal: AbortSignal.timeout(DECISION_TIMEOUT_MS),
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
const out = (await res.json()) as {
|
||||
data?: { status?: string; choice?: string; confidence?: number; model?: string; latencyMs?: number };
|
||||
};
|
||||
const d = out.data;
|
||||
if (!d || d.status !== "DECIDED") return { decided: false, confidence: d?.confidence };
|
||||
return {
|
||||
decided: true,
|
||||
choice: String(d.choice ?? ""),
|
||||
confidence: d.confidence,
|
||||
model: d.model,
|
||||
latencyMs: d.latencyMs,
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user