TypeScript
fix(provider-acp): ACP threads keep receiving events after a rollback (#28987)
Trevorb156a7d7f319
diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.tsindex 41034b1134e..3efa9047d58 100644--- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts+++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts@@ -4680,10 +4680,16 @@ describe("AcpAdapterV2", () => {browserToolsAvailable: false,});const runtimeInputs: Array<AcpAdapterV2RuntimeInput> = [];+ const nativeRuntimes: Array<AcpSessionRuntime.AcpSessionRuntime["Service"]> = [];+ let sessionEventCount = 0;const makeRuntime = makeMockRuntime({childProcessSpawner,mockAgentPath,environment: { T3_ACP_PROMPT_DELAY_MS: "100" },+ wrapRuntime: (nativeRuntime) => {+ nativeRuntimes.push(nativeRuntime);+ return nativeRuntime;+ },});const adapter = yield* makeAcpAdapterV2({instanceId,@@ -4694,6 +4700,10 @@ describe("AcpAdapterV2", () => {Effect.sync(() => runtimeInputs.push(runtimeInput)).pipe(Effect.andThen(makeRuntime(runtimeInput)),),+ onSessionEvent: () =>+ Effect.sync(() => {+ sessionEventCount += 1;+ }),},selfInvocation,});@@ -4788,6 +4798,7 @@ describe("AcpAdapterV2", () => {});assert.deepEqual(snapshotAfterRollback.providerTurns, []);assert.deepEqual(snapshotAfterRollback.messages, []);+ const sessionEventsBeforeSecondTurn = sessionEventCount;yield* runtime.startTurn(makeTurnInput({@@ -4814,6 +4825,8 @@ describe("AcpAdapterV2", () => {}}assert.equal(secondStatus, "completed");+ yield* nativeRuntimes[1]!.drainEvents;+ assert.isAbove(sessionEventCount, sessionEventsBeforeSecondTurn);}).pipe(Effect.provide(layerTest), Effect.scoped),);diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.tsindex 268dfbafa8d..ad0b716f37c 100644--- a/packages/provider-acp/src/server/adapter.ts+++ b/packages/provider-acp/src/server/adapter.ts@@ -6300,6 +6300,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (readonly sessionUpdates?: boolean;readonly terminals?: boolean;readonly mcp?: boolean;+ readonly scope?: Scope.Scope;} = {},) {yield* targetRuntime.getEvents().pipe(@@ -6312,7 +6313,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (flavor.onSessionEvent?.(event) ?? Effect.void,).pipe(Effect.asVoid);}),- Effect.forkIn(runtimeScope ?? sessionScope),+ Effect.forkIn(handlerOptions.scope ?? runtimeScope ?? sessionScope),);const requestUserInput = (request: AcpAdapterV2UserInputRequest,@@ -6880,7 +6881,12 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (yield* wireAcpRuntimeHandlers(replacementExit.value.replacementRuntime,replacementGeneration,- { sessionUpdates: false, terminals: false, mcp: false },+ {+ sessionUpdates: false,+ terminals: false,+ mcp: false,+ scope: replacementScope,+ },);const lifecycle = yield* Ref.modify(candidateLifecycle,