fix(orchestrator): preserve retryable effect failures

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex committed 2026-07-29 04:52:28 +02:00
1 parent 5bdb6deef7
commit bac4703bb1
2 files changed
+108 -28

No files matched your search

@@ -24,6 +24,7 @@ import {
executorLayer,
isNonRetryableProviderTurnControlFailure,
layerWithOptions as effectWorkerLayerWithOptions,
OrchestrationEffectExecutionError,
OrchestrationEffectExecutorV2,
OrchestrationEffectWorkerError,
OrchestrationEffectWorkerV2,
@@ -377,6 +378,81 @@ it.effect("requeues a replay-safe claim when success settlement fails", () =>
}),
);
it.effect("keeps a process-bound executor failure retryable when retry settlement fails", () =>
Effect.gen(function* () {
const now = DateTime.formatIso(yield* DateTime.now);
const effectId = "effect:worker-process-bound-retry-settlement-failure";
const workerId = "worker-process-bound-retry-settlement-failure";
const claimedEffect: OrchestrationEffectV2 = {
id: effectId,
commandId: CommandId.make("command:worker-process-bound-retry-settlement-failure"),
threadId: ThreadId.make("thread:worker-process-bound-retry-settlement-failure"),
request: {
type: "provider-turn.start",
runId: RunId.make("run:worker-process-bound-retry-settlement-failure"),
},
status: "running",
attemptCount: 1,
availableAt: now,
leaseOwner: workerId,
leaseExpiresAt: now,
createdAt: now,
updatedAt: now,
completedAt: null,
lastError: null,
};
const retryAttempts = yield* Ref.make(0);
const terminalizations = yield* Ref.make(0);
const outboxLayer = Layer.mock(EffectOutboxV2)({
claimNext: () => Effect.succeed(Option.some(claimedEffect)),
get: () => Effect.succeed(Option.some(claimedEffect)),
awaitCancellation: () => Effect.never,
clearCancellation: () => Effect.void,
retry: () =>
Ref.updateAndGet(retryAttempts, (count) => count + 1).pipe(
Effect.flatMap((attempt) =>
attempt === 1
? Effect.fail(
new EffectOutboxError({
operation: "retry",
effectId,
cause: "simulated retry settlement failure",
}),
)
: Effect.succeed(true),
),
),
fail: () => Ref.update(terminalizations, (count) => count + 1).pipe(Effect.as(true)),
});
const executorLayer = Layer.succeed(
OrchestrationEffectExecutorV2,
OrchestrationEffectExecutorV2.of({
execute: () =>
Effect.fail(
new OrchestrationEffectExecutionError({
effectId,
effectType: claimedEffect.request.type,
cause: "simulated provider execution failure",
}),
),
}),
);
const workerLayer = effectWorkerLayerWithOptions({ workerId }).pipe(
Layer.provide(Layer.merge(outboxLayer, executorLayer)),
);
const exit = yield* OrchestrationEffectWorkerV2.pipe(
Effect.flatMap((worker) => worker.runOnce),
Effect.provide(workerLayer),
Effect.exit,
);
assert.isTrue(Exit.isFailure(exit));
assert.equal(yield* Ref.get(retryAttempts), 2);
assert.equal(yield* Ref.get(terminalizations), 0);
}),
);
it.effect("uses durable deadlines, notifications, and a slow liveness poll", () =>
Effect.gen(function* () {
const attempts = yield* Ref.make(0);
@@ -493,38 +493,42 @@ export const layerWithOptions = (
}).pipe(Effect.onError((cause) => recoverClaimAfterExecutionStarted(effect, cause)));
}
return yield* Effect.gen(function* () {
const error = Cause.pretty(exit.cause);
const nonRetryable = isNonRetryableProviderTurnControlFailure(effect.request.type, error);
yield* Effect.logWarning("Orchestration effect execution failed", {
effectId: effect.id,
effectType: effect.request.type,
attemptCount: effect.attemptCount,
nonRetryable,
error,
});
// Prefer succeed for terminal interrupt races so the outbox does not
// keep a failed interrupt around; fail only when we must not retry.
const updated = nonRetryable
? yield* outbox.succeed({ effectId: effect.id, workerId })
: effect.attemptCount >= maxAttempts
? yield* outbox.fail({ effectId: effect.id, workerId, error })
: yield* outbox.retry({
const error = Cause.pretty(exit.cause);
const nonRetryable = isNonRetryableProviderTurnControlFailure(effect.request.type, error);
yield* Effect.logWarning("Orchestration effect execution failed", {
effectId: effect.id,
effectType: effect.request.type,
attemptCount: effect.attemptCount,
nonRetryable,
error,
});
// Prefer succeed for terminal interrupt races so the outbox does not
// keep a failed interrupt around; fail only when we must not retry.
const updated = nonRetryable
? yield* outbox
.succeed({ effectId: effect.id, workerId })
.pipe(Effect.onError((cause) => recoverClaimAfterExecutionStarted(effect, cause)))
: effect.attemptCount >= maxAttempts
? yield* outbox
.fail({ effectId: effect.id, workerId, error })
.pipe(Effect.onError((cause) => recoverClaimAfterExecutionStarted(effect, cause)))
: yield* outbox
.retry({
effectId: effect.id,
workerId,
error,
delayMs: Math.min(30_000, 100 * 2 ** Math.max(0, effect.attemptCount - 1)),
});
if (!updated) {
if (yield* wasCancelled(effect.id)) return true;
return yield* new OrchestrationEffectWorkerError({
operation: "reschedule",
effectId: effect.id,
cause: "The worker no longer owns the effect lease.",
});
}
return true;
}).pipe(Effect.onError((cause) => recoverClaimAfterExecutionStarted(effect, cause)));
})
.pipe(Effect.onError((cause) => requeueClaim(effect, cause)));
if (!updated) {
if (yield* wasCancelled(effect.id)) return true;
return yield* new OrchestrationEffectWorkerError({
operation: "reschedule",
effectId: effect.id,
cause: "The worker no longer owns the effect lease.",
});
}
return true;
}).pipe(
Effect.mapError((cause) =>
isOrchestrationEffectWorkerError(cause)