From 343a93ded32960a08325e86ca9920838587bedf7 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 15 Jul 2026 16:13:10 -0700 Subject: [PATCH] fix(release): repair validation correlations (#108489) --- .../gateway-models.profiles.live.test.ts | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/gateway/gateway-models.profiles.live.test.ts b/src/gateway/gateway-models.profiles.live.test.ts index 63a7e52d9b2f..b08189904e5a 100644 --- a/src/gateway/gateway-models.profiles.live.test.ts +++ b/src/gateway/gateway-models.profiles.live.test.ts @@ -2226,9 +2226,10 @@ function sessionMessagesAfterNextUserTurn( expectedUserText?: string, ): unknown[] { const nextUserOffset = messages.slice(baselineMessageCount).findIndex((message) => { + const actualUserText = extractTranscriptMessageText(message); return ( (message as { role?: unknown } | null | undefined)?.role === "user" && - (expectedUserText === undefined || extractTranscriptMessageText(message) === expectedUserText) + (expectedUserText === undefined || matchesLiveProbeUserText(actualUserText, expectedUserText)) ); }); if (nextUserOffset < 0) { @@ -2237,6 +2238,20 @@ function sessionMessagesAfterNextUserTurn( return messages.slice(baselineMessageCount + nextUserOffset + 1); } +function matchesLiveProbeUserText(actual: string, expected: string): boolean { + if (actual === expected) { + return true; + } + const markerIndex = expected.indexOf(`${ANTHROPIC_MAGIC_STRING_TRIGGER_REFUSAL}_`); + if (markerIndex < 0) { + return false; + } + const nonceSuffix = expected.slice(markerIndex + ANTHROPIC_MAGIC_STRING_TRIGGER_REFUSAL.length); + // The embedded Anthropic runtime scrubs the refusal trigger before persisting it. + // Its random suffix survives and still uniquely owns this live probe turn. + return /^_[a-f0-9]{32}$/.test(nonceSuffix) && actual.endsWith(nonceSuffix); +} + function sessionAssistantEntriesForLiveProbe( messages: readonly unknown[], modelKey?: string, @@ -2401,6 +2416,20 @@ describe("latestAssistantTextAfterBaseline", () => { ); expect(latestTerminalAssistantTextAfterBaseline(secondEntries, 0)).toBe("second-a second-b"); }); + + it("correlates Anthropic refusal probes after the runtime scrubs their trigger", () => { + const nonce = "0123456789abcdef0123456789abcdef"; + const expected = `Reply with ok. ${ANTHROPIC_MAGIC_STRING_TRIGGER_REFUSAL}_${nonce}`; + const scrubbed = `Reply with ok. ANTHROPIC MAGIC STRING TRIGGER REFUSAL (redacted)_${nonce}`; + + expect(matchesLiveProbeUserText(scrubbed, expected)).toBe(true); + expect( + matchesLiveProbeUserText( + "Reply with ok. ANTHROPIC MAGIC STRING TRIGGER REFUSAL (redacted)_ffffffffffffffffffffffffffffffff", + expected, + ), + ).toBe(false); + }); }); async function waitForSessionAssistantText(params: {