Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/closura-arc-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ jobs:
apps/server/src/peer/RemoteDelegation.test.ts \
apps/server/src/mcp/OrchestratorMcpService.test.ts \
apps/server/src/cli/thread.test.ts \
apps/web/src/composerDraftStore.test.ts
apps/web/src/composerDraftStore.test.ts \
apps/web/src/components/chat/composerSend.logic.test.ts \
apps/web/src/components/chat/chatViewSend.test.ts \
apps/web/src/components/chat/composerImagePersistence.test.ts

- name: Build native T3 server
shell: bash
Expand Down
57 changes: 56 additions & 1 deletion apps/server/src/orchestration-v2/ThreadLaunchService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts";
import * as ThreadLaunch from "./ThreadLaunchService.ts";
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
import * as ThreadManagement from "./ThreadManagementService.ts";
import { OrchestratorProjectionError } from "./Orchestrator.ts";
import * as ThreadTitleRegeneration from "./ThreadTitleRegenerationService.ts";
import * as ProviderReplayHarness from "./testkit/ProviderReplayHarness.ts";
import * as RemoteDelegation from "../peer/RemoteDelegation.ts";
Expand Down Expand Up @@ -138,6 +139,10 @@ interface HarnessOptions {
readonly getLaunchSettings?: ServerSettings.ServerSettingsService["Service"]["getSettings"];
readonly providers?: ReadonlyArray<ServerProvider>;
readonly git?: Partial<GitWorkflow.GitWorkflowService["Service"]>;
/** Replaces methods of the thread service the launch uses, around the real one. */
readonly threads?: (
threads: ThreadManagement.ThreadManagementService["Service"],
) => Partial<ThreadManagement.ThreadManagementService["Service"]>;
readonly isGitRepository?: CheckpointStore.CheckpointStore["Service"]["isGitRepository"];
}

Expand Down Expand Up @@ -247,11 +252,22 @@ function makeHarness(options: HarnessOptions = {}) {
folderForThread: () => Effect.succeedNone,
}),
);
const wrapThreads = options.threads;
const layerLaunchThreads =
wrapThreads === undefined
? layerThreadManagement
: Layer.effect(
ThreadManagement.ThreadManagementService,
Effect.gen(function* () {
const threads = yield* ThreadManagement.ThreadManagementService;
return { ...threads, ...wrapThreads(threads) };
}),
).pipe(Layer.provide(layerThreadManagement));
const layerLaunch = ThreadLaunch.layer.pipe(
Layer.provide(
Layer.mergeAll(
layerExternalServices,
layerThreadManagement,
layerLaunchThreads,
layerReceipts,
layerOrchestrator,
IdAllocator.layer,
Expand Down Expand Up @@ -2000,6 +2016,45 @@ it.effect("replays a server-allocated launch", () =>
}),
);

// A launch can fail after its claim committed the thread, its message and its run: the caller
// gets a launch error for a launch that exists, so only the same command can settle it.
it.effect("a launch that fails after its claim committed is recovered by the same command", () =>
Effect.gen(function* () {
let failedReads = 0;
const harness = makeHarness({
threads: (threads) => ({
getThreadProjection: (threadId) =>
failedReads++ === 0
? Effect.fail(new OrchestratorProjectionError({ threadId }))
: threads.getThreadProjection(threadId),
}),
});
yield* Effect.gen(function* () {
const launches = yield* ThreadLaunch.ThreadLaunchService;
const threads = yield* ThreadManagement.ThreadManagementService;
const input = launchInput({
command: "command:launch:fails-after-claim",
thread: "thread:fails-after-claim",
message: "Run the suite",
});
const failed = yield* launches.launch(input).pipe(Effect.flip);
assert.equal(failed._tag, "ThreadLaunchError");
// The launch it reported as failed was accepted: its thread, message and run exist.
const accepted = yield* threads.getThreadProjection(input.threadId);
assert.equal(accepted.messages.length, 1);
assert.equal(accepted.runs.length, 1);
// The same command returns that launch; it starts nothing new.
const retried = yield* launches.launch(input);
assert.isTrue(retried.resumed);
assert.equal(retried.threadId, input.threadId);
assert.equal(retried.projection.messages.length, 1);
assert.equal(retried.projection.messages[0]?.id, accepted.messages[0]?.id);
assert.equal(retried.projection.runs.length, 1);
assert.equal(retried.projection.runs[0]?.id, accepted.runs[0]?.id);
}).pipe(Effect.provide(harness.layer));
}),
);

it.effect("replays an accepted launch after the project disables the instance", () => {
const harness = makeHarness();
return Effect.gen(function* () {
Expand Down
Loading
Loading