fix(orchestration): a reasonless allow keeps the person's refusal, and terminal checks no hook may approve are person-only

This commit is contained in:
Jinwoo-H
2026-11-11 21:52:20 -05:00
parent 0874d40663
commit a6c1ddcd3e
5 changed files with 58 additions and 8 deletions
@@ -58,18 +58,31 @@ export type TerminalWorkerApprovalHold = {
export type TerminalWorkerApprovalCloseHow = Pick<WorkerApprovalOutcome, 'by' | 'decision'>
/** 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<TerminalWorkerApprovalHold, 'summary'>): 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
@@ -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.
@@ -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(
@@ -15,7 +15,13 @@ export function workerApprovalAccess({
}: OrchestrationAccessRuleInput<z.infer<typeof ApprovalAnswerParams>>): 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 }
)
}
@@ -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',