Skip to content

Commit f0742da

Browse files
committed
revert: remove broken subagent permission auto-reject code
The task permission handling added in commits 6d65d0b..b5ba057 does not work. Rejecting crashes the task (Effect.orDie), aborting leaves the parent hanging, and promptAsync into the child session is unreliable. None of the approaches produce correct behavior, so remove all of it until OpenCode fixes task permission denial upstream (anomalyco/opencode#31108). Removed: - permission.asked event handling and auto-reject/abort/promptAsync logic from subagent-rate-limit-plugin.ts (reverted to rate-limit-only version) - getPermissionAskedEvent, getTaskLaunch, trackSubagentSession, abortSubagentSession helpers and unclaimed session tracking state - subagent-permission-auto-reject.e2e.test.ts (entire file) - 4 deterministic matchers in queue-advanced-e2e-setup.ts - dismiss-stale-permission-buttons: updatePermissionMessage export and auto-rejected button dismissal in thread-session-runtime.ts - 3 related changesets Kept logger.bindClient(client) from 9cddaaf since that is independently useful. Session: ses_159f8de9bffeqXb0B6Fy5j5Mqm
1 parent bdf5417 commit f0742da

8 files changed

Lines changed: 37 additions & 395 deletions

‎.changeset/abort-subagent-permissions.md‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎.changeset/dismiss-stale-permission-buttons.md‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎.changeset/test-subagent-permission-auto-reject.md‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎cli/src/commands/permissions.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export async function showPermissionButtons({
247247
return { messageId: permissionMessage.id, contextHash }
248248
}
249249

250-
export function updatePermissionMessage({
250+
function updatePermissionMessage({
251251
context,
252252
status,
253253
}: {

‎cli/src/queue-advanced-e2e-setup.ts‎

Lines changed: 1 addition & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -336,119 +336,7 @@ export function createDeterministicMatchers(): DeterministicMatcher[] {
336336
},
337337
}
338338

339-
const subagentPermissionTaskMatcher: DeterministicMatcher = {
340-
id: 'subagent-permission-auto-reject-task',
341-
priority: 112,
342-
when: {
343-
lastMessageRole: 'user',
344-
latestUserTextIncludes: 'SUBAGENT_PERMISSION_AUTO_REJECT_MARKER',
345-
},
346-
then: {
347-
parts: [
348-
{ type: 'stream-start', warnings: [] },
349-
{
350-
type: 'tool-call',
351-
toolCallId: 'subagent-permission-task-call',
352-
toolName: 'task',
353-
input: JSON.stringify({
354-
description: 'probe subagent permission rejection',
355-
subagent_type: 'general',
356-
prompt:
357-
'SUBAGENT_PERMISSION_CHILD_MARKER. Read /Users/morse/.zprofile with the read tool, then reply exactly: child-permission-finished.',
358-
}),
359-
},
360-
{
361-
type: 'finish',
362-
finishReason: 'tool-calls',
363-
usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
364-
},
365-
],
366-
},
367-
}
368339

369-
const subagentPermissionChildMatcher: DeterministicMatcher = {
370-
id: 'subagent-permission-auto-reject-child',
371-
priority: 112,
372-
when: {
373-
lastMessageRole: 'user',
374-
latestUserTextIncludes: 'SUBAGENT_PERMISSION_CHILD_MARKER',
375-
},
376-
then: {
377-
parts: [
378-
{ type: 'stream-start', warnings: [] },
379-
{ type: 'text-start', id: 'subagent-permission-child-start' },
380-
{
381-
type: 'text-delta',
382-
id: 'subagent-permission-child-start',
383-
delta: 'subagent requesting external read permission',
384-
},
385-
{ type: 'text-end', id: 'subagent-permission-child-start' },
386-
{
387-
type: 'tool-call',
388-
toolCallId: 'subagent-permission-read-call',
389-
toolName: 'read',
390-
input: JSON.stringify({ filePath: '/Users/morse/.zprofile' }),
391-
},
392-
{
393-
type: 'finish',
394-
finishReason: 'tool-calls',
395-
usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
396-
},
397-
],
398-
},
399-
}
400-
401-
const subagentPermissionChildFollowupMatcher: DeterministicMatcher = {
402-
id: 'subagent-permission-auto-reject-child-followup',
403-
priority: 112,
404-
when: {
405-
lastMessageRole: 'tool',
406-
latestUserTextIncludes: 'SUBAGENT_PERMISSION_CHILD_MARKER',
407-
},
408-
then: {
409-
parts: [
410-
{ type: 'stream-start', warnings: [] },
411-
{ type: 'text-start', id: 'subagent-permission-child-followup' },
412-
{
413-
type: 'text-delta',
414-
id: 'subagent-permission-child-followup',
415-
delta: 'child-permission-finished',
416-
},
417-
{ type: 'text-end', id: 'subagent-permission-child-followup' },
418-
{
419-
type: 'finish',
420-
finishReason: 'stop',
421-
usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
422-
},
423-
],
424-
},
425-
}
426-
427-
const subagentPermissionParentFollowupMatcher: DeterministicMatcher = {
428-
id: 'subagent-permission-auto-reject-parent-followup',
429-
priority: 112,
430-
when: {
431-
lastMessageRole: 'tool',
432-
latestUserTextIncludes: 'SUBAGENT_PERMISSION_AUTO_REJECT_MARKER',
433-
},
434-
then: {
435-
parts: [
436-
{ type: 'stream-start', warnings: [] },
437-
{ type: 'text-start', id: 'subagent-permission-parent-followup' },
438-
{
439-
type: 'text-delta',
440-
id: 'subagent-permission-parent-followup',
441-
delta: 'subagent-permission-auto-reject-done',
442-
},
443-
{ type: 'text-end', id: 'subagent-permission-parent-followup' },
444-
{
445-
type: 'finish',
446-
finishReason: 'stop',
447-
usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
448-
},
449-
],
450-
},
451-
}
452340

453341
const actionButtonClickFollowupMatcher: DeterministicMatcher = {
454342
id: 'action-button-click-followup',
@@ -876,10 +764,7 @@ export function createDeterministicMatchers(): DeterministicMatcher[] {
876764
permissionTypingFollowupMatcher,
877765
channelReferencePermissionMatcher,
878766
channelReferencePermissionFollowupMatcher,
879-
subagentPermissionTaskMatcher,
880-
subagentPermissionChildMatcher,
881-
subagentPermissionChildFollowupMatcher,
882-
subagentPermissionParentFollowupMatcher,
767+
883768
multiToolMatcher,
884769
multiToolFollowupMatcher,
885770
undoFileMatcher,

‎cli/src/session-handler/thread-session-runtime.ts‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ import {
6565
addPermissionRequestToContext,
6666
arePatternsCoveredBy,
6767
pendingPermissionContexts,
68-
updatePermissionMessage,
6968
} from '../commands/permissions.js'
7069
import {
7170
showAskUserQuestionDropdowns,
@@ -2485,27 +2484,8 @@ export class ThreadSessionRuntime {
24852484
if (!pending) {
24862485
return
24872486
}
2488-
// Get the permission context before deleting it — needed to update the
2489-
// Discord message when a plugin (e.g. subagent-rate-limit-plugin) auto-
2490-
// rejected the permission instead of the user clicking a button.
2491-
const permissionContext = pendingPermissionContexts.get(pending.contextHash)
24922487
pendingPermissionContexts.delete(pending.contextHash)
24932488
threadPermissions.delete(properties.requestID)
2494-
2495-
if (permissionContext?.messageId) {
2496-
const statusText = properties.reply === 'reject'
2497-
? '❌ Permission **auto-rejected**'
2498-
: properties.reply === 'once'
2499-
? '✅ Permission **accepted**'
2500-
: properties.reply === 'always'
2501-
? '✅ Permission **accepted** (auto-approve similar requests)'
2502-
: `_Permission replied: ${properties.reply}_`
2503-
updatePermissionMessage({
2504-
context: permissionContext,
2505-
status: statusText,
2506-
})
2507-
}
2508-
25092489
if (threadPermissions.size === 0) {
25102490
pendingPermissions.delete(this.thread.id)
25112491
}

‎cli/src/subagent-permission-auto-reject.e2e.test.ts‎

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)