fix(session): retain failed provider cleanup for lifecycle retries (#1260)

Retire inactive clients until cleanup succeeds and block replacement startup
while owned resources remain. Preserve startup/cancellation failures alongside
cleanup diagnostics and retain explicit document choices across retries.

Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
This commit is contained in:
Ysopwnable
2026-10-09 17:56:17 +08:00
committed by GitHub
parent db0afce5f3
commit 24a3aa08d1
4 changed files with 441 additions and 37 deletions
+5 -4
View File
@@ -6,6 +6,7 @@ import { ProviderAdapterError } from "../domain/providerAdapterError.js";
import { err, type Result } from "../domain/result.js";
import type { AnalysisExecution } from "./AnalysisProvider.js";
import type { BinarySession } from "./binary/BinarySession.js";
import { analysisErrorWithCleanupFailure } from "./binary/AnalysisClientCleanup.js";
/** Await one-shot cleanup and retain either the outcome or both failures. */
export const withSessionCleanup = async <Value>(
@@ -77,19 +78,19 @@ export const managedAnalysisCleanupFailure = (
result: Result<AnalysisExecution, AnalysisError>,
error: AnalysisError,
): Result<AnalysisExecution, AnalysisError> => {
if (!result.ok)
return err(analysisErrorWithCleanupFailure(result.error, error));
const cleanup = projectAnalysisError(error);
return err(
new ProviderAdapterError(
error instanceof ProviderAdapterError ? error.providerId : "rea",
"close_binary",
{
cause: result.ok ? error : result.error,
cause: error,
cleanup: { reason: cleanup.message, resources: error.cleanupResources },
diagnostics: {
cleanup_error: cleanup,
...(result.ok
? { partial_observation: jsonValueSchema.parse(result.value) }
: { primary_error: projectAnalysisError(result.error) }),
partial_observation: jsonValueSchema.parse(result.value),
},
},
),