fix(orchestrator): execute resolved runtime responses
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
ee6ff5574d
commit
bbfed6c19e
2 files changed
+73
-5
No files matched your search
@@ -11,6 +11,7 @@ import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Option from "effect/Option";
|
||||
|
||||
import type { ProviderAdapterV2RuntimeRequestResponseInput } from "./ProviderAdapter.ts";
|
||||
import { ProjectionStoreV2 } from "./ProjectionStore.ts";
|
||||
import { ProviderSessionManagerV2 } from "./ProviderSessionManager.ts";
|
||||
import {
|
||||
@@ -18,11 +19,13 @@ import {
|
||||
RuntimeRequestServiceV2,
|
||||
} from "./RuntimeRequestService.ts";
|
||||
|
||||
it.effect("rejects resolved runtime requests before invoking the live adapter", () => {
|
||||
it.effect("forwards orchestrator-resolved runtime requests to the live adapter", () => {
|
||||
const threadId = ThreadId.make("thread-runtime-request-resolved");
|
||||
const providerSessionId = ProviderSessionId.make("provider-session-runtime-request-resolved");
|
||||
const requestId = RuntimeRequestId.make("request-resolved");
|
||||
const respondToRuntimeRequest = vi.fn(() => Effect.void);
|
||||
const respondToRuntimeRequest = vi.fn(
|
||||
(_input: ProviderAdapterV2RuntimeRequestResponseInput) => Effect.void,
|
||||
);
|
||||
const getSession = vi.fn(() =>
|
||||
Effect.succeed(
|
||||
Option.some({
|
||||
@@ -61,6 +64,69 @@ it.effect("rejects resolved runtime requests before invoking the live adapter",
|
||||
),
|
||||
);
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const service = yield* RuntimeRequestServiceV2;
|
||||
yield* service.respond({
|
||||
threadId,
|
||||
providerSessionId,
|
||||
requestId,
|
||||
decision: "accept",
|
||||
});
|
||||
|
||||
assert.equal(getSession.mock.calls.length, 1);
|
||||
assert.equal(respondToRuntimeRequest.mock.calls.length, 1);
|
||||
assert.deepEqual(respondToRuntimeRequest.mock.calls[0]?.[0], {
|
||||
requestId,
|
||||
decision: "accept",
|
||||
});
|
||||
}).pipe(Effect.provide(testLayer));
|
||||
});
|
||||
|
||||
it.effect("rejects expired runtime requests before invoking the live adapter", () => {
|
||||
const threadId = ThreadId.make("thread-runtime-request-expired");
|
||||
const providerSessionId = ProviderSessionId.make("provider-session-runtime-request-expired");
|
||||
const requestId = RuntimeRequestId.make("request-expired");
|
||||
const respondToRuntimeRequest = vi.fn(
|
||||
(_input: ProviderAdapterV2RuntimeRequestResponseInput) => Effect.void,
|
||||
);
|
||||
const getSession = vi.fn(() =>
|
||||
Effect.succeed(
|
||||
Option.some({
|
||||
respondToRuntimeRequest,
|
||||
} as never),
|
||||
),
|
||||
);
|
||||
const projection = {
|
||||
runtimeRequests: [
|
||||
{
|
||||
id: requestId,
|
||||
nodeId: NodeId.make("node-runtime-request-expired"),
|
||||
providerTurnId: null,
|
||||
nativeRequestRef: null,
|
||||
kind: "command",
|
||||
status: "expired",
|
||||
responseCapability: {
|
||||
type: "live",
|
||||
providerSessionId,
|
||||
},
|
||||
createdAt: DateTime.makeUnsafe("2026-07-29T00:00:00.000Z"),
|
||||
resolvedAt: DateTime.makeUnsafe("2026-07-29T00:00:01.000Z"),
|
||||
},
|
||||
],
|
||||
} as unknown as OrchestrationV2ThreadProjection;
|
||||
const testLayer = runtimeRequestServiceLayer.pipe(
|
||||
Layer.provide(
|
||||
Layer.mergeAll(
|
||||
Layer.mock(ProjectionStoreV2)({
|
||||
getThreadProjection: () => Effect.succeed(projection),
|
||||
}),
|
||||
Layer.mock(ProviderSessionManagerV2)({
|
||||
get: getSession,
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const service = yield* RuntimeRequestServiceV2;
|
||||
const error = yield* service
|
||||
@@ -72,7 +138,7 @@ it.effect("rejects resolved runtime requests before invoking the live adapter",
|
||||
})
|
||||
.pipe(Effect.flip);
|
||||
|
||||
assert.equal(error.cause, "The runtime request is no longer pending.");
|
||||
assert.equal(error.cause, "The runtime request is not ready for response execution.");
|
||||
assert.equal(getSession.mock.calls.length, 0);
|
||||
assert.equal(respondToRuntimeRequest.mock.calls.length, 0);
|
||||
}).pipe(Effect.provide(testLayer));
|
||||
|
||||
@@ -62,11 +62,13 @@ export const layer: Layer.Layer<
|
||||
cause: "The runtime request no longer exists.",
|
||||
});
|
||||
}
|
||||
if (request.status !== "pending") {
|
||||
// Dispatch validates the request while it is pending, then persists the
|
||||
// resolved projection before this effect is executed.
|
||||
if (request.status !== "resolved") {
|
||||
return yield* new RuntimeRequestResponseExecutionError({
|
||||
threadId: input.threadId,
|
||||
requestId: input.requestId,
|
||||
cause: "The runtime request is no longer pending.",
|
||||
cause: "The runtime request is not ready for response execution.",
|
||||
});
|
||||
}
|
||||
if (
|
||||
|
||||
Reference in new issue
Block a user