From b2898c239281f6b8180d446f942bf3a59c38b3fa Mon Sep 17 00:00:00 2001 From: nullStack65 <112618179+nullStack65@users.noreply.github.com> Date: Fri, 20 Nov 2026 05:27:10 +0000 Subject: [PATCH 1/2] fix(server): full-access Claude threads no longer wait on approval A full-access thread whose workspace disables Claude bypass was downgraded to auto mode and then sat on the permission callback, including an ask rule for gh pr merge. Full access now runs the command. Claude's removal check and a permission-rule denial still fail immediately, and approval-required threads still wait. Model: grok-4.7 Task: CLO-962 Agent: Codex Lane: magpie Harness: t3/codex Model-family: Grok Model-generation: 4.7 Skills-SHA: de3fb55970ecd0672d321d45360bc13d187b9bda2b601bfe75d3bd9c4f5c2888 Co-Authored-By: Codex --- .../Adapters/ClaudeAdapterV2.test.ts | 78 ++++++++++++++++--- .../Adapters/ClaudeAdapterV2.ts | 53 ++++++++++--- 2 files changed, 111 insertions(+), 20 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index c07ab96746eb5..3e81cf6ee163d 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -948,6 +948,51 @@ describe("ClaudeAdapterV2 context usage", () => { }); }); +describe("ClaudeAdapterV2 full-access command approval", () => { + it("runs a full-access command instead of waiting, and still denies removal and permission-rule checks", () => { + assert.equal( + ClaudeAdapterV2.claudeCommandApprovalDisposition({ + runtimeMode: "full-access", + interactionMode: "default", + permissionMode: "auto", + toolName: "Bash", + safetyReason: "", + }), + "allow", + ); + assert.equal( + ClaudeAdapterV2.claudeCommandApprovalDisposition({ + runtimeMode: "full-access", + interactionMode: "default", + permissionMode: "auto", + toolName: "Bash", + safetyReason: "Dangerous rm on a path built from a variable", + }), + "deny", + ); + assert.equal( + ClaudeAdapterV2.claudeCommandApprovalDisposition({ + runtimeMode: "full-access", + interactionMode: "default", + permissionMode: "bypassPermissions", + toolName: "Bash", + safetyReason: "A permission rule denies a command in this shell -c script", + }), + "deny", + ); + assert.equal( + ClaudeAdapterV2.claudeCommandApprovalDisposition({ + runtimeMode: "approval-required", + interactionMode: "default", + permissionMode: "default", + toolName: "Bash", + safetyReason: "", + }), + "ask", + ); + }); +}); + describe("ClaudeAdapterV2 approval presentation", () => { it("marks asks that full access could not auto-allow and keeps the CLI's reason", () => { const presentation = ClaudeAdapterV2.claudeApprovalPresentation({ @@ -2016,25 +2061,38 @@ describe("ClaudeAdapterV2 resume compaction", () => { Effect.map((event) => ({ type: "approval", event }) as const), ), ); - assert.equal(safety.type, askRule ? "approval" : "decision"); + assert.equal(safety.type, "decision"); if (safety.type === "decision") { assert.equal(safety.result?.behavior, "deny"); if (safety.result?.behavior === "deny") { assert.include(safety.result.message, reason); assert.notInclude(safety.result.message, "\u001b["); } - } else if ( - Option.isSome(safety.event) && - safety.event.value.type === "runtime_request.updated" - ) { - yield* runtime.respondToRuntimeRequest({ - requestId: safety.event.value.runtimeRequest.id, - decision: "decline", - }); - assert.equal((yield* Fiber.join(safetyDecision))?.behavior, "deny"); } yield* Fiber.interrupt(safetyRequest); } + const mergeSignal = yield* Effect.abortSignal; + const mergeDecision = yield* Effect.promise(() => + canUseTool!( + "Bash", + { + command: + "gh pr merge 1968 -R nullStack65/Closura --squash --match-head-commit b2fdb044ce56f30784c10f4a2daf59c51f8a0346", + }, + { + signal: mergeSignal, + toolUseID: "tool-merge-ask-rule", + requestId: "request-merge-ask-rule", + matchedAskRule: { + source: "projectSettings" as const, + toolName: "Bash", + ruleContent: "gh pr merge *", + }, + }, + ), + ); + assert.equal(mergeDecision.behavior, "allow"); + const longQuestion = `Choose a deployment target: ${"region ".repeat(80)}`; const questionRequestEvent = yield* runtime.events.pipe( Stream.filter((event) => event.type === "runtime_request.updated"), diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index 25d9d616cb939..c902cb72508fa 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -4280,6 +4280,26 @@ const CLAUDE_NO_STANDING_GRANT_OPTIONS = [ { decision: "accept", label: "Approve" }, ] satisfies ReadonlyArray; +export function claudeCommandApprovalDisposition(input: { + readonly runtimeMode: ProviderAdapter.ProviderAdapterV2RuntimePolicy["runtimeMode"]; + readonly interactionMode: ProviderAdapter.ProviderAdapterV2RuntimePolicy["interactionMode"]; + readonly permissionMode: PermissionMode; + readonly toolName: string; + readonly safetyReason: string; +}): "allow" | "deny" | "ask" { + const safetyDenial = + input.toolName === "Bash" && + (/^Dangerous rm(?:dir)?\b/i.test(input.safetyReason) || + input.safetyReason === "This shell -c script runs rm and could not be checked" || + input.safetyReason === "A permission rule denies a command in this shell -c script"); + const fullAccess = input.runtimeMode === "full-access" && input.interactionMode !== "plan"; + if (safetyDenial && (fullAccess || input.permissionMode === "bypassPermissions")) { + return "deny"; + } + if (fullAccess) return "allow"; + return "ask"; +} + export function claudeApprovalPresentation(input: { readonly permissionMode: PermissionMode; readonly prompt: string; @@ -12234,17 +12254,30 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( callbackOptions.decisionReason ?? "", ).trim(); // The SDK omits the CLI's dangerousRemoval discriminator, so match its removal warnings. - if ( - toolName === "Bash" && - activePermissionMode === "bypassPermissions" && - callbackOptions.matchedAskRule === undefined && - (/^Dangerous rm(?:dir)?\b/i.test(safetyReason) || - safetyReason === "This shell -c script runs rm and could not be checked" || - safetyReason === "A permission rule denies a command in this shell -c script") - ) { + const disposition = claudeCommandApprovalDisposition({ + runtimeMode: context.input.runtimePolicy.runtimeMode, + interactionMode: context.input.runtimePolicy.interactionMode, + permissionMode: activePermissionMode, + toolName, + safetyReason, + }); + if (disposition === "deny") { + const removal = + /^Dangerous rm(?:dir)?\b/i.test(safetyReason) || + safetyReason === "This shell -c script runs rm and could not be checked"; + const message = removal + ? `Claude Code's removal safety check denied this command; the user did not reject it. The command did not run. Do not bypass the check by splitting the removal, putting it in a script, or using another tool or shell. If the warning below supplies a safe rewrite, use it and let the same check evaluate it. Otherwise continue the rest of the task without the removal and tell the user what you needed to delete and why. Warning: ${safetyReason}` + : `A permission rule denied this command before it ran. Nobody is waiting to approve it. Do not bypass the rule by splitting the command, putting it in a script, or using another tool. Warning: ${safetyReason}`; return { behavior: "deny", - message: `Claude Code's removal safety check denied this command; the user did not reject it. The command did not run. Do not bypass the check by splitting the removal, putting it in a script, or using another tool or shell. If the warning below supplies a safe rewrite, use it and let the same check evaluate it. Otherwise continue the rest of the task without the removal and tell the user what you needed to delete and why. Warning: ${safetyReason}`, + message, + toolUseID: callbackOptions.toolUseID, + } satisfies PermissionResult; + } + if (disposition === "allow") { + return { + behavior: "allow", + updatedInput: toolInput, toolUseID: callbackOptions.toolUseID, } satisfies PermissionResult; } @@ -13215,7 +13248,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( } const nativeItemId = `bypass-policy-downgrade:${context.providerTurnId}`; const notice = - "T3 could not confirm Claude bypass permissions here, so Full access is running with approval checks."; + "Claude settings disable bypass permissions here. Full access will not wait for approval. A deny rule or Claude's removal check still fails the command immediately."; yield* emitProviderEvent({ type: "turn_item.updated", driver: CLAUDE_PROVIDER, From acdf9d1a1a7395a51a6c46a7704c2aa6ecb18f13 Mon Sep 17 00:00:00 2001 From: nullStack65 <112618179+nullStack65@users.noreply.github.com> Date: Fri, 20 Nov 2026 05:50:10 +0000 Subject: [PATCH 2/2] fix(server): full-access approval follows the bypass permission mode Replay threads keep a full-access runtime mode and set an approval policy. Treating every full-access mode as bypass auto-allowed those tools, so the harness waited forever for a request. Full access now means permissionModeForClaudeRuntimePolicy returns bypassPermissions, the same predicate as the downgrade notice. Plan mode, an explicit approval policy, and a read-only never policy still ask. Removal checks and deny rules still fail immediately. Model: grok-4.7 Task: CLO-962 Agent: Codex Lane: magpie Harness: t3/codex Model-family: Grok Model-generation: 4.7 Skills-SHA: de3fb55970ecd0672d321d45360bc13d187b9bda2b601bfe75d3bd9c4f5c2888 Co-Authored-By: Codex --- .../Adapters/ClaudeAdapterV2.test.ts | 69 ++++++++++++++++--- .../Adapters/ClaudeAdapterV2.ts | 12 ++-- 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index 3e81cf6ee163d..6998e4aa31861 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -949,11 +949,28 @@ describe("ClaudeAdapterV2 context usage", () => { }); describe("ClaudeAdapterV2 full-access command approval", () => { + const policy = (input: { + readonly runtimeMode?: "full-access" | "approval-required"; + readonly interactionMode?: "default" | "plan"; + readonly approvalPolicy?: "on-request" | "never"; + readonly sandboxPolicy?: { + readonly type: "readOnly" | "dangerFullAccess"; + readonly access?: { readonly type: "fullAccess" }; + readonly networkAccess?: false; + }; + }) => + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ + runtimeMode: input.runtimeMode ?? "full-access", + interactionMode: input.interactionMode ?? "default", + cwd: "/workspace", + ...(input.approvalPolicy === undefined ? {} : { approvalPolicy: input.approvalPolicy }), + ...(input.sandboxPolicy === undefined ? {} : { sandboxPolicy: input.sandboxPolicy }), + }); + it("runs a full-access command instead of waiting, and still denies removal and permission-rule checks", () => { assert.equal( ClaudeAdapterV2.claudeCommandApprovalDisposition({ - runtimeMode: "full-access", - interactionMode: "default", + runtimePolicy: policy({}), permissionMode: "auto", toolName: "Bash", safetyReason: "", @@ -962,8 +979,7 @@ describe("ClaudeAdapterV2 full-access command approval", () => { ); assert.equal( ClaudeAdapterV2.claudeCommandApprovalDisposition({ - runtimeMode: "full-access", - interactionMode: "default", + runtimePolicy: policy({}), permissionMode: "auto", toolName: "Bash", safetyReason: "Dangerous rm on a path built from a variable", @@ -972,8 +988,7 @@ describe("ClaudeAdapterV2 full-access command approval", () => { ); assert.equal( ClaudeAdapterV2.claudeCommandApprovalDisposition({ - runtimeMode: "full-access", - interactionMode: "default", + runtimePolicy: policy({}), permissionMode: "bypassPermissions", toolName: "Bash", safetyReason: "A permission rule denies a command in this shell -c script", @@ -982,14 +997,50 @@ describe("ClaudeAdapterV2 full-access command approval", () => { ); assert.equal( ClaudeAdapterV2.claudeCommandApprovalDisposition({ - runtimeMode: "approval-required", - interactionMode: "default", + runtimePolicy: policy({ runtimeMode: "approval-required" }), + permissionMode: "default", + toolName: "Bash", + safetyReason: "", + }), + "ask", + ); + assert.equal( + ClaudeAdapterV2.claudeCommandApprovalDisposition({ + runtimePolicy: policy({ interactionMode: "plan" }), + permissionMode: "plan", + toolName: "Bash", + safetyReason: "", + }), + "ask", + ); + assert.equal( + ClaudeAdapterV2.claudeCommandApprovalDisposition({ + runtimePolicy: policy({ + approvalPolicy: "on-request", + sandboxPolicy: { + type: "readOnly", + access: { type: "fullAccess" }, + networkAccess: false, + }, + }), permissionMode: "default", toolName: "Bash", safetyReason: "", }), "ask", ); + assert.equal( + ClaudeAdapterV2.claudeCommandApprovalDisposition({ + runtimePolicy: policy({ + approvalPolicy: "never", + sandboxPolicy: { type: "readOnly", access: { type: "fullAccess" }, networkAccess: false }, + }), + permissionMode: "dontAsk", + toolName: "Bash", + safetyReason: "", + }), + "ask", + ); }); }); @@ -2091,7 +2142,7 @@ describe("ClaudeAdapterV2 resume compaction", () => { }, ), ); - assert.equal(mergeDecision.behavior, "allow"); + assert.equal(mergeDecision?.behavior, "allow"); const longQuestion = `Choose a deployment target: ${"region ".repeat(80)}`; const questionRequestEvent = yield* runtime.events.pipe( diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index c902cb72508fa..8da1e2f181440 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -3490,8 +3490,7 @@ function claudeBypassAvailability( } function requiresClaudeApproval(context: ActiveClaudeTurnContext): boolean { - // CLI-forwarded requests need a person's decision even under bypass (ask rules, - // safety checks, or settings fallback). Do not wait for queued init/status updates. + // Bypass still reaches the callback so a removal check or deny rule can fail closed. const policy = context.queryPolicy; return policy.installPermissionCallback || policy.permissionMode === "bypassPermissions"; } @@ -4281,8 +4280,7 @@ const CLAUDE_NO_STANDING_GRANT_OPTIONS = [ ] satisfies ReadonlyArray; export function claudeCommandApprovalDisposition(input: { - readonly runtimeMode: ProviderAdapter.ProviderAdapterV2RuntimePolicy["runtimeMode"]; - readonly interactionMode: ProviderAdapter.ProviderAdapterV2RuntimePolicy["interactionMode"]; + readonly runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy; readonly permissionMode: PermissionMode; readonly toolName: string; readonly safetyReason: string; @@ -4292,7 +4290,8 @@ export function claudeCommandApprovalDisposition(input: { (/^Dangerous rm(?:dir)?\b/i.test(input.safetyReason) || input.safetyReason === "This shell -c script runs rm and could not be checked" || input.safetyReason === "A permission rule denies a command in this shell -c script"); - const fullAccess = input.runtimeMode === "full-access" && input.interactionMode !== "plan"; + const fullAccess = + permissionModeForClaudeRuntimePolicy(input.runtimePolicy) === "bypassPermissions"; if (safetyDenial && (fullAccess || input.permissionMode === "bypassPermissions")) { return "deny"; } @@ -12255,8 +12254,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( ).trim(); // The SDK omits the CLI's dangerousRemoval discriminator, so match its removal warnings. const disposition = claudeCommandApprovalDisposition({ - runtimeMode: context.input.runtimePolicy.runtimeMode, - interactionMode: context.input.runtimePolicy.interactionMode, + runtimePolicy: context.input.runtimePolicy, permissionMode: activePermissionMode, toolName, safetyReason,