Skip to content

Commit bac7165

Browse files
committed
refactor(server): type native start ownership failures
Carry the exact thread, run and attempt plus missing/superseded state in a private tagged domain error instead of rejecting with bare strings. Keep interruption timeout classification and control behavior unchanged. Assert structured missing-owner diagnostics in the existing pre-ownership Stop regression.
1 parent 9954e9b commit bac7165

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/ProviderStartStop.integration.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,20 @@ it.effect.each([
420420
}
421421
if (scenario === "before-ownership") {
422422
yield* Deferred.await(beforeOwnership);
423+
const pending = (yield* orchestrator.getThreadProjection(threadId)).runs[0]!;
424+
const missing = yield* execution
425+
.interruptOwnedStart({
426+
threadId,
427+
runId: pending.id,
428+
attemptId: pending.activeAttemptId!,
429+
})
430+
.pipe(Effect.flip);
431+
assert.isFalse(missing.unresponsive);
432+
assert.nestedPropertyVal(missing, "cause._tag", "NativeStartOwnershipError");
433+
assert.nestedPropertyVal(missing, "cause.state", "missing");
434+
assert.nestedPropertyVal(missing, "cause.threadId", threadId);
435+
assert.nestedPropertyVal(missing, "cause.runId", pending.id);
436+
assert.nestedPropertyVal(missing, "cause.attemptId", pending.activeAttemptId);
423437
yield* orchestrator.dispatch({
424438
type: "thread.stop",
425439
commandId: CommandId.make("stop"),

‎apps/server/src/orchestration-v2/RunExecutionService.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,22 @@ type StartInterruptTarget = {
608608
readonly providerTurnId: ProviderTurnId;
609609
};
610610

611+
class NativeStartOwnershipError extends Schema.TaggedError<NativeStartOwnershipError>()(
612+
"NativeStartOwnershipError",
613+
{
614+
threadId: ThreadId,
615+
runId: RunId,
616+
attemptId: RunAttemptId,
617+
state: Schema.Literals(["missing", "superseded"]),
618+
},
619+
) {
620+
override get message(): string {
621+
return this.state === "missing"
622+
? "Missing unresolved native-start owner"
623+
: "Native-start binding was superseded";
624+
}
625+
}
626+
611627
export class RunExecutionInterruptError extends Schema.TaggedError<RunExecutionInterruptError>()(
612628
"RunExecutionInterruptError",
613629
{
@@ -1001,7 +1017,7 @@ export const layer: Layer.Layer<
10011017
.every((turn) => isTerminalProviderTurnStatus(turn.status))
10021018
)
10031019
return;
1004-
return yield* Effect.fail("Missing unresolved native-start owner");
1020+
return yield* new NativeStartOwnershipError({ ...key, state: "missing" });
10051021
}
10061022
const accepted = yield* Deferred.await(owner.accepted).pipe(
10071023
Effect.raceFirst(Deferred.await(owner.terminal).pipe(Effect.as(undefined))),
@@ -1023,7 +1039,7 @@ export const layer: Layer.Layer<
10231039
binding.nativeThreadRef?.nativeId !==
10241040
owner.input.providerThread.nativeThreadRef?.nativeId
10251041
) {
1026-
return yield* Effect.fail("Native-start binding was superseded");
1042+
return yield* new NativeStartOwnershipError({ ...key, state: "superseded" });
10271043
}
10281044
if (yield* Deferred.isDone(owner.terminal)) return;
10291045
const turn = owner.turn ?? accepted;

0 commit comments

Comments
 (0)