TypeScript
perf(acp): ACP agents skip decoding output twice for unused diagnostics (#29100)
Andreicf48ea8d5c0b
diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.tsindex 829725a89bd..a58a83bffa3 100644--- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts+++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts@@ -381,6 +381,8 @@ function makeMockRuntime(input: {? runtimeInput.protocolLogging: {...runtimeInput.protocolLogging,+ logIncoming: true,+ logOutgoing: true,logger: (event: EffectAcpProtocol.AcpProtocolLogEvent) =>Queue.offer(protocolEvents, event).pipe(Effect.andThen(runtimeInput.protocolLogging.logger?.(event) ?? Effect.void),@@ -3077,6 +3079,92 @@ describe("AcpAdapterV2", () => {}).pipe(Effect.provide(layerTest), Effect.scoped),);+ it.effect("keeps protocol diagnostics off unless a protocol logger is supplied", () =>+ Effect.gen(function* () {+ const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;+ const path = yield* Path.Path;+ const selfInvocation = yield* resolveSelfInvocation();+ const mockAgentPath = yield* path.fromFileUrl(+ new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),+ );+ const runTurn = Effect.fn("AcpAdapterV2.testProtocolLoggingTurn")(function* (+ name: string,+ nativeLogging?: NonNullable<Parameters<typeof makeAcpAdapterV2>[0]["nativeLogging"]>,+ ) {+ const events: Array<EffectAcpProtocol.AcpProtocolLogEvent> = [];+ const instanceId = ProviderInstanceId.make(`acp-test-${name}`);+ const threadId = ThreadId.make(`thread-acp-${name}`);+ const makeRuntime = makeMockRuntime({ childProcessSpawner, mockAgentPath });+ const adapter = yield* makeAcpAdapterV2({+ instanceId,+ flavor: {+ driver: ACP_TEST_DRIVER,+ capabilities: AcpProviderCapabilitiesV2,+ makeRuntime: (runtimeInput) =>+ makeRuntime({+ ...runtimeInput,+ protocolLogging: {+ ...runtimeInput.protocolLogging,+ logger: (event) =>+ Effect.sync(() => void events.push(event)).pipe(+ Effect.andThen(runtimeInput.protocolLogging.logger?.(event) ?? Effect.void),+ ),+ },+ }),+ },+ selfInvocation,+ ...(nativeLogging === undefined ? {} : { nativeLogging }),+ });+ const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({+ runtimeMode: "full-access",+ interactionMode: "default",+ cwd: process.cwd(),+ });+ const modelSelection = { instanceId, model: "default" } as const;+ const runtime = yield* adapter.openSession({+ threadId,+ providerSessionId: ProviderSessionId.make(`provider-session-acp-${name}`),+ modelSelection,+ runtimePolicy,+ });+ const providerThread = yield* runtime.ensureThread({+ threadId,+ modelSelection,+ runtimePolicy,+ });+ yield* runtime.startTurn(+ makeTurnInput({+ threadId,+ providerThread,+ instanceId,+ runtimePolicy,+ now: yield* DateTime.now,+ ordinal: 1,+ }),+ );+ const terminal = yield* runtime.events.pipe(+ Stream.filter((event) => event.type === "turn.terminal"),+ Stream.runHead,+ );+ assert.equal(Option.getOrThrow(terminal).status, "completed");+ return events;+ });++ assert.deepEqual(yield* runTurn("protocol-logging-default"), []);++ const explicit: Array<EffectAcpProtocol.AcpProtocolLogEvent> = [];+ yield* runTurn("protocol-logging-explicit", () => ({+ protocolLogging: {+ logIncoming: true,+ logOutgoing: true,+ logger: (event) => Effect.sync(() => void explicit.push(event)),+ },+ }));+ assert.isTrue(explicit.some((e) => e.direction === "incoming" && e.stage === "raw"));+ assert.isTrue(explicit.some((e) => e.direction === "outgoing"));+ }).pipe(Effect.provide(layerTest), Effect.scoped),+ );+it.effect("advertises ACP session notices and shows them as system notices", () =>Effect.gen(function* () {const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.tsindex 5d4536dfc7c..985f6c8ee98 100644--- a/packages/provider-acp/src/server/adapter.ts+++ b/packages/provider-acp/src/server/adapter.ts@@ -2367,8 +2367,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (? {}: { requestLogger: nativeLogging.requestLogger }),protocolLogging: nativeLogging?.protocolLogging ?? {- logIncoming: true,- logOutgoing: true,+ logIncoming: false,+ logOutgoing: false,logger: () => Effect.void,},};