fix(llm): honor a carried failure snapshot on any Error

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.
This commit is contained in:
Tianyi Cui
2026-07-26 03:28:13 +08:00
parent 2e52c0670c
commit bb0bcf6250

View File

@@ -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),