The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 05:45 UTC
fix(acp): Always allow no longer cancels the turn when an agent only offers allow-once (#29463)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
MarcoDotIO committed
Nov 3, 2026 at 18:09 UTC
21e4f980ca375dee6ac6305c0c021e7f08e8deb4
2 files changed
+141
-7
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+134
@@ -4525,6 +4525,140 @@ describe("AcpAdapterV2", () => {
4525
}).pipe(Effect.provide(layerTest), Effect.scoped),
4526
);
4527
4528
+ it.effect.each([
4529
+ {
4530
+ label: "answers Always allow with the agent's allow-always option",
4531
+ options: [
4532
+ { optionId: "allow-once", name: "Allow once", kind: "allow_once" },
4533
+ { optionId: "allow-always", name: "Always allow", kind: "allow_always" },
4534
+ { optionId: "reject-once", name: "Reject", kind: "reject_once" },
4535
+ ],
4536
+ optionId: "allow-always",
4537
+ },
4538
+ {
4539
+ label: "answers Always allow with allow-once when the agent offers no allow-always option",
4540
+ options: [
4541
+ { optionId: "allow-once", name: "Allow once", kind: "allow_once" },
4542
+ { optionId: "reject-once", name: "Reject", kind: "reject_once" },
4543
+ ],
4544
+ optionId: "allow-once",
4545
+ },
4546
+ ] as const)("$label", ({ options, optionId }) =>
4547
+ Effect.gen(function* () {
4548
+ const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
4549
+ const path = yield* Path.Path;
4550
+ const selfInvocation = yield* resolveSelfInvocation();
4551
+ const mockAgentPath = yield* path.fromFileUrl(
4552
+ new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
4553
+ );
4554
+ type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"];
4555
+ let requestPermission: Parameters<RuntimeService["handleRequestPermission"]>[0] | undefined;
4556
+ let runtimeInput: AcpAdapterV2RuntimeInput | undefined;
4557
+ const makeRuntime = makeMockRuntime({
4558
+ childProcessSpawner,
4559
+ mockAgentPath,
4560
+ environment: { T3_ACP_HANG_PROMPT_FOREVER: "1" },
4561
+ wrapRuntime: (runtime) => ({
4562
+ ...runtime,
4563
+ handleRequestPermission: (handler) =>
4564
+ Effect.sync(() => {
4565
+ requestPermission = handler;
4566
+ }).pipe(Effect.andThen(runtime.handleRequestPermission(handler))),
4567
+ }),
4568
+ });
4569
+ const instanceId = ProviderInstanceId.make("acp-test-always-allow");
4570
+ const adapter = yield* makeAcpAdapterV2({
4571
+ instanceId,
4572
+ flavor: {
4573
+ driver: ACP_TEST_DRIVER,
4574
+ capabilities: AcpProviderCapabilitiesV2,
4575
+ interruptPromptOnCancel: true,
4576
+ makeRuntime: (input) =>
4577
+ Effect.sync(() => {
4578
+ runtimeInput = input;
4579
+ }).pipe(Effect.andThen(makeRuntime(input))),
4580
+ },
4581
+ selfInvocation,
4582
+ clientTerminals: {},
4583
+ });
4584
+ const threadId = ThreadId.make("thread-acp-always-allow");
4585
+ const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
4586
+ runtimeMode: "approval-required",
4587
+ interactionMode: "default",
4588
+ cwd: process.cwd(),
4589
+ });
4590
+ const modelSelection = { instanceId, model: "default" } as const;
4591
+ const runtime = yield* adapter.openSession({
4592
+ threadId,
4593
+ providerSessionId: ProviderSessionId.make("provider-session-acp-always-allow"),
4594
+ modelSelection,
4595
+ runtimePolicy,
4596
+ });
4597
+ const providerThread = yield* runtime.ensureThread({
4598
+ threadId,
4599
+ modelSelection,
4600
+ runtimePolicy,
4601
+ });
4602
+ const turnFiber = yield* runtime
4603
+ .startTurn(
4604
+ makeTurnInput({
4605
+ threadId,
4606
+ providerThread,
4607
+ instanceId,
4608
+ runtimePolicy,
4609
+ now: yield* DateTime.now,
4610
+ }),
4611
+ )
4612
+ .pipe(Effect.forkScoped);
4613
+ if (requestPermission === undefined) {
4614
+ return yield* Effect.die("ACP runtime must register a permission handler");
4615
+ }
4616
+
4617
+ const permissionFiber = yield* requestPermission(
4618
+ {
4619
+ sessionId: "mock-session-1",
4620
+ toolCall: { toolCallId: "always-allow-tool", title: "Run tests", kind: "execute" },
4621
+ options,
4622
+ },
4623
+ { requestId: "always-allow-request", method: "session/request_permission" },
4624
+ ).pipe(Effect.forkScoped);
4625
+ const pending = Option.getOrThrow(
4626
+ yield* runtime.events.pipe(
4627
+ Stream.filter(
4628
+ (event) =>
4629
+ event.type === "runtime_request.updated" && event.runtimeRequest.status === "pending",
4630
+ ),
4631
+ Stream.runHead,
4632
+ ),
4633
+ );
4634
+ if (
4635
+ pending.type !== "runtime_request.updated" ||
4636
+ pending.runtimeRequest.providerTurnId === null
4637
+ ) {
4638
+ return yield* Effect.die("Expected an ACP approval request");
4639
+ }
4640
+ const responseFiber = yield* runtime
4641
+ .respondToRuntimeRequest({
4642
+ requestId: pending.runtimeRequest.id,
4643
+ decision: "acceptForSession",
4644
+ })
4645
+ .pipe(Effect.forkScoped);
4646
+ const { outcome } = yield* Fiber.join(permissionFiber);
4647
+ if (runtimeInput?.onOutgoingResponse === undefined) {
4648
+ return yield* Effect.die("ACP runtime must expose native response acknowledgements");
4649
+ }
4650
+ yield* runtimeInput.onOutgoingResponse("always-allow-request");
4651
+ yield* Fiber.join(responseFiber);
4652
+
4653
+ yield* runtime.interruptTurn({
4654
+ providerThread,
4655
+ providerTurnId: pending.runtimeRequest.providerTurnId,
4656
+ });
4657
+ yield* Fiber.join(turnFiber);
4658
+ assert.deepEqual(outcome, { outcome: "selected", optionId });
4659
+ }).pipe(Effect.provide(layerTest), Effect.scoped),
4660
+ );
4661
+
4662
it.effect("replaces the ACP session and clears conversation state on rollback", () =>
4663
Effect.gen(function* () {
4664
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
packages/provider-acp/src/server/adapter.ts
+7
-7
@@ -1256,13 +1256,13 @@ function selectPermissionOptionId(
1256
request: EffectAcpSchema.RequestPermissionRequest,
1257
decision: Exclude<ProviderApprovalDecision, "cancel">,
1258
): string | undefined {
1259
- const kind =
1260
- decision === "acceptForSession"
1261
- ? "allow_always"
1262
- : decision === "accept"
1263
- ? "allow_once"
1264
- : "reject_once";
1265
- return request.options.find((option) => option.kind === kind)?.optionId.trim() || undefined;
1259
+ const optionIdOfKind = (kind: EffectAcpSchema.PermissionOption["kind"]) =>
1260
+ request.options.find((option) => option.kind === kind)?.optionId.trim() || undefined;
1261
+ if (decision === "acceptForSession") {
1262
+ // Agents may offer only allow_once, and answering "cancelled" would stop the turn the user approved.
1263
+ return optionIdOfKind("allow_always") ?? optionIdOfKind("allow_once");
1264
+ }
1265
+ return optionIdOfKind(decision === "accept" ? "allow_once" : "reject_once");
1266
}
1267
1268
// Prefer allow-once; allow-always can persist beyond the session.