Skip to content

Commit 0771326

Browse files
t3dotggclaude
andcommitted
fix(server): Codex subagent turns also end "Always allow" on a mode change
Only root turns started through startNativeTurn reset the allowance, so a Codex subagent resumed in another mode kept it. The reset now runs where every root and subagent turn is registered. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 643d26b commit 0771326

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,17 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
18961896
* request arrives and add to that same set when the user answers, so a
18971897
* late answer from a turn whose mode has since ended is dropped.
18981898
*/
1899+
/** Every native turn registers here. A turn in another mode ends the allowance. */
1900+
const endSessionApprovalsOnModeChange = (context: ActiveCodexTurnContext) => {
1901+
const nativeThreadId = context.providerThread.nativeThreadRef?.nativeId;
1902+
if (
1903+
nativeThreadId != null &&
1904+
sessionApprovals.get(nativeThreadId)?.runtimeMode !==
1905+
context.input.runtimePolicy.runtimeMode
1906+
) {
1907+
sessionApprovals.delete(nativeThreadId);
1908+
}
1909+
};
18991910
const sessionAllowance = (
19001911
nativeThreadId: string,
19011912
context: ActiveCodexTurnContext,
@@ -2058,6 +2069,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
20582069
return next;
20592070
});
20602071
beginTurnTokenUsage(context);
2072+
endSessionApprovalsOnModeChange(context);
20612073
yield* Ref.update(activeTurns, (current) => {
20622074
const updated = new Map(current);
20632075
updated.set(input.nativeTurnId, context);
@@ -2643,6 +2655,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
26432655
itemPositions: new Map(),
26442656
};
26452657
beginTurnTokenUsage(activeContext);
2658+
endSessionApprovalsOnModeChange(activeContext);
26462659
yield* Ref.update(activeTurns, (current) => {
26472660
const updated = new Map(current);
26482661
updated.set(turn.nativeTurnId, activeContext);
@@ -6268,12 +6281,6 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
62686281
) =>
62696282
Effect.gen(function* () {
62706283
const threadId = yield* getNativeThreadId(turnInput.providerThread);
6271-
// Returning to the earlier mode must not bring the allowance back.
6272-
if (
6273-
sessionApprovals.get(threadId)?.runtimeMode !== turnInput.runtimePolicy.runtimeMode
6274-
) {
6275-
sessionApprovals.delete(threadId);
6276-
}
62776284
const mcpSession = yield* mcpSessions.read(turnInput.threadId);
62786285
const turnStartParams = yield* buildCodexTurnStartParams({
62796286
nativeThreadId: threadId,

0 commit comments

Comments
 (0)