Skip to content

Commit cf20d21

Browse files
fix(orchestration): preserve v2 thread deletion planning
1 parent 393e2a0 commit cf20d21

3 files changed

Lines changed: 28 additions & 27 deletions

File tree

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

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,9 +1909,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
19091909
// decided serially against the projection, so a turn start that
19101910
// re-engages the thread cannot race this detach.
19111911
const detachSessionIds = new Set(
1912-
command.type === "thread.archive" ||
1913-
command.type === "thread.delete" ||
1914-
command.type === "thread.settle"
1912+
command.type === "thread.archive" || command.type === "thread.settle"
19151913
? projection.providerSessions.map((session) => session.id)
19161914
: command.type === "thread.metadata.update" &&
19171915
command.worktreePath !== undefined &&
@@ -1953,13 +1951,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
19531951
? "Thread archived."
19541952
: command.type === "thread.settle"
19551953
? "Thread settled."
1956-
: command.type === "thread.delete"
1957-
? "Thread deleted."
1958-
: command.type === "thread.metadata.update"
1959-
? "Workspace changed."
1960-
: command.type === "thread.runtime-mode.set"
1961-
? "Runtime mode changed."
1962-
: "Provider or model selection changed.",
1954+
: command.type === "thread.metadata.update"
1955+
? "Workspace changed."
1956+
: command.type === "thread.runtime-mode.set"
1957+
? "Runtime mode changed."
1958+
: "Provider or model selection changed.",
19631959
},
19641960
});
19651961
const pendingEffect = {
@@ -1974,19 +1970,15 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
19741970
? "Thread archived."
19751971
: command.type === "thread.settle"
19761972
? "Thread settled."
1977-
: command.type === "thread.delete"
1978-
? "Thread deleted."
1979-
: command.type === "thread.metadata.update"
1980-
? "Workspace changed."
1981-
: command.type === "thread.runtime-mode.set"
1982-
? "Runtime mode changed."
1983-
: "Provider or model selection changed.",
1973+
: command.type === "thread.metadata.update"
1974+
? "Workspace changed."
1975+
: command.type === "thread.runtime-mode.set"
1976+
? "Runtime mode changed."
1977+
: "Provider or model selection changed.",
19841978
// Terminal detaches revoke the thread's MCP credentials; other
19851979
// detach reasons keep them so a re-attaching provider process
19861980
// stays authorized.
1987-
...(command.type === "thread.archive" || command.type === "thread.delete"
1988-
? { revokeMcpCredential: true }
1989-
: {}),
1981+
...(command.type === "thread.archive" ? { revokeMcpCredential: true } : {}),
19901982
},
19911983
} satisfies PendingOrchestrationEffectV2;
19921984
yield* Ref.update(effects, (existing) => [...existing, pendingEffect]);
@@ -1995,7 +1987,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
19951987
);
19961988
}
19971989

1998-
if (command.type === "thread.archive" || command.type === "thread.delete") {
1990+
if (command.type === "thread.archive") {
19991991
yield* Ref.update(effects, (existing) => [
20001992
...existing,
20011993
{

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import {
1818
ProviderSessionId,
1919
ProviderThreadId,
2020
RunId,
21-
RuntimeRequestId,
2221
ThreadId,
2322
} from "@t3tools/contracts";
2423
import * as Effect from "effect/Effect";
2524
import * as DateTime from "effect/DateTime";
2625
import * as Deferred from "effect/Deferred";
2726
import * as Fiber from "effect/Fiber";
27+
import * as FileSystem from "effect/FileSystem";
2828
import * as Layer from "effect/Layer";
2929
import * as Option from "effect/Option";
3030
import * as Queue from "effect/Queue";
@@ -909,7 +909,7 @@ it.layer(LegacyImportTestLayer)("OrchestrationV2 legacy import", (it) => {
909909
);
910910
});
911911

912-
it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
912+
it.layer(Layer.merge(TestLayer, NodeServices.layer))("OrchestrationV2LayerLive lifecycle", (it) => {
913913
it.effect("applies lifecycle commands idempotently and emits archive/removal shell deltas", () =>
914914
Effect.gen(function* () {
915915
const orchestrator = yield* OrchestratorV2;
@@ -1414,6 +1414,10 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
14141414

14151415
it.effect("applies deferred settlement after safe completion and replays its receipt", () =>
14161416
Effect.gen(function* () {
1417+
const fileSystem = yield* FileSystem.FileSystem;
1418+
const workspacePath = yield* fileSystem.makeTempDirectoryScoped({
1419+
prefix: "t3-runtime-layer-deferred-settle-",
1420+
});
14171421
const orchestrator = yield* OrchestratorV2;
14181422
const eventSink = yield* EventSinkV2;
14191423
const sql = yield* SqlClient.SqlClient;
@@ -1434,7 +1438,7 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
14341438
runtimeMode: "full-access",
14351439
interactionMode: "default",
14361440
branch: null,
1437-
worktreePath: "/tmp/runtime-layer-deferred-settle",
1441+
worktreePath: workspacePath,
14381442
});
14391443
yield* orchestrator.dispatch({
14401444
type: "thread.pin",
@@ -1465,7 +1469,7 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
14651469
providerSessionId,
14661470
modelSelection,
14671471
runtimePolicy: {
1468-
cwd: "/tmp/runtime-layer-deferred-settle",
1472+
cwd: workspacePath,
14691473
runtimeMode: "full-access",
14701474
interactionMode: "default",
14711475
},
@@ -1571,6 +1575,10 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
15711575

15721576
it.effect("archives after safe completion and discards stale or blocked deferred intents", () =>
15731577
Effect.gen(function* () {
1578+
const fileSystem = yield* FileSystem.FileSystem;
1579+
const workspacePath = yield* fileSystem.makeTempDirectoryScoped({
1580+
prefix: "t3-runtime-layer-deferred-organization-",
1581+
});
15741582
const orchestrator = yield* OrchestratorV2;
15751583
const eventSink = yield* EventSinkV2;
15761584
const sql = yield* SqlClient.SqlClient;
@@ -1592,7 +1600,7 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
15921600
runtimeMode: "full-access",
15931601
interactionMode: "default",
15941602
branch: null,
1595-
worktreePath: `/tmp/runtime-layer-deferred-${suffix}`,
1603+
worktreePath: workspacePath,
15961604
});
15971605
yield* orchestrator.dispatch({
15981606
type: "message.dispatch",
@@ -1656,7 +1664,7 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
16561664
providerSessionId,
16571665
modelSelection,
16581666
runtimePolicy: {
1659-
cwd: "/tmp/runtime-layer-deferred-archive",
1667+
cwd: workspacePath,
16601668
runtimeMode: "full-access",
16611669
interactionMode: "default",
16621670
},

‎apps/server/src/orchestration-v2/testkit/ProviderReplayHarness.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ export function makeOrchestratorV2ReplayLayerWithRegistry<Error>(
427427
Layer.provide(
428428
Layer.mergeAll(effectWorkerProvided, storesLayer, eventSinkProvided, idAllocatorLayer),
429429
),
430+
Layer.provide(serverSettingsLayer),
430431
);
431432
const replayRuntime = Layer.mergeAll(
432433
orchestratorProvided,

0 commit comments

Comments
 (0)