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
66 changes: 20 additions & 46 deletions apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5834,12 +5834,17 @@ describe("AcpAdapterV2", () => {
);
const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
const continuationRequests: Array<ProviderContinuationRequest> = [];
const promptSettled = yield* Deferred.make<void>();
const instanceId = ProviderInstanceId.make("acp-test");
const childSessionId = "mock-child-session-post-settle";
let subagentPhase: "spawn" | "complete" = "spawn";
type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"];
let sessionUpdateHandler: Parameters<RuntimeService["handleSessionUpdate"]>[0] | undefined;
const adapter = makeAcpAdapterV2({
testHooks: {
afterPromptSettledWithBackgroundWork: () =>
Deferred.succeed(promptSettled, undefined).pipe(Effect.asVoid),
},
crypto: yield* Crypto.Crypto,
instanceId,
flavor: {
Expand Down Expand Up @@ -5929,28 +5934,13 @@ describe("AcpAdapterV2", () => {
yield* runtime.startTurn(
makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now }),
);
yield* Stream.fromQueue(protocolEvents).pipe(
Stream.filter(
(event) =>
event.direction === "incoming" &&
event.stage === "raw" &&
typeof event.payload === "string" &&
event.payload.includes('"stopReason"'),
),
Stream.runHead,
);
yield* Effect.yieldNow;
yield* Effect.yieldNow;
yield* Deferred.await(promptSettled);

const firstProviderTurnId = idAllocator.derive.providerTurn({
driver: ACP_TEST_DRIVER,
nativeTurnId: acpScopedNativeId(instanceId, "mock-session-1:turn:1"),
});
const interruptFiber = yield* runtime
.interruptTurn({ providerThread, providerTurnId: firstProviderTurnId })
.pipe(Effect.forkScoped);
yield* TestClock.adjust("10 seconds");
yield* Fiber.join(interruptFiber);
yield* runtime.interruptTurn({ providerThread, providerTurnId: firstProviderTurnId });

let firstTerminalStatus: string | null = null;
while (firstTerminalStatus === null) {
Expand Down Expand Up @@ -7006,12 +6996,17 @@ describe("AcpAdapterV2", () => {
);
const protocolEvents = yield* Queue.bounded<EffectAcpProtocol.AcpProtocolLogEvent>(256);
const continuationRequests: Array<ProviderContinuationRequest> = [];
const promptSettled = yield* Deferred.make<void>();
const instanceId = ProviderInstanceId.make("acp-test");
const childSessionId = "019f5470-bf92-7a90-afb3-5a6cea5b34a3";
let subagentPhase: "spawn" | "complete" = "spawn";
type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"];
let sessionUpdateHandler: Parameters<RuntimeService["handleSessionUpdate"]>[0] | undefined;
const adapter = makeAcpAdapterV2({
testHooks: {
afterPromptSettledWithBackgroundWork: () =>
Deferred.succeed(promptSettled, undefined).pipe(Effect.asVoid),
},
crypto: yield* Crypto.Crypto,
instanceId,
flavor: {
Expand Down Expand Up @@ -7110,28 +7105,13 @@ describe("AcpAdapterV2", () => {
yield* runtime.startTurn(
makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now }),
);
yield* Stream.fromQueue(protocolEvents).pipe(
Stream.filter(
(event) =>
event.direction === "incoming" &&
event.stage === "raw" &&
typeof event.payload === "string" &&
event.payload.includes('"stopReason"'),
),
Stream.runHead,
);
yield* Effect.yieldNow;
yield* Effect.yieldNow;
yield* Deferred.await(promptSettled);

const firstProviderTurnId = idAllocator.derive.providerTurn({
driver: ACP_TEST_DRIVER,
nativeTurnId: acpScopedNativeId(instanceId, "mock-session-1:turn:1"),
});
const interruptFiber = yield* runtime
.interruptTurn({ providerThread, providerTurnId: firstProviderTurnId })
.pipe(Effect.forkScoped);
yield* TestClock.adjust("10 seconds");
yield* Fiber.join(interruptFiber);
yield* runtime.interruptTurn({ providerThread, providerTurnId: firstProviderTurnId });

let firstTerminalStatus: string | null = null;
while (firstTerminalStatus === null) {
Expand Down Expand Up @@ -8539,7 +8519,12 @@ describe("AcpAdapterV2", () => {
const authoritativeSubagentText = "authoritative subagent carryover text";
type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"];
let sessionUpdateHandler: Parameters<RuntimeService["handleSessionUpdate"]>[0] | undefined;
const promptSettled = yield* Deferred.make<void>();
const adapter = makeAcpAdapterV2({
testHooks: {
afterPromptSettledWithBackgroundWork: () =>
Deferred.succeed(promptSettled, undefined).pipe(Effect.asVoid),
},
crypto: yield* Crypto.Crypto,
instanceId,
flavor: {
Expand Down Expand Up @@ -8629,18 +8614,7 @@ describe("AcpAdapterV2", () => {
yield* runtime.startTurn(
makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now }),
);
yield* Stream.fromQueue(protocolEvents).pipe(
Stream.filter(
(event) =>
event.direction === "incoming" &&
event.stage === "raw" &&
typeof event.payload === "string" &&
event.payload.includes('"stopReason"'),
),
Stream.runHead,
);
yield* Effect.yieldNow;
yield* Effect.yieldNow;
yield* Deferred.await(promptSettled);

// Project an authoritative v2 assistant-message upsert onto the carryover
// subagent while the deferred turn is still active.
Expand Down
4 changes: 4 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ export interface AcpAdapterV2Options {
* by exactly that on this receipt.
*/
readonly onDeferredFinalizeScheduled?: (debounce: Duration.Input) => Effect.Effect<void>;
readonly afterPromptSettledWithBackgroundWork?: () => Effect.Effect<void>;
readonly afterNativeResponseTransportClosed?: () => Effect.Effect<void>;
readonly afterHardTeardownTransportDrained?: () => Effect.Effect<void>;
readonly beforeNativeResponseAdmissionCheck?: (
Expand Down Expand Up @@ -6935,6 +6936,9 @@ export function makeAcpAdapterV2(options: AcpAdapterV2Options): ProviderAdapterV
// The agent finished this prompt's reply. Background work
// holds the run open, not the text it already sent.
yield* closeTextStreams(context);
yield* (
options.testHooks?.afterPromptSettledWithBackgroundWork?.() ?? Effect.void
);
return;
}
yield* finalizeTurn(context, status);
Expand Down
Loading