Align orchestration V2 with Effect service conventions

This commit is contained in:
Julius Marminge authored and Julius Marminge committed 2026-08-14 11:22:52 +02:00
1 parent 27da49519f
commit 63f2e161e7
23 files changed
+370 -321

No files matched your search

+4 -4
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env node
// @effect-diagnostics nodeBuiltinImport:off
import { writeFileSync } from "node:fs";
import { createInterface } from "node:readline";
import * as NodeFS from "node:fs";
import * as NodeReadline from "node:readline";
interface ReplayEntry {
readonly type: "emit_inbound" | "expect_outbound" | "runtime_exit";
@@ -54,7 +54,7 @@ const pendingClientRequestIds = new Map<string, string | number>();
const pendingAgentRequestMethods = new Map<string, string>();
function writeStatus(failure?: unknown): void {
writeFileSync(
NodeFS.writeFileSync(
replayStatusPath,
JSON.stringify({
scenario: transcript.scenario,
@@ -268,7 +268,7 @@ function handleMessage(message: JsonRpcMessage): void {
writeStatus();
flushInbound();
const input = createInterface({ input: process.stdin, crlfDelay: Infinity });
const input = NodeReadline.createInterface({ input: process.stdin, crlfDelay: Infinity });
input.on("line", (line) => {
if (stopped || line.trim().length === 0) return;
try {
@@ -1067,7 +1067,7 @@ function installReplayHandlers({
startCommandExecution,
beforeApprovalResponse,
}: {
readonly client: CodexClient.CodexAppServerClientShape;
readonly client: CodexClient.CodexAppServerClient["Service"];
readonly startTurn: (turnId: string) => Effect.Effect<void>;
readonly completeTurn: (turnId: string) => Effect.Effect<void>;
readonly startCommandExecution: (turnId: string) => Effect.Effect<void>;
@@ -1222,7 +1222,7 @@ function runReplaySession({
});
const runTurnStep = (
client: CodexClient.CodexAppServerClientShape,
client: CodexClient.CodexAppServerClient["Service"],
threadId: string,
step: TurnReplayStep,
) =>
@@ -15,7 +15,7 @@ import * as Layer from "effect/Layer";
import { FetchHttpClient } from "effect/unstable/http";
import { describe } from "vite-plus/test";
import { CheckpointStoreLive } from "../checkpointing/Layers/CheckpointStore.ts";
import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
import { ServerConfig } from "../config.ts";
import { SqlitePersistenceMemory } from "../persistence/Layers/Sqlite.ts";
import { ProviderInstanceRegistryHydrationLive } from "../provider/Layers/ProviderInstanceRegistryHydration.ts";
@@ -48,7 +48,7 @@ const vcsDriverRegistryLayer = VcsDriverRegistry.layer.pipe(
Layer.provide(NodeServices.layer),
);
const checkpointStoreLayer = CheckpointStoreLive.pipe(Layer.provide(vcsDriverRegistryLayer));
const checkpointStoreLayer = CheckpointStore.layer.pipe(Layer.provide(vcsDriverRegistryLayer));
const serverSettingsLayer = ServerSettingsService.layerTest({
providerInstances: {
@@ -24,7 +24,7 @@ import * as TestClock from "effect/testing/TestClock";
import { ChildProcessSpawner } from "effect/unstable/process";
import { ServerConfig } from "../../config.ts";
import { AcpSessionRuntime } from "../../provider/acp/AcpSessionRuntime.ts";
import * as AcpSessionRuntime from "../../provider/acp/AcpSessionRuntime.ts";
import { layer as idAllocatorLayer, IdAllocatorV2 } from "../IdAllocator.ts";
import {
ProviderAdapterV2RuntimePolicy,
@@ -66,7 +66,9 @@ function makeMockRuntime(input: {
),
),
);
return yield* Effect.service(AcpSessionRuntime).pipe(Effect.provide(context));
return yield* Effect.service(AcpSessionRuntime.AcpSessionRuntime).pipe(
Effect.provide(context),
);
});
}
@@ -11,10 +11,7 @@ import type * as Scope from "effect/Scope";
import { ChildProcessSpawner } from "effect/unstable/process";
import * as EffectAcpErrors from "effect-acp/errors";
import {
AcpSessionRuntime,
type AcpSessionRuntimeShape,
} from "../../provider/acp/AcpSessionRuntime.ts";
import * as AcpSessionRuntime from "../../provider/acp/AcpSessionRuntime.ts";
import { ACP_PROTOCOL, type AcpAdapterV2RuntimeInput } from "./AcpAdapterV2.ts";
export const AcpReplayTranscript = Schema.Struct({
@@ -155,7 +152,11 @@ export function makeAcpReplayRuntime(input: {
readonly childProcessSpawner: ChildProcessSpawner.ChildProcessSpawner["Service"];
}): (
runtimeInput: AcpAdapterV2RuntimeInput,
) => Effect.Effect<AcpSessionRuntimeShape, EffectAcpErrors.AcpError, Scope.Scope> {
) => Effect.Effect<
AcpSessionRuntime.AcpSessionRuntime["Service"],
EffectAcpErrors.AcpError,
Scope.Scope
> {
const encodedTranscript = Buffer.from(JSON.stringify(input.transcript), "utf8").toString(
"base64",
);
@@ -182,6 +183,8 @@ export function makeAcpReplayRuntime(input: {
),
),
);
return yield* Effect.service(AcpSessionRuntime).pipe(Effect.provide(context));
return yield* Effect.service(AcpSessionRuntime.AcpSessionRuntime).pipe(
Effect.provide(context),
);
});
}
@@ -35,7 +35,7 @@ import type * as EffectAcpProtocol from "effect-acp/protocol";
import type * as EffectAcpSchema from "effect-acp/schema";
import { resolveAttachmentPath } from "../../attachmentStore.ts";
import { type ServerConfigShape } from "../../config.ts";
import { ServerConfig } from "../../config.ts";
import * as McpProviderSession from "../../mcp/McpProviderSession.ts";
import {
mergeToolCallState,
@@ -46,9 +46,9 @@ import {
} from "../../provider/acp/AcpRuntimeModel.ts";
import type {
AcpSessionRuntimeOptions,
AcpSessionRuntimeShape,
AcpSessionRuntimeStartResult,
} from "../../provider/acp/AcpSessionRuntime.ts";
import * as AcpSessionRuntime from "../../provider/acp/AcpSessionRuntime.ts";
import { IdAllocatorV2, type IdAllocatorV2Shape } from "../IdAllocator.ts";
import {
ProviderAdapterEnsureThreadError,
@@ -90,7 +90,7 @@ export interface AcpAdapterV2UserInputRequest {
}
export interface AcpAdapterV2ExtensionContext {
readonly runtime: AcpSessionRuntimeShape;
readonly runtime: AcpSessionRuntime.AcpSessionRuntime["Service"];
readonly requestUserInput: (
input: AcpAdapterV2UserInputRequest,
) => Effect.Effect<ProviderUserInputAnswers | null, EffectAcpErrors.AcpError>;
@@ -101,7 +101,11 @@ export interface AcpAdapterV2Flavor {
readonly capabilities: OrchestrationV2ProviderCapabilities;
readonly makeRuntime: (
input: AcpAdapterV2RuntimeInput,
) => Effect.Effect<AcpSessionRuntimeShape, EffectAcpErrors.AcpError, Scope.Scope>;
) => Effect.Effect<
AcpSessionRuntime.AcpSessionRuntime["Service"],
EffectAcpErrors.AcpError,
Scope.Scope
>;
readonly resolveModelId?: (selection: ModelSelection) => string | undefined;
readonly registerExtensions?: (
context: AcpAdapterV2ExtensionContext,
@@ -114,7 +118,7 @@ export interface AcpAdapterV2Options {
readonly flavor: AcpAdapterV2Flavor;
readonly fileSystem: FileSystem.FileSystem;
readonly idAllocator: IdAllocatorV2Shape;
readonly serverConfig: ServerConfigShape;
readonly serverConfig: ServerConfig["Service"];
}
export const AcpProviderCapabilitiesV2 = {
@@ -19,10 +19,7 @@ import {
makeAcpRegistryResolver,
type AcpRegistryResolverShape,
} from "../../provider/acp/AcpRegistrySupport.ts";
import {
AcpSessionRuntime,
type AcpSessionRuntimeShape,
} from "../../provider/acp/AcpSessionRuntime.ts";
import * as AcpSessionRuntime from "../../provider/acp/AcpSessionRuntime.ts";
import { mergeProviderInstanceEnvironment } from "../../provider/ProviderInstanceEnvironment.ts";
import { IdAllocatorV2 } from "../IdAllocator.ts";
import {
@@ -55,14 +52,22 @@ export interface AcpRegistryAdapterV2Options {
readonly serverConfig: ServerConfig["Service"];
readonly makeRuntime?: (
input: AcpAdapterV2RuntimeInput,
) => Effect.Effect<AcpSessionRuntimeShape, EffectAcpErrors.AcpError, Scope.Scope>;
) => Effect.Effect<
AcpSessionRuntime.AcpSessionRuntime["Service"],
EffectAcpErrors.AcpError,
Scope.Scope
>;
readonly assertComplete?: Effect.Effect<void, EffectAcpErrors.AcpError>;
}
function makeAcpRegistryRuntime(options: AcpRegistryAdapterV2Options) {
return (
input: AcpAdapterV2RuntimeInput,
): Effect.Effect<AcpSessionRuntimeShape, EffectAcpErrors.AcpError, Scope.Scope> =>
): Effect.Effect<
AcpSessionRuntime.AcpSessionRuntime["Service"],
EffectAcpErrors.AcpError,
Scope.Scope
> =>
Effect.gen(function* () {
const resolved = yield* options.resolver
.resolve(options.settings, input.cwd, options.environment)
@@ -86,7 +91,9 @@ function makeAcpRegistryRuntime(options: AcpRegistryAdapterV2Options) {
),
),
);
return yield* Effect.service(AcpSessionRuntime).pipe(Effect.provide(context));
return yield* Effect.service(AcpSessionRuntime.AcpSessionRuntime).pipe(
Effect.provide(context),
);
});
}
@@ -9,7 +9,7 @@ import * as Path from "effect/Path";
import * as PlatformError from "effect/PlatformError";
import * as Schema from "effect/Schema";
import { ServerConfig, type ServerConfigShape } from "../../config.ts";
import { ServerConfig } from "../../config.ts";
import { layer as idAllocatorLayer } from "../IdAllocator.ts";
import { ProviderAdapterOpenSessionError } from "../ProviderAdapter.ts";
import { layerFromProviderAdapter } from "../ProviderAdapterRegistry.ts";
@@ -51,7 +51,7 @@ function metadataFromTranscript(transcript: ProviderReplayTranscript): {
function makeReplayServerConfig(
scenario: string,
): Effect.Effect<
ServerConfigShape,
ServerConfig["Service"],
PlatformError.PlatformError,
FileSystem.FileSystem | Path.Path
> {
@@ -41,7 +41,11 @@ import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
import { resolveAttachmentPath } from "../../attachmentStore.ts";
import { ServerConfig } from "../../config.ts";
import { CODEX_PLAN_MODE_DEVELOPER_INSTRUCTIONS } from "../../provider/codex/CodexDeveloperInstructions.ts";
import { CODEX_PLAN_MODE_DEVELOPER_INSTRUCTIONS } from "../../provider/CodexDeveloperInstructions.ts";
import {
materializeCodexShadowHome,
resolveCodexHomeLayout,
} from "../../provider/Drivers/CodexHomeLayout.ts";
import {
type EventNdjsonLogger,
makeEventNdjsonLogger,
@@ -758,7 +762,7 @@ export interface CodexAppServerClientFactoryShape {
readonly providerSessionId: OrchestrationV2ProviderSession["id"];
readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
}) => Effect.Effect<
CodexClient.CodexAppServerClientShape,
CodexClient.CodexAppServerClient["Service"],
ProviderAdapterOpenSessionError,
Scope.Scope
>;
@@ -1056,7 +1060,7 @@ export interface CodexAdapterV2Options {
readonly clientFactory: CodexAppServerClientFactoryShape;
readonly fileSystem: FileSystem.FileSystem;
readonly idAllocator: IdAllocatorV2Shape;
readonly serverConfig: ServerConfigShape;
readonly serverConfig: ServerConfig["Service"];
}
export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): ProviderAdapterV2Shape {
@@ -13,7 +13,7 @@ import * as Path from "effect/Path";
import * as PlatformError from "effect/PlatformError";
import * as Schema from "effect/Schema";
import { ServerConfig, type ServerConfigShape } from "../../config.ts";
import { ServerConfig } from "../../config.ts";
import { layer as idAllocatorLayer } from "../IdAllocator.ts";
import { ProviderAdapterDriverCreateError } from "../ProviderAdapterDriver.ts";
import { makeDriverLayer as makeProviderAdapterRegistryDriverLayer } from "../ProviderAdapterRegistry.ts";
@@ -508,7 +508,7 @@ export function makeCursorAgentSdkReplayLayer(
function makeReplayServerConfig(
scenario: string,
): Effect.Effect<
ServerConfigShape,
ServerConfig["Service"],
PlatformError.PlatformError,
FileSystem.FileSystem | Path.Path
> {
@@ -39,7 +39,7 @@ import * as Schema from "effect/Schema";
import * as Stream from "effect/Stream";
import { resolveAttachmentPath } from "../../attachmentStore.ts";
import { ServerConfig, type ServerConfigShape } from "../../config.ts";
import { ServerConfig } from "../../config.ts";
import * as McpProviderSession from "../../mcp/McpProviderSession.ts";
import { cursorSdkParameterId } from "../../provider/cursorSdkModel.ts";
import { mergeProviderInstanceEnvironment } from "../../provider/ProviderInstanceEnvironment.ts";
@@ -818,7 +818,7 @@ export interface CursorAdapterV2Options {
readonly fileSystem: FileSystem.FileSystem;
readonly idAllocator: IdAllocatorV2Shape;
readonly runner: CursorAgentSdkRunnerShape;
readonly serverConfig: ServerConfigShape;
readonly serverConfig: ServerConfig["Service"];
}
export function makeCursorAdapterV2(
@@ -26,7 +26,7 @@ import {
XAiAskUserQuestionRequest,
} from "../../provider/acp/XAiAcpExtension.ts";
import { mergeProviderInstanceEnvironment } from "../../provider/ProviderInstanceEnvironment.ts";
import type { AcpSessionRuntimeShape } from "../../provider/acp/AcpSessionRuntime.ts";
import * as AcpSessionRuntime from "../../provider/acp/AcpSessionRuntime.ts";
import { IdAllocatorV2 } from "../IdAllocator.ts";
import { ProviderAdapterV2 } from "../ProviderAdapter.ts";
import {
@@ -83,7 +83,11 @@ export interface GrokAdapterV2Options {
readonly serverConfig: ServerConfig["Service"];
readonly makeRuntime?: (
input: AcpAdapterV2RuntimeInput,
) => Effect.Effect<AcpSessionRuntimeShape, EffectAcpErrors.AcpError, Scope.Scope>;
) => Effect.Effect<
AcpSessionRuntime.AcpSessionRuntime["Service"],
EffectAcpErrors.AcpError,
Scope.Scope
>;
readonly assertComplete?: Effect.Effect<void, EffectAcpErrors.AcpError>;
}
@@ -49,7 +49,7 @@ import * as Scope from "effect/Scope";
import * as Stream from "effect/Stream";
import { resolveAttachmentPath } from "../../attachmentStore.ts";
import { ServerConfig, type ServerConfigShape } from "../../config.ts";
import { ServerConfig } from "../../config.ts";
import * as McpProviderSession from "../../mcp/McpProviderSession.ts";
import { mergeProviderInstanceEnvironment } from "../../provider/ProviderInstanceEnvironment.ts";
import {
@@ -271,7 +271,7 @@ export interface OpenCodeAdapterV2Options {
readonly environment: NodeJS.ProcessEnv;
readonly runtime: OpenCodeRuntimeShape;
readonly idAllocator: IdAllocatorV2Shape;
readonly serverConfig: ServerConfigShape;
readonly serverConfig: ServerConfig["Service"];
}
function protocolError(detail: string, payload?: unknown): ProviderAdapterProtocolError {
@@ -9,6 +9,7 @@ import {
RunId,
ThreadId,
} from "@t3tools/contracts";
import * as NodeCrypto from "node:crypto";
import * as Context from "effect/Context";
import * as DateTime from "effect/DateTime";
import * as Effect from "effect/Effect";
@@ -19,7 +20,7 @@ import * as Schema from "effect/Schema";
import * as Semaphore from "effect/Semaphore";
import { parseTurnDiffFilesFromUnifiedDiff } from "../checkpointing/Diffs.ts";
import { CheckpointStore } from "../checkpointing/Services/CheckpointStore.ts";
import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
import { IdAllocatorV2, type IdAllocatorV2Shape } from "./IdAllocator.ts";
const CHECKPOINT_REFS_PREFIX = "refs/t3/orchestration-v2/checkpoints";
@@ -30,7 +31,7 @@ export class CheckpointRootScopePrepareError extends Schema.TaggedErrorClass<Che
{
threadId: ThreadId,
runId: RunId,
cause: Schema.optional(Schema.Defect()),
cause: Schema.Defect(),
},
) {
override get message(): string {
@@ -42,7 +43,7 @@ export class CheckpointScopeEnsureError extends Schema.TaggedErrorClass<Checkpoi
"CheckpointScopeEnsureError",
{
scopeId: CheckpointScopeId,
cause: Schema.optional(Schema.Defect()),
cause: Schema.Defect(),
},
) {
override get message(): string {
@@ -55,7 +56,7 @@ export class CheckpointBaselineCaptureError extends Schema.TaggedErrorClass<Chec
{
scopeId: CheckpointScopeId,
ordinalWithinScope: Schema.Number,
cause: Schema.optional(Schema.Defect()),
cause: Schema.Defect(),
},
) {
override get message(): string {
@@ -68,7 +69,7 @@ export class CheckpointCaptureError extends Schema.TaggedErrorClass<CheckpointCa
{
scopeId: CheckpointScopeId,
parentCheckpointId: Schema.optional(CheckpointId),
cause: Schema.optional(Schema.Defect()),
cause: Schema.Defect(),
},
) {
override get message(): string {
@@ -81,7 +82,7 @@ export class CheckpointRestoreError extends Schema.TaggedErrorClass<CheckpointRe
{
scopeId: CheckpointScopeId,
checkpointId: CheckpointId,
cause: Schema.optional(Schema.Defect()),
cause: Schema.Defect(),
},
) {
override get message(): string {
@@ -94,7 +95,7 @@ export class CheckpointDeleteStaleRefsError extends Schema.TaggedErrorClass<Chec
{
scopeId: CheckpointScopeId,
checkpointIds: Schema.Array(CheckpointId),
cause: Schema.optional(Schema.Defect()),
cause: Schema.Defect(),
},
) {
override get message(): string {
@@ -112,6 +113,8 @@ export const CheckpointServiceV2Error = Schema.Union([
]);
export type CheckpointServiceV2Error = typeof CheckpointServiceV2Error.Type;
const isCheckpointRestoreError = Schema.is(CheckpointRestoreError);
export interface CheckpointServiceV2Shape {
readonly prepareRootRunScope: (input: {
readonly threadId: ThreadId;
@@ -155,7 +158,7 @@ function checkpointRefForScopeOrdinal(input: {
readonly scopeId: CheckpointScopeId;
readonly ordinalWithinScope: number;
}): CheckpointRef {
const scopeKey = createHash("sha256").update(input.scopeId).digest("hex").slice(0, 32);
const scopeKey = NodeCrypto.createHash("sha256").update(input.scopeId).digest("hex").slice(0, 32);
return CheckpointRef.make(
`${CHECKPOINT_REFS_PREFIX}/${Encoding.encodeBase64Url(scopeKey)}/ordinal/${input.ordinalWithinScope}`,
);
@@ -233,180 +236,105 @@ function makeCheckpoint(input: {
};
}
export const layer: Layer.Layer<CheckpointServiceV2, never, CheckpointStore | IdAllocatorV2> =
Layer.effect(
CheckpointServiceV2,
Effect.gen(function* () {
const checkpointStore = yield* CheckpointStore;
const idAllocator = yield* IdAllocatorV2;
const workspaceSemaphores = yield* Ref.make(new Map<string, Semaphore.Semaphore>());
export const layer: Layer.Layer<
CheckpointServiceV2,
never,
CheckpointStore.CheckpointStore | IdAllocatorV2
> = Layer.effect(
CheckpointServiceV2,
Effect.gen(function* () {
const checkpointStore = yield* CheckpointStore.CheckpointStore;
const idAllocator = yield* IdAllocatorV2;
const workspaceSemaphores = yield* Ref.make(new Map<string, Semaphore.Semaphore>());
const getWorkspaceSemaphore = (cwd: string) =>
const getWorkspaceSemaphore = (cwd: string) =>
Effect.gen(function* () {
const existing = (yield* Ref.get(workspaceSemaphores)).get(cwd);
if (existing !== undefined) {
return existing;
}
const created = yield* Semaphore.make(1);
return yield* Ref.modify(workspaceSemaphores, (current) => {
const concurrent = current.get(cwd);
if (concurrent !== undefined) {
return [concurrent, current];
}
const updated = new Map(current);
updated.set(cwd, created);
return [created, updated];
});
});
const withWorkspaceLock = <A, E, R>(cwd: string, effect: Effect.Effect<A, E, R>) =>
Effect.flatMap(getWorkspaceSemaphore(cwd), (semaphore) => semaphore.withPermits(1)(effect));
const isGitCheckpointable = (cwd: string) =>
checkpointStore.isGitRepository(cwd).pipe(Effect.orElseSucceed(() => false));
const ensureScope: CheckpointServiceV2Shape["ensureScope"] = (scope) => Effect.succeed(scope);
const captureBaseline: CheckpointServiceV2Shape["captureBaseline"] = (input) =>
withWorkspaceLock(
input.scope.cwd,
Effect.gen(function* () {
const existing = (yield* Ref.get(workspaceSemaphores)).get(cwd);
if (existing !== undefined) {
return existing;
if (!(yield* isGitCheckpointable(input.scope.cwd))) {
return;
}
const created = yield* Semaphore.make(1);
return yield* Ref.modify(workspaceSemaphores, (current) => {
const concurrent = current.get(cwd);
if (concurrent !== undefined) {
return [concurrent, current];
}
const updated = new Map(current);
updated.set(cwd, created);
return [created, updated];
const checkpointRef = checkpointRefForScopeOrdinal({
scopeId: input.scope.id,
ordinalWithinScope: input.ordinalWithinScope,
});
});
const exists = yield* checkpointStore.hasCheckpointRef({
cwd: input.scope.cwd,
checkpointRef,
});
if (exists) {
return;
}
const withWorkspaceLock = <A, E, R>(cwd: string, effect: Effect.Effect<A, E, R>) =>
Effect.flatMap(getWorkspaceSemaphore(cwd), (semaphore) => semaphore.withPermits(1)(effect));
const isGitCheckpointable = (cwd: string) =>
checkpointStore.isGitRepository(cwd).pipe(Effect.orElseSucceed(() => false));
const ensureScope: CheckpointServiceV2Shape["ensureScope"] = (scope) => Effect.succeed(scope);
const captureBaseline: CheckpointServiceV2Shape["captureBaseline"] = (input) =>
withWorkspaceLock(
input.scope.cwd,
Effect.gen(function* () {
if (!(yield* isGitCheckpointable(input.scope.cwd))) {
return;
}
const checkpointRef = checkpointRefForScopeOrdinal({
yield* checkpointStore.captureCheckpoint({
cwd: input.scope.cwd,
checkpointRef,
});
}),
).pipe(
Effect.mapError(
(cause) =>
new CheckpointBaselineCaptureError({
scopeId: input.scope.id,
ordinalWithinScope: input.ordinalWithinScope,
});
const exists = yield* checkpointStore.hasCheckpointRef({
cwd: input.scope.cwd,
checkpointRef,
});
if (exists) {
return;
}
cause,
}),
),
);
yield* checkpointStore.captureCheckpoint({
cwd: input.scope.cwd,
checkpointRef,
});
}),
).pipe(
Effect.mapError(
(cause) =>
new CheckpointBaselineCaptureError({
scopeId: input.scope.id,
ordinalWithinScope: input.ordinalWithinScope,
cause,
}),
),
);
const capture: CheckpointServiceV2Shape["capture"] = (input) =>
withWorkspaceLock(
input.scope.cwd,
Effect.gen(function* () {
const checkpointId = yield* checkpointIdForScopeOrdinal(idAllocator, {
scopeId: input.scope.id,
ordinalWithinScope: input.ordinalWithinScope,
});
const parentCheckpointId =
input.ordinalWithinScope > 1
? yield* checkpointIdForScopeOrdinal(idAllocator, {
scopeId: input.scope.id,
ordinalWithinScope: input.ordinalWithinScope - 1,
})
: null;
const checkpointRef = checkpointRefForScopeOrdinal({
scopeId: input.scope.id,
ordinalWithinScope: input.ordinalWithinScope,
});
const previousCheckpointRef = checkpointRefForScopeOrdinal({
scopeId: input.scope.id,
ordinalWithinScope: Math.max(0, input.ordinalWithinScope - 1),
});
if (!(yield* isGitCheckpointable(input.scope.cwd))) {
return makeCheckpoint({
id: checkpointId,
scope: input.scope,
runId: input.runId,
nodeId: input.nodeId,
parentCheckpointId,
ordinalWithinScope: input.ordinalWithinScope,
appRunOrdinal: input.appRunOrdinal,
ref: checkpointRef,
status: "missing",
files: [],
capturedAt: input.capturedAt,
});
}
const captured = yield* checkpointStore
.captureCheckpoint({
cwd: input.scope.cwd,
checkpointRef,
})
.pipe(
Effect.as(true),
Effect.catch((cause) =>
Effect.logWarning("orchestration V2 checkpoint capture failed", {
scopeId: input.scope.id,
checkpointRef,
cause: String(cause),
}).pipe(Effect.as(false)),
),
);
if (!captured) {
return makeCheckpoint({
id: checkpointId,
scope: input.scope,
runId: input.runId,
nodeId: input.nodeId,
parentCheckpointId,
ordinalWithinScope: input.ordinalWithinScope,
appRunOrdinal: input.appRunOrdinal,
ref: checkpointRef,
status: "error",
files: [],
capturedAt: input.capturedAt,
});
}
const previousExists = yield* checkpointStore.hasCheckpointRef({
cwd: input.scope.cwd,
checkpointRef: previousCheckpointRef,
});
const files = previousExists
? yield* checkpointStore
.diffCheckpoints({
cwd: input.scope.cwd,
fromCheckpointRef: previousCheckpointRef,
toCheckpointRef: checkpointRef,
fallbackFromToHead: false,
})
.pipe(
Effect.map((diff) =>
parseTurnDiffFilesFromUnifiedDiff(diff).map((file) => ({
path: file.path,
kind: "modified",
additions: file.additions,
deletions: file.deletions,
})),
),
Effect.catch((cause) =>
Effect.logWarning("orchestration V2 checkpoint diff summary failed", {
scopeId: input.scope.id,
checkpointRef,
cause: String(cause),
}).pipe(Effect.as([])),
),
)
: [];
const capture: CheckpointServiceV2Shape["capture"] = (input) =>
withWorkspaceLock(
input.scope.cwd,
Effect.gen(function* () {
const checkpointId = yield* checkpointIdForScopeOrdinal(idAllocator, {
scopeId: input.scope.id,
ordinalWithinScope: input.ordinalWithinScope,
});
const parentCheckpointId =
input.ordinalWithinScope > 1
? yield* checkpointIdForScopeOrdinal(idAllocator, {
scopeId: input.scope.id,
ordinalWithinScope: input.ordinalWithinScope - 1,
})
: null;
const checkpointRef = checkpointRefForScopeOrdinal({
scopeId: input.scope.id,
ordinalWithinScope: input.ordinalWithinScope,
});
const previousCheckpointRef = checkpointRefForScopeOrdinal({
scopeId: input.scope.id,
ordinalWithinScope: Math.max(0, input.ordinalWithinScope - 1),
});
if (!(yield* isGitCheckpointable(input.scope.cwd))) {
return makeCheckpoint({
id: checkpointId,
scope: input.scope,
@@ -416,94 +344,172 @@ export const layer: Layer.Layer<CheckpointServiceV2, never, CheckpointStore | Id
ordinalWithinScope: input.ordinalWithinScope,
appRunOrdinal: input.appRunOrdinal,
ref: checkpointRef,
status: "ready",
files,
status: "missing",
files: [],
capturedAt: input.capturedAt,
});
}),
).pipe(
Effect.mapError(
(cause) =>
new CheckpointCaptureError({
scopeId: input.scope.id,
cause,
}),
),
);
}
const restore: CheckpointServiceV2Shape["restore"] = (input) =>
withWorkspaceLock(
input.scope.cwd,
Effect.gen(function* () {
if (input.checkpoint.status !== "ready") {
return yield* new CheckpointRestoreError({
scopeId: input.scope.id,
checkpointId: input.checkpoint.id,
cause: `Checkpoint status is ${input.checkpoint.status}.`,
});
}
const restored = yield* checkpointStore.restoreCheckpoint({
const captured = yield* checkpointStore
.captureCheckpoint({
cwd: input.scope.cwd,
checkpointRef: input.checkpoint.ref,
fallbackToHead: false,
checkpointRef,
})
.pipe(
Effect.as(true),
Effect.catch((cause) =>
Effect.logWarning("orchestration V2 checkpoint capture failed", {
scopeId: input.scope.id,
checkpointRef,
cause: String(cause),
}).pipe(Effect.as(false)),
),
);
if (!captured) {
return makeCheckpoint({
id: checkpointId,
scope: input.scope,
runId: input.runId,
nodeId: input.nodeId,
parentCheckpointId,
ordinalWithinScope: input.ordinalWithinScope,
appRunOrdinal: input.appRunOrdinal,
ref: checkpointRef,
status: "error",
files: [],
capturedAt: input.capturedAt,
});
if (!restored) {
return yield* new CheckpointRestoreError({
}
const previousExists = yield* checkpointStore.hasCheckpointRef({
cwd: input.scope.cwd,
checkpointRef: previousCheckpointRef,
});
const files = previousExists
? yield* checkpointStore
.diffCheckpoints({
cwd: input.scope.cwd,
fromCheckpointRef: previousCheckpointRef,
toCheckpointRef: checkpointRef,
fallbackFromToHead: false,
ignoreWhitespace: false,
})
.pipe(
Effect.map((diff) =>
parseTurnDiffFilesFromUnifiedDiff(diff).map((file) => ({
path: file.path,
kind: "modified",
additions: file.additions,
deletions: file.deletions,
})),
),
Effect.catch((cause) =>
Effect.logWarning("orchestration V2 checkpoint diff summary failed", {
scopeId: input.scope.id,
checkpointRef,
cause: String(cause),
}).pipe(Effect.as([])),
),
)
: [];
return makeCheckpoint({
id: checkpointId,
scope: input.scope,
runId: input.runId,
nodeId: input.nodeId,
parentCheckpointId,
ordinalWithinScope: input.ordinalWithinScope,
appRunOrdinal: input.appRunOrdinal,
ref: checkpointRef,
status: "ready",
files,
capturedAt: input.capturedAt,
});
}),
).pipe(
Effect.mapError(
(cause) =>
new CheckpointCaptureError({
scopeId: input.scope.id,
cause,
}),
),
);
const restore: CheckpointServiceV2Shape["restore"] = (input) =>
withWorkspaceLock(
input.scope.cwd,
Effect.gen(function* () {
if (input.checkpoint.status !== "ready") {
return yield* new CheckpointRestoreError({
scopeId: input.scope.id,
checkpointId: input.checkpoint.id,
cause: `Checkpoint status is ${input.checkpoint.status}.`,
});
}
const restored = yield* checkpointStore.restoreCheckpoint({
cwd: input.scope.cwd,
checkpointRef: input.checkpoint.ref,
fallbackToHead: false,
});
if (!restored) {
return yield* new CheckpointRestoreError({
scopeId: input.scope.id,
checkpointId: input.checkpoint.id,
cause: "Checkpoint ref is unavailable.",
});
}
}),
).pipe(
Effect.mapError((cause) =>
isCheckpointRestoreError(cause)
? cause
: new CheckpointRestoreError({
scopeId: input.scope.id,
checkpointId: input.checkpoint.id,
cause: "Checkpoint ref is unavailable.",
});
}
}),
).pipe(
Effect.mapError((cause) =>
Schema.is(CheckpointRestoreError)(cause)
? cause
: new CheckpointRestoreError({
scopeId: input.scope.id,
checkpointId: input.checkpoint.id,
cause,
}),
),
);
cause,
}),
),
);
const deleteStaleRefs: CheckpointServiceV2Shape["deleteStaleRefs"] = (input) =>
withWorkspaceLock(
input.scope.cwd,
checkpointStore.deleteCheckpointRefs({
cwd: input.scope.cwd,
checkpointRefs: input.checkpoints.map((checkpoint) => checkpoint.ref),
}),
).pipe(
const deleteStaleRefs: CheckpointServiceV2Shape["deleteStaleRefs"] = (input) =>
withWorkspaceLock(
input.scope.cwd,
checkpointStore.deleteCheckpointRefs({
cwd: input.scope.cwd,
checkpointRefs: input.checkpoints.map((checkpoint) => checkpoint.ref),
}),
).pipe(
Effect.mapError(
(cause) =>
new CheckpointDeleteStaleRefsError({
scopeId: input.scope.id,
checkpointIds: input.checkpoints.map((checkpoint) => checkpoint.id),
cause,
}),
),
);
return CheckpointServiceV2.of({
prepareRootRunScope: (input) =>
makeRootRunScope({ ...input, idAllocator }).pipe(
Effect.mapError(
(cause) =>
new CheckpointDeleteStaleRefsError({
scopeId: input.scope.id,
checkpointIds: input.checkpoints.map((checkpoint) => checkpoint.id),
new CheckpointRootScopePrepareError({
threadId: input.threadId,
runId: input.runId,
cause,
}),
),
);
return CheckpointServiceV2.of({
prepareRootRunScope: (input) =>
makeRootRunScope({ ...input, idAllocator }).pipe(
Effect.mapError(
(cause) =>
new CheckpointRootScopePrepareError({
threadId: input.threadId,
runId: input.runId,
cause,
}),
),
),
ensureScope,
captureBaseline,
capture,
restore,
deleteStaleRefs,
} satisfies CheckpointServiceV2Shape);
}),
);
import { createHash } from "node:crypto";
),
ensureScope,
captureBaseline,
capture,
restore,
deleteStaleRefs,
} satisfies CheckpointServiceV2Shape);
}),
);
@@ -13,7 +13,7 @@ import * as Layer from "effect/Layer";
import { FetchHttpClient } from "effect/unstable/http";
import { describe } from "vite-plus/test";
import { CheckpointStoreLive } from "../checkpointing/Layers/CheckpointStore.ts";
import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
import { ServerConfig } from "../config.ts";
import { SqlitePersistenceMemory } from "../persistence/Layers/Sqlite.ts";
import { ProviderInstanceRegistryHydrationLive } from "../provider/Layers/ProviderInstanceRegistryHydration.ts";
@@ -39,7 +39,7 @@ const vcsDriverRegistryLayer = VcsDriverRegistry.layer.pipe(
Layer.provide(NodeServices.layer),
);
const checkpointStoreLayer = CheckpointStoreLive.pipe(Layer.provide(vcsDriverRegistryLayer));
const checkpointStoreLayer = CheckpointStore.layer.pipe(Layer.provide(vcsDriverRegistryLayer));
const serverSettingsLayer = ServerSettingsService.layerTest({
providers: {
@@ -13,7 +13,7 @@ import * as Layer from "effect/Layer";
import { FetchHttpClient } from "effect/unstable/http";
import { describe } from "vite-plus/test";
import { CheckpointStoreLive } from "../checkpointing/Layers/CheckpointStore.ts";
import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
import { ServerConfig } from "../config.ts";
import { SqlitePersistenceMemory } from "../persistence/Layers/Sqlite.ts";
import { ProviderInstanceRegistryHydrationLive } from "../provider/Layers/ProviderInstanceRegistryHydration.ts";
@@ -39,7 +39,7 @@ const vcsDriverRegistryLayer = VcsDriverRegistry.layer.pipe(
Layer.provide(NodeServices.layer),
);
const checkpointStoreLayer = CheckpointStoreLive.pipe(Layer.provide(vcsDriverRegistryLayer));
const checkpointStoreLayer = CheckpointStore.layer.pipe(Layer.provide(vcsDriverRegistryLayer));
const serverSettingsLayer = ServerSettingsService.layerTest({
providers: {
@@ -23,7 +23,7 @@ import * as Stream from "effect/Stream";
import { TestClock } from "effect/testing";
import { HttpServer } from "effect/unstable/http";
import { ServerEnvironment } from "../environment/Services/ServerEnvironment.ts";
import { ServerEnvironment } from "../environment/ServerEnvironment.ts";
import * as McpProviderSession from "../mcp/McpProviderSession.ts";
import * as McpSessionRegistry from "../mcp/McpSessionRegistry.ts";
import { SqlitePersistenceMemory } from "../persistence/Layers/Sqlite.ts";
@@ -12,7 +12,7 @@ import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Stream from "effect/Stream";
import { CheckpointStoreLive } from "../checkpointing/Layers/CheckpointStore.ts";
import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
import { ServerConfig } from "../config.ts";
import { GitCoreLive } from "../git/Layers/GitCore.ts";
import { SqlitePersistenceMemory } from "../persistence/Layers/Sqlite.ts";
@@ -35,9 +35,8 @@ const GitCoreTestLayer = GitCoreLive.pipe(
Layer.provide(NodeServices.layer),
);
const CheckpointStoreTestLayer = CheckpointStoreLive.pipe(
Layer.provide(GitCoreTestLayer),
Layer.provide(NodeServices.layer),
const CheckpointStoreTestLayer = CheckpointStore.layer.pipe(
Layer.provide(VcsDriverRegistryTestLayer),
);
const driver = ProviderDriverKind.make("codex");
@@ -9,9 +9,8 @@ import type * as SqlClient from "effect/unstable/sql/SqlClient";
import type { MigrationError } from "effect/unstable/sql/Migrator";
import type { SqlError } from "effect/unstable/sql/SqlError";
import { CheckpointStoreLive } from "../../checkpointing/Layers/CheckpointStore.ts";
import { ServerConfig, type ServerConfigShape } from "../../config.ts";
import { GitCoreLive } from "../../git/Layers/GitCore.ts";
import * as CheckpointStore from "../../checkpointing/CheckpointStore.ts";
import { ServerConfig } from "../../config.ts";
import { SqlitePersistenceMemory } from "../../persistence/Layers/Sqlite.ts";
import { ServerSettingsService } from "../../serverSettings.ts";
import * as VcsDriverRegistry from "../../vcs/VcsDriverRegistry.ts";
@@ -59,7 +58,7 @@ import {
export function makeReplayServerConfig(
scenario: string,
): Effect.Effect<
ServerConfigShape,
ServerConfig["Service"],
PlatformError.PlatformError,
FileSystem.FileSystem | Path.Path
> {
@@ -245,8 +244,8 @@ export function makeOrchestratorV2ReplayLayerWithRegistry<Error>(
Layer.provide(serverConfigLayer),
Layer.provide(NodeServices.layer),
);
const checkpointStoreLayer = CheckpointStoreLive.pipe(
Layer.provide(gitCoreLayer),
const checkpointStoreLayer = CheckpointStore.layer.pipe(
Layer.provide(vcsDriverRegistryLayer),
Layer.provide(NodeServices.layer),
);
const checkpointServiceProvided = checkpointServiceLayer.pipe(
+7 -7
View File
@@ -567,13 +567,10 @@ const buildAppUnderTest = (options?: {
),
);
const servedRoutesLayer = HttpRouter.serve(
makeRoutesLayer.pipe(Layer.provide(ServiceLauncherClient.layer)),
{
disableListenLog: true,
disableLogger: true,
},
).pipe(
const servedRoutesBaseLayer = HttpRouter.serve(makeRoutesLayer, {
disableListenLog: true,
disableLogger: true,
}).pipe(
Layer.provide(
Layer.mock(Keybindings.Keybindings)({
loadConfigState: Effect.succeed({
@@ -780,6 +777,9 @@ const buildAppUnderTest = (options?: {
...options?.layers?.checkpointDiffQuery,
}),
),
);
const servedRoutesLayer = servedRoutesBaseLayer.pipe(
Layer.provide(OrchestrationV2UnavailableTestLayer),
);
+23 -5
View File
@@ -28,8 +28,7 @@ import type { CSSProperties, DragEvent, ReactNode } from "react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { ProviderModelPicker } from "../components/chat/ProviderModelPicker";
import { getPrimaryEnvironmentConnection } from "../environments/runtime";
import { useSettings } from "../hooks/useSettings";
import { usePrimarySettings } from "../hooks/useSettings";
import {
removeAndRenumberTimelineItem,
upsertTimelineItemAtStablePosition,
@@ -1627,9 +1626,28 @@ function OrchestrationV2DebugRoute() {
const unsubscribeRef = useRef<(() => void) | null>(null);
const shellUnsubscribeRef = useRef<(() => void) | null>(null);
const serverProviders = useServerProviders();
const settings = useSettings();
const keybindings = useServerKeybindings();
const environmentId = usePrimaryEnvironmentId();
const serverProviders = useAtomValue(primaryServerProvidersAtom);
const settings = usePrimarySettings();
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
const dispatchCommandMutation = useAtomCommand(orchestrationEnvironment.v2.dispatchCommand, {
reportFailure: false,
});
const getThreadProjectionQuery = useAtomQueryRunner(
orchestrationEnvironment.v2.threadProjection,
{ reportFailure: false },
);
const shellSubscription = useEnvironmentQuery(
environmentId === null ? null : orchestrationEnvironment.v2.shell({ environmentId, input: {} }),
);
const threadSubscription = useEnvironmentQuery(
environmentId === null || threadId === null
? null
: orchestrationEnvironment.v2.thread({
environmentId,
input: { threadId },
}),
);
const providerSnapshots = useMemo(
() =>
deriveOrchestrationV2DebugProviderSnapshots({
+5 -1
View File
@@ -1,4 +1,8 @@
import { ORCHESTRATION_WS_METHODS, WS_METHODS } from "@t3tools/contracts";
import {
ORCHESTRATION_V2_WS_METHODS,
ORCHESTRATION_WS_METHODS,
WS_METHODS,
} from "@t3tools/contracts";
import * as Cause from "effect/Cause";
import * as Context from "effect/Context";
import type * as Duration from "effect/Duration";
@@ -319,7 +319,6 @@ function encodeInboundFrame(frame: unknown): Uint8Array {
}
function replayTransportError(
transcript: CodexAppServerReplayTranscript,
error: CodexAppServerReplayError,
): CodexError.CodexAppServerTransportError {
return new CodexError.CodexAppServerTransportError({
@@ -505,7 +504,7 @@ const makeReplayClientWithState = Effect.fn(
const terminationError: Effect.Effect<CodexError.CodexAppServerError> = Ref.get(state).pipe(
Effect.map((current) =>
current.failure
? replayTransportError(transcript, current.failure)
? replayTransportError(current.failure)
: new CodexError.CodexAppServerProcessExitedError({ code: 0 }),
),
);