From a6c1ddcd3e19a4ed80f4e3a821e0707dfd2ba013 Mon Sep 17 00:00:00 2001 From: Jinwoo-H Date: Wed, 11 Nov 2026 21:12:57 -0500 Subject: [PATCH] fix(orchestration): a reasonless allow keeps the person's refusal, and terminal checks no hook may approve are person-only --- .../terminal-worker-approval-hold.ts | 20 +++++++++++--- .../terminal-worker-approval-holds.test.ts | 27 +++++++++++++++++++ .../terminal-worker-approval-holds.ts | 4 +++ .../worker/worker-approval-access.ts | 12 ++++++--- .../worker/worker-approval-answer.test.ts | 3 ++- 5 files changed, 58 insertions(+), 8 deletions(-) diff --git a/src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-hold.ts b/src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-hold.ts index 4b413eb7566..6c857918d40 100644 --- a/src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-hold.ts +++ b/src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-hold.ts @@ -58,18 +58,31 @@ export type TerminalWorkerApprovalHold = { export type TerminalWorkerApprovalCloseHow = Pick -/** Claude dropped Orca's allow and still asks: some checks only a person at the terminal may approve. */ +// Claude's words for a check no hook may approve (2.1.322 strings: "allow rules, hooks and plugins +// cannot approve it", "hooks cannot approve …"); its dialog shows them as the warning. +const HOOKS_CANNOT_APPROVE = /\bhooks\b[^.]*\bcannot (?:approve|grant)\b/i + +/** Claude lets only a person at its terminal allow this prompt. */ +export function holdIsPersonOnly(hold: Pick): boolean { + return HOOKS_CANNOT_APPROVE.test(hold.summary.reason ?? '') +} + +/** An allow Claude will not take: its check is one only a person at the terminal may approve, or it + * dropped Orca's allow and still asks. */ export function droppedAllowRefusal( hold: TerminalWorkerApprovalHold, input: { approvalId: string; decision: 'allow' | 'deny' } ): TerminalWorkerApprovalAnswer | null { - if (input.decision !== 'allow' || hold.closedAs?.by !== 'terminal-only') { + if ( + input.decision !== 'allow' || + (hold.closedAs?.by !== 'terminal-only' && !holdIsPersonOnly(hold)) + ) { return null } return { ok: false, code: 'approval_requires_person', - message: `Claude did not take the allow for ${input.approvalId} and still asks in the worker's terminal: it lets only a person approve this one there, so it stays with the user.` + message: `Claude lets only a person approve ${input.approvalId}, in the worker's terminal, so it stays with the user.` } } @@ -89,6 +102,7 @@ export function holdPayload( worker: { handle: hold.handle, dispatchId: hold.dispatch.id, taskId: hold.dispatch.task_id }, summary: hold.summary, allowedActions: ['allow', 'deny'], + ...(holdIsPersonOnly(hold) ? { personOnly: true } : {}), ...(hold.expiresAt ? { expiresAt: hold.expiresAt } : {}) } return outcome ? closedApproval(open, outcome) : open diff --git a/src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-holds.test.ts b/src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-holds.test.ts index 6f72ff6cdf3..105c4d6b786 100644 --- a/src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-holds.test.ts +++ b/src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-holds.test.ts @@ -219,6 +219,33 @@ describe('terminal worker approval holds', () => { expect(ctx.closedWith()[0]).toMatchObject({ state: 'answered', by: 'unknown' }) }) + it('marks a check Claude lets no hook approve as person-only, and refuses an allow without spending the hook', async () => { + const ctx = setup() + ctx.screen.lines = [ + ' Bash command', + ' │ rm -rf build', + ' ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌', + " │ Bash may act on this session's desktop, so each call is reviewed; allow rules, hooks and plugins cannot approve it.", + ...DIALOG.slice(3) + ] + const asked = hook('tool-1', () => { + ctx.screen.lines = AFTER + ctx.screen.record = record(OURS, 'deny') + }) + ctx.holds.admit(asked.request) + await ctx.tick() + const escalated = await ctx.holds.takeOpenApproval(PANE, ctx.dispatch.id) + const approvalId = escalated!.approvalId + + expect(escalated).toMatchObject({ personOnly: true }) + expect(await answer(ctx, approvalId, 'allow')).toMatchObject({ + ok: false, + code: 'approval_requires_person' + }) + expect(asked.replies).toEqual([]) + expect(await deny(ctx, approvalId)).toMatchObject({ ok: true }) + }) + it('refuses an allow Claude drops while its dialog stays, and leaves the prompt with the person', async () => { const ctx = setup() // A check only a person may approve: Claude ignores a hook's allow and keeps asking. diff --git a/src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-holds.ts b/src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-holds.ts index 1212d5be276..befdb7eb289 100644 --- a/src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-holds.ts +++ b/src/main/runtime/orchestration/workers/approvals/terminal-worker-approval-holds.ts @@ -188,6 +188,10 @@ export class TerminalWorkerApprovalHolds implements ClaudePermissionHolds { if (hold.state !== 'open' || !before || !showsClaudeDialog(before)) { return notOpen } + const personOnly = droppedAllowRefusal(hold, input) + if (personOnly) { + return personOnly + } hold.state = 'answering' hold.timer?.cancel() const written = await hold.channel.answer( diff --git a/src/main/runtime/rpc/methods/orchestration/worker/worker-approval-access.ts b/src/main/runtime/rpc/methods/orchestration/worker/worker-approval-access.ts index 6b172160dab..12d5357aa1b 100644 --- a/src/main/runtime/rpc/methods/orchestration/worker/worker-approval-access.ts +++ b/src/main/runtime/rpc/methods/orchestration/worker/worker-approval-access.ts @@ -15,7 +15,13 @@ export function workerApprovalAccess({ }: OrchestrationAccessRuleInput>): WorkerApprovalAccess { const person = ctx.caller?.kind === 'desktop' const reason = params.reason?.trim() || null - if (params.decision === 'allow' && !person && !ctx.runtime.coordinatorApprovalsEnabled()) { + // Without a reason it is not a coordinator's approve: a person on a remote-connected desktop + // sends none, and keeps the refusal they always got. + if ( + params.decision === 'allow' && + !person && + !(reason && ctx.runtime.coordinatorApprovalsEnabled()) + ) { throw new OrchestrationError( 'approval_requires_person', `Only a person can allow ${params.prompt}, from Orca or the worker itself. You can deny it with a reason, or leave it for the person.`, @@ -25,9 +31,7 @@ export function workerApprovalAccess({ if (!person && !reason) { throw new OrchestrationError( 'invalid_argument', - params.decision === 'allow' - ? 'Missing --reason: say why you approve it.' - : 'Missing --reason: tell the worker what to do instead.', + 'Missing --reason: tell the worker what to do instead.', { effectsApplied: false } ) } diff --git a/src/main/runtime/rpc/methods/orchestration/worker/worker-approval-answer.test.ts b/src/main/runtime/rpc/methods/orchestration/worker/worker-approval-answer.test.ts index 3c77acc1b24..cb1f130caef 100644 --- a/src/main/runtime/rpc/methods/orchestration/worker/worker-approval-answer.test.ts +++ b/src/main/runtime/rpc/methods/orchestration/worker/worker-approval-answer.test.ts @@ -334,7 +334,8 @@ const ROWS: Row[] = [ decision: 'allow', worker: 'chat', meanwhile: 'takes it', - expected: { code: 'invalid_argument', closing: [] } + // A person on a remote-connected desktop sends no reason: the refusal they always got. + expected: { code: 'approval_requires_person', closing: [] } }, { setting: 'on',