From bb0bcf62504c8e483b0d71aba900e30e439881ef Mon Sep 17 00:00:00 2001 From: Tianyi Cui <53024+tianyicui@users.noreply.github.com> Date: Sun, 26 Jul 2026 03:28:13 +0800 Subject: [PATCH] fix(llm): honor a carried failure snapshot on any Error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit markLlmAdapterFailure gated the own-`failure` data property on instanceof HarnessError, which drops the validated facts exactly when class identity is lost — two copies of this package in one process (e.g. a source-plane replay harness throwing into a lib-plane boot) make the replay-thrown LlmError's SERVER/AUTH code arrive as UNKNOWN and defeat llm-retry's retryable-code match. The snapshot is already validated field-by-field and cross-checked against the error's own code, so honor it on any Error. --- packages/llm/llm/src/adapter-failure.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/llm/llm/src/adapter-failure.ts b/packages/llm/llm/src/adapter-failure.ts index 390282327d..8da17807fa 100644 --- a/packages/llm/llm/src/adapter-failure.ts +++ b/packages/llm/llm/src/adapter-failure.ts @@ -47,7 +47,12 @@ export function markLlmAdapterFailure( const error = value instanceof Error ? value as Error & { code?: string } : new HarnessError(String(value), 'UNKNOWN', { cause: value }) - const carried = error instanceof HarnessError ? ownFailureSnapshot(error) : undefined + // The own `failure` data property is the serializable boundary contract: + // validated field-by-field and cross-checked against the error's own code, + // then honored on ANY Error — an instanceof gate here would drop the facts + // exactly when class identity is lost (a second copy of this package in + // the process, e.g. a source-plane test harness over a lib-plane boot). + const carried = ownFailureSnapshot(error) const failure = carried !== undefined && carried.code === error.code ? carried : Object.freeze({ message: errorMessage(error), code: harnessErrorCode(error),