@devries-cameron20 / t3code Mirror · read-only / commits / 21cbec39d2
Fork 0

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 23, 01:45 UTC

fix(server): Codex file-change approvals list the files they change (#18248)

Co-authored-by: only21mil <263261067+only21mil@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Victor Vogel committed Oct 19, 2026 at 15:25 UTC 21cbec39d2a66ea078e7276ece7b5c1baf09ccc9
3 files changed +245 -2
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+213
@@ -17,6 +17,7 @@ import {
17 type OrchestrationV2AppThread,
18 type OrchestrationV2ProviderThread,
19 type OrchestrationV2ProviderTurn,
20 + type OrchestrationV2RuntimeRequest,
21 type OrchestrationV2TurnItem,
22 ProjectId,
23 type ProviderApprovalDecision,
@@ -35,6 +36,7 @@ import { SpawnExecutableResolution } from "@t3tools/shared/shell";
36 import * as CodexClient from "effect-codex-app-server/client";
37 import * as CodexError from "effect-codex-app-server/errors";
38 import * as CodexReplay from "effect-codex-app-server/replay";
39 +import type * as CodexSchema from "effect-codex-app-server/schema";
40 import * as DateTime from "effect/DateTime";
41 import * as Deferred from "effect/Deferred";
42 import * as Crypto from "effect/Crypto";
@@ -47,6 +49,7 @@ import * as Fiber from "effect/Fiber";
49 import * as Layer from "effect/Layer";
50 import * as Path from "effect/Path";
51 import * as PlatformError from "effect/PlatformError";
52 +import * as Queue from "effect/Queue";
53 import * as Ref from "effect/Ref";
54 import * as Schema from "effect/Schema";
55 import * as Stream from "effect/Stream";
@@ -9533,4 +9536,214 @@ describe("CodexAdapterV2 post-settle continuation", () => {
9536 ),
9537 );
9538 });
9539 +
9540 + describe("Codex file-change approval paths", () => {
9541 + const nativeThreadId = "file-approval-thread";
9542 + const nativeTurnId = "file-approval-turn";
9543 + const prompt = "Edit the files.";
9544 + type FileUpdateChange = CodexSchema.V2ItemStartedNotification__FileUpdateChange;
9545 + const addA: FileUpdateChange = { path: "/w/a.ts", kind: { type: "add" }, diff: "export {};" };
9546 + const updateB: FileUpdateChange = {
9547 + path: "/w/b.ts",
9548 + kind: { type: "update", move_path: null },
9549 + diff: "@@",
9550 + };
9551 + const renameC: FileUpdateChange = {
9552 + path: "/w/c.ts",
9553 + kind: { type: "update", move_path: "/w/d.ts" },
9554 + diff: "@@",
9555 + };
9556 +
9557 + const deleteE: FileUpdateChange = { path: "/w/e.ts", kind: { type: "delete" }, diff: "gone" };
9558 +
9559 + const fileChange = (
9560 + phase: "started" | "completed",
9561 + turnId: string,
9562 + itemId: string,
9563 + changes: ReadonlyArray<FileUpdateChange>,
9564 + ): CodexReplay.CodexAppServerReplayEntry => ({
9565 + type: "emit_inbound",
9566 + label: `${phase} ${itemId}`,
9567 + frame: {
9568 + method: `item/${phase}`,
9569 + params: {
9570 + threadId: nativeThreadId,
9571 + turnId,
9572 + ...(phase === "started" ? { startedAtMs: 1 } : { completedAtMs: 3 }),
9573 + item: {
9574 + type: "fileChange",
9575 + id: itemId,
9576 + status: phase === "started" ? "inProgress" : "completed",
9577 + changes,
9578 + },
9579 + },
9580 + },
9581 + });
9582 +
9583 + const approval = (input: {
9584 + readonly id: number;
9585 + readonly turnId: string;
9586 + readonly itemId: string;
9587 + }): Array<CodexReplay.CodexAppServerReplayEntry> => [
9588 + {
9589 + type: "emit_inbound",
9590 + label: `approval ${input.itemId}`,
9591 + frame: {
9592 + id: input.id,
9593 + method: "item/fileChange/requestApproval",
9594 + params: {
9595 + threadId: nativeThreadId,
9596 + turnId: input.turnId,
9597 + itemId: input.itemId,
9598 + startedAtMs: 2,
9599 + reason: null,
9600 + grantRoot: null,
9601 + },
9602 + },
9603 + },
9604 + {
9605 + type: "expect_outbound",
9606 + label: `approval ${input.itemId}`,
9607 + frame: { id: input.id, result: { decision: "accept" } },
9608 + },
9609 + ];
9610 +
9611 + const turnCompleted = (turnId: string): CodexReplay.CodexAppServerReplayEntry => ({
9612 + type: "emit_inbound",
9613 + label: `complete ${turnId}`,
9614 + frame: {
9615 + method: "turn/completed",
9616 + params: {
9617 + threadId: nativeThreadId,
9618 + turn: makeCodexReplayTurn({ id: turnId, status: "completed" }),
9619 + },
9620 + },
9621 + });
9622 +
9623 + const startApprovalTurn = (
9624 + scenario: string,
9625 + entries: ReadonlyArray<CodexReplay.CodexAppServerReplayEntry>,
9626 + ) =>
9627 + Effect.gen(function* () {
9628 + const pending = yield* Queue.unbounded<OrchestrationV2RuntimeRequest>();
9629 + const harness = yield* makeCodexReplayHarness(
9630 + makeCodexReplayTranscript({
9631 + scenario,
9632 + entries: [...codexReplayPreamble({ nativeThreadId, nativeTurnId, prompt }), ...entries],
9633 + }),
9634 + (event) =>
9635 + event.type === "runtime_request.updated" && event.runtimeRequest.status === "pending"
9636 + ? Queue.offer(pending, event.runtimeRequest)
9637 + : Effect.void,
9638 + );
9639 + yield* harness.runtime.startTurn(
9640 + makeCodexTestTurnInput({
9641 + threadId: harness.threadId,
9642 + providerThread: harness.providerThread,
9643 + now: yield* DateTime.now,
9644 + attemptId: RunAttemptId.make(`${scenario}-attempt`),
9645 + text: prompt,
9646 + }),
9647 + );
9648 + return {
9649 + harness,
9650 + answerNext: Queue.take(pending).pipe(
9651 + Effect.tap((request) =>
9652 + harness.runtime.respondToRuntimeRequest({
9653 + requestId: request.id,
9654 + decision: "accept",
9655 + }),
9656 + ),
9657 + ),
9658 + };
9659 + });
9660 +
9661 + const approvalItem = (
9662 + events: ReadonlyArray<ProviderAdapter.ProviderAdapterV2Event>,
9663 + request: OrchestrationV2RuntimeRequest,
9664 + ) =>
9665 + events.flatMap((event) =>
9666 + event.type === "turn_item.updated" &&
9667 + event.turnItem.type === "approval_request" &&
9668 + event.turnItem.requestId === request.id
9669 + ? [event.turnItem]
9670 + : [],
9671 + )[0];
9672 +
9673 + it.effect("answers without waiting for late paths or borrowing another item's paths", () =>
9674 + Effect.gen(function* () {
9675 + const { harness, answerNext } = yield* startApprovalTurn("file-approval-after", [
9676 + fileChange("started", nativeTurnId, "other-patch", [updateB]),
9677 + // Late details cannot arrive until the approval response has been sent.
9678 + ...approval({ id: 0, turnId: nativeTurnId, itemId: "patch-a" }),
9679 + fileChange("started", nativeTurnId, "patch-a", [addA]),
9680 + fileChange("completed", nativeTurnId, "patch-a", [addA]),
9681 + fileChange("completed", nativeTurnId, "other-patch", [updateB]),
9682 + turnCompleted(nativeTurnId),
9683 + ]);
9684 + const request = yield* answerNext;
9685 + yield* harness.firstTerminal;
9686 +
9687 + const items = harness.events.flatMap((event) =>
9688 + event.type === "turn_item.updated" &&
9689 + event.turnItem.type === "approval_request" &&
9690 + event.turnItem.requestId === request.id
9691 + ? [event.turnItem]
9692 + : [],
9693 + );
9694 + assert.equal(request.nativeRequestRef?.nativeId, "patch-a");
9695 + assert.isNotEmpty(items);
9696 + for (const item of items) {
9697 + assert.equal(item.requestKind, "file-change");
9698 + assert.isUndefined(item.prompt);
9699 + }
9700 + assert.deepEqual(
9701 + harness.terminalEvents().map((event) => event.status),
9702 + ["completed"],
9703 + );
9704 + }).pipe(
9705 + Effect.scoped,
9706 + Effect.provide(
9707 + Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
9708 + ),
9709 + ),
9710 + );
9711 +
9712 + it.effect("matches file paths to items approved out of order", () =>
9713 + Effect.gen(function* () {
9714 + const { harness, answerNext } = yield* startApprovalTurn("file-approval-concurrent", [
9715 + fileChange("started", nativeTurnId, "patch-a", [renameC, deleteE, addA]),
9716 + fileChange("started", nativeTurnId, "patch-b", [updateB]),
9717 + ...approval({ id: 0, turnId: nativeTurnId, itemId: "patch-b" }),
9718 + fileChange("completed", nativeTurnId, "patch-b", [updateB]),
9719 + ...approval({ id: 1, turnId: nativeTurnId, itemId: "patch-a" }),
9720 + fileChange("completed", nativeTurnId, "patch-a", [renameC, deleteE, addA]),
9721 + turnCompleted(nativeTurnId),
9722 + ]);
9723 + const first = yield* answerNext;
9724 + const second = yield* answerNext;
9725 + yield* harness.firstTerminal;
9726 +
9727 + assert.deepEqual(
9728 + [first, second].map((request) => [
9729 + request.nativeRequestRef?.nativeId,
9730 + approvalItem(harness.events, request)?.prompt,
9731 + ]),
9732 + [
9733 + ["patch-b", "update /w/b.ts"],
9734 + ["patch-a", "add /w/a.ts\nupdate /w/c.ts -> /w/d.ts\ndelete /w/e.ts"],
9735 + ],
9736 + );
9737 + assert.deepEqual(
9738 + harness.terminalEvents().map((event) => event.status),
9739 + ["completed"],
9740 + );
9741 + }).pipe(
9742 + Effect.scoped,
9743 + Effect.provide(
9744 + Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
9745 + ),
9746 + ),
9747 + );
9748 + });
9749 });
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+25 -2
@@ -153,10 +153,14 @@ const CODEX_PROVIDER = ProviderDriverKind.make("codex");
153 export const CODEX_DRIVER_KIND = CODEX_PROVIDER;
154 export const CODEX_DEFAULT_INSTANCE_ID = defaultInstanceIdForDriver(CODEX_DRIVER_KIND);
155
156 +type CodexFileChangeKinds = Readonly<
157 + Record<string, CodexSchema.V2ItemStartedNotification__PatchChangeKind>
158 +>;
159 +
160 export function codexFileChangeApprovalPrompt(input: {
161 readonly reason?: string | null;
162 readonly grantRoot?: string | null;
159 - readonly fileChanges?: CodexSchema.ServerRequest__ApplyPatchApprovalParams["fileChanges"];
163 + readonly fileChanges?: CodexFileChangeKinds;
164 }): string | undefined {
165 const reason = input.reason?.trim();
166 if (reason) return reason;
@@ -1126,6 +1130,8 @@ interface ActiveCodexTurnContext {
1130 readonly rootNodeId: OrchestrationV2ExecutionNode["id"];
1131 readonly subagent: CodexSubagentThreadContext | null;
1132 readonly startedAt: DateTime.Utc;
1133 + // Modern approval requests omit paths; keep the kinds without retaining patch bodies.
1134 + readonly fileChangeKindsByItem: Map<string, CodexFileChangeKinds>;
1135 readonly itemPositions: Map<
1136 string,
1137 { readonly ordinal: number; readonly startedAt: DateTime.Utc }
@@ -2010,6 +2016,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
2016 subagent: null,
2017 startedAt: input.startedAt,
2018 itemPositions: new Map(),
2019 + fileChangeKindsByItem: new Map(),
2020 };
2021 yield* Ref.update(limitedTurnItems, (current) => {
2022 const next = new Map(current);
@@ -2581,6 +2588,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
2588 subagent,
2589 startedAt: turn.startedAt,
2590 itemPositions: new Map(),
2591 + fileChangeKindsByItem: new Map(),
2592 };
2593 beginTurnTokenUsage(activeContext);
2594 endSessionApprovalsOnModeChange(activeContext);
@@ -4659,6 +4667,14 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
4667 );
4668 }
4669
4670 + if (payload.item.type === "fileChange") {
4671 + context.fileChangeKindsByItem.set(
4672 + payload.item.id,
4673 + Object.fromEntries(payload.item.changes.map(({ path, kind }) => [path, kind])),
4674 + );
4675 + return;
4676 + }
4677 +
4678 if (payload.item.type === "agentMessage") {
4679 if (payload.item.phase !== "commentary") {
4680 yield* Ref.update(finalAnswerItemIdsByTurn, (current) => {
@@ -4875,6 +4891,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
4891 }
4892
4893 if (payload.item.type === "fileChange") {
4894 + context.fileChangeKindsByItem.delete(payload.item.id);
4895 const artifacts = yield* buildFileChangeArtifacts(context, payload.item);
4896 if (artifacts === null) {
4897 return;
@@ -5127,7 +5144,11 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
5144 nativeItemId: payload.itemId,
5145 nativeRequestId: payload.itemId,
5146 requestKind: "file-change",
5130 - prompt: codexFileChangeApprovalPrompt(payload) ?? null,
5147 + prompt:
5148 + codexFileChangeApprovalPrompt({
5149 + ...payload,
5150 + fileChanges: context.fileChangeKindsByItem.get(payload.itemId) ?? {},
5151 + }) ?? null,
5152 });
5153 const decision = yield* Deferred.make<ProviderApprovalDecision, never>();
5154 yield* Ref.update(pendingRuntimeRequests, (current) => {
@@ -5752,6 +5773,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
5773 if (current !== input.context) {
5774 return false;
5775 }
5776 + input.context.fileChangeKindsByItem.clear();
5777 const providerRetry = yield* Ref.modify(providerRetries, (current) => {
5778 const retry = current.get(input.context.providerTurnId);
5779 if (retry === undefined) {
@@ -6050,6 +6072,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
6072 subagent: null,
6073 startedAt: now,
6074 itemPositions: new Map(),
6075 + fileChangeKindsByItem: new Map(),
6076 };
6077 const providerTurn = {
6078 id: context.providerTurnId,
apps/server/src/orchestration-v2/testkit/fixtures/tool_call_restricted_granular/codex_output.ts
+7
@@ -1,3 +1,4 @@
1 +import { assert } from "@effect/vitest";
2 import type { ProviderReplayTranscript } from "@t3tools/contracts";
3
4 import type { OrchestratorV2ScenarioResult } from "../../OrchestratorScenario.ts";
@@ -33,4 +34,10 @@ export function assertToolCallRestrictedGranularOutput(
34 assertRuntimeRequestKinds(projection, ["file-change"]);
35 assertAllRuntimeRequestsResolved(projection);
36 assertUserMessagesInclude(projection, [TOOL_CALL_WRITE_PROMPT]);
37 +
38 + const approval = projection.turnItems.find((item) => item.type === "approval_request");
39 + assert.equal(
40 + approval?.prompt,
41 + "add /home/replay-user/t3code/packages/effect-codex-app-server/.codex-probe-write-action.txt",
42 + );
43 }