Skip to content

Commit fc1bf74

Browse files
author
Brandon Vincitore
committed
fix(server): narrow exact force-stop settlement targets
Express active-run and completed-background settlement as explicit branches so each native target is narrowed before use. Preserve the exact-attempt and checkpoint-waiting behavior. Complete the fork-owned proof typing: discard an interrupt waiter's unused target value, and declare the adapter test hook's actual runtime Scope requirement. These corrections preserve runtime behavior and pass the owning server typecheck. Source-PR: pingdotgg#31933 Source-Commit: fbaa763 Model: gpt-6.1-sol. Harness: Codex.
1 parent bde4544 commit fc1bf74

3 files changed

Lines changed: 39 additions & 36 deletions

File tree

‎apps/server/src/orchestration-v2/ProviderSessionManager.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import * as Layer from "effect/Layer";
3030
import * as Option from "effect/Option";
3131
import * as Queue from "effect/Queue";
3232
import * as Ref from "effect/Ref";
33+
import type * as Scope from "effect/Scope";
3334
import * as Stream from "effect/Stream";
3435
import { TestClock } from "effect/testing";
3536
import { HttpServer } from "effect/http";
@@ -433,7 +434,7 @@ const makeProviderAdapter = Effect.fnUntraced(function* (
433434
readonly beforeOpen?: (input: {
434435
readonly providerSessionId: ProviderSessionId;
435436
readonly initialProviderItemIdentityVersion?: 2;
436-
}) => Effect.Effect<void>;
437+
}) => Effect.Effect<void, never, Scope.Scope>;
437438
readonly hasPendingBackgroundWork?: Effect.Effect<boolean>;
438439
readonly hasPendingBackgroundWorkForThread?: Effect.Effect<boolean>;
439440
readonly backgroundTasksEndWithProcess?: boolean;
@@ -600,7 +601,7 @@ function layerTest(input: {
600601
readonly beforeOpen?: (input: {
601602
readonly providerSessionId: ProviderSessionId;
602603
readonly initialProviderItemIdentityVersion?: 2;
603-
}) => Effect.Effect<void>;
604+
}) => Effect.Effect<void, never, Scope.Scope>;
604605
readonly failReleaseEventWrites?: boolean;
605606
readonly flakyReleaseWrites?: FlakyReleaseWrites;
606607
readonly pauseAttachWrite?: Parameters<typeof layerPausingAttachEventSink>[0];

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,13 @@ it.effect.each([
564564
Effect.andThen(
565565
scenario === "failed-scope-close"
566566
? Effect.void
567-
: execution.interruptOwnedStart({
568-
threadId,
569-
runId: run.id,
570-
attemptId: run.activeAttemptId!,
571-
}),
567+
: execution
568+
.interruptOwnedStart({
569+
threadId,
570+
runId: run.id,
571+
attemptId: run.activeAttemptId!,
572+
})
573+
.pipe(Effect.asVoid),
572574
),
573575
Effect.forkScoped,
574576
);

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,35 +1245,35 @@ const make = Effect.gen(function* () {
12451245
const commandId = CommandId.make(
12461246
`server:force-stop:${run.id}:${yield* Clock.currentTimeMillis}`,
12471247
);
1248-
yield* providerTurn === undefined && !active
1249-
? Effect.void
1250-
: active
1251-
? orchestrator.dispatch(
1252-
run.activeAttemptId === null
1253-
? {
1254-
type: "run.interrupt",
1255-
commandId,
1256-
threadId: input.threadId,
1257-
runId: run.id,
1258-
reason: FORCE_STOP_REASON,
1259-
}
1260-
: {
1261-
type: "run.force-stop.settle",
1262-
commandId,
1263-
threadId: input.threadId,
1264-
runId: run.id,
1265-
attemptId: run.activeAttemptId,
1266-
reason: FORCE_STOP_REASON,
1267-
},
1268-
)
1269-
: orchestrator.dispatch({
1270-
type: "thread.background-work.settle",
1271-
commandId,
1272-
threadId: input.threadId,
1273-
providerThreadId: providerTurn.providerThreadId,
1274-
providerTurnId: providerTurn.id,
1275-
reason: FORCE_STOP_REASON,
1276-
});
1248+
if (active) {
1249+
yield* orchestrator.dispatch(
1250+
run.activeAttemptId === null
1251+
? {
1252+
type: "run.interrupt",
1253+
commandId,
1254+
threadId: input.threadId,
1255+
runId: run.id,
1256+
reason: FORCE_STOP_REASON,
1257+
}
1258+
: {
1259+
type: "run.force-stop.settle",
1260+
commandId,
1261+
threadId: input.threadId,
1262+
runId: run.id,
1263+
attemptId: run.activeAttemptId,
1264+
reason: FORCE_STOP_REASON,
1265+
},
1266+
);
1267+
} else if (providerTurn !== undefined) {
1268+
yield* orchestrator.dispatch({
1269+
type: "thread.background-work.settle",
1270+
commandId,
1271+
threadId: input.threadId,
1272+
providerThreadId: providerTurn.providerThreadId,
1273+
providerTurnId: providerTurn.id,
1274+
reason: FORCE_STOP_REASON,
1275+
});
1276+
}
12771277
}
12781278
const ownProviderThreadIds = records.providerThreads.flatMap((providerThread) =>
12791279
providerThread.appThreadId === input.threadId ? [providerThread.id] : [],

0 commit comments

Comments
 (0)