Skip to content

Commit 6b8e026

Browse files
remorseszpetterd
authored andcommitted
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 34160d8 commit 6b8e026

8 files changed

Lines changed: 39 additions & 393 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
@@ -237,7 +237,7 @@ export async function showPermissionButtons({
237237
return { messageId: permissionMessage.id, contextHash }
238238
}
239239

240-
export function updatePermissionMessage({
240+
function updatePermissionMessage({
241241
context,
242242
status,
243243
}: {

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

Lines changed: 4 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -337,119 +337,6 @@ export function createDeterministicMatchers(): DeterministicMatcher[] {
337337
}
338338

339339

340-
const subagentPermissionTaskMatcher: DeterministicMatcher = {
341-
id: 'subagent-permission-auto-reject-task',
342-
priority: 112,
343-
when: {
344-
lastMessageRole: 'user',
345-
latestUserTextIncludes: 'SUBAGENT_PERMISSION_AUTO_REJECT_MARKER',
346-
},
347-
then: {
348-
parts: [
349-
{ type: 'stream-start', warnings: [] },
350-
{
351-
type: 'tool-call',
352-
toolCallId: 'subagent-permission-task-call',
353-
toolName: 'task',
354-
input: JSON.stringify({
355-
description: 'probe subagent permission rejection',
356-
subagent_type: 'general',
357-
prompt:
358-
'SUBAGENT_PERMISSION_CHILD_MARKER. Read /Users/morse/.zprofile with the read tool, then reply exactly: child-permission-finished.',
359-
}),
360-
},
361-
{
362-
type: 'finish',
363-
finishReason: 'tool-calls',
364-
usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
365-
},
366-
],
367-
},
368-
}
369-
370-
const subagentPermissionChildMatcher: DeterministicMatcher = {
371-
id: 'subagent-permission-auto-reject-child',
372-
priority: 112,
373-
when: {
374-
lastMessageRole: 'user',
375-
latestUserTextIncludes: 'SUBAGENT_PERMISSION_CHILD_MARKER',
376-
},
377-
then: {
378-
parts: [
379-
{ type: 'stream-start', warnings: [] },
380-
{ type: 'text-start', id: 'subagent-permission-child-start' },
381-
{
382-
type: 'text-delta',
383-
id: 'subagent-permission-child-start',
384-
delta: 'subagent requesting external read permission',
385-
},
386-
{ type: 'text-end', id: 'subagent-permission-child-start' },
387-
{
388-
type: 'tool-call',
389-
toolCallId: 'subagent-permission-read-call',
390-
toolName: 'read',
391-
input: JSON.stringify({ filePath: '/Users/morse/.zprofile' }),
392-
},
393-
{
394-
type: 'finish',
395-
finishReason: 'tool-calls',
396-
usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
397-
},
398-
],
399-
},
400-
}
401-
402-
const subagentPermissionChildFollowupMatcher: DeterministicMatcher = {
403-
id: 'subagent-permission-auto-reject-child-followup',
404-
priority: 112,
405-
when: {
406-
lastMessageRole: 'tool',
407-
latestUserTextIncludes: 'SUBAGENT_PERMISSION_CHILD_MARKER',
408-
},
409-
then: {
410-
parts: [
411-
{ type: 'stream-start', warnings: [] },
412-
{ type: 'text-start', id: 'subagent-permission-child-followup' },
413-
{
414-
type: 'text-delta',
415-
id: 'subagent-permission-child-followup',
416-
delta: 'child-permission-finished',
417-
},
418-
{ type: 'text-end', id: 'subagent-permission-child-followup' },
419-
{
420-
type: 'finish',
421-
finishReason: 'stop',
422-
usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
423-
},
424-
],
425-
},
426-
}
427-
428-
const subagentPermissionParentFollowupMatcher: DeterministicMatcher = {
429-
id: 'subagent-permission-auto-reject-parent-followup',
430-
priority: 112,
431-
when: {
432-
lastMessageRole: 'tool',
433-
latestUserTextIncludes: 'SUBAGENT_PERMISSION_AUTO_REJECT_MARKER',
434-
},
435-
then: {
436-
parts: [
437-
{ type: 'stream-start', warnings: [] },
438-
{ type: 'text-start', id: 'subagent-permission-parent-followup' },
439-
{
440-
type: 'text-delta',
441-
id: 'subagent-permission-parent-followup',
442-
delta: 'subagent-permission-auto-reject-done',
443-
},
444-
{ type: 'text-end', id: 'subagent-permission-parent-followup' },
445-
{
446-
type: 'finish',
447-
finishReason: 'stop',
448-
usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
449-
},
450-
],
451-
},
452-
}
453340

454341
const actionButtonClickFollowupMatcher: DeterministicMatcher = {
455342
id: 'action-button-click-followup',
@@ -877,6 +764,10 @@ export function createDeterministicMatchers(): DeterministicMatcher[] {
877764
permissionTypingFollowupMatcher,
878765
channelReferencePermissionMatcher,
879766
channelReferencePermissionFollowupMatcher,
767+
<<<<<<< HEAD
768+
=======
769+
770+
>>>>>>> f0742da (revert: remove broken subagent permission auto-reject code)
880771
multiToolMatcher,
881772
multiToolFollowupMatcher,
882773
undoFileMatcher,
@@ -906,10 +797,6 @@ export const TEST_USER_ID = '200000000000000991'
906797
* Sets up a full queue-advanced e2e environment: digital-twin Discord server,
907798
* opencode deterministic provider, database, bot client.
908799
* Each caller should use a unique channelId and dirName to avoid collisions
909-
* when vitest runs files in parallel.
910-
*/
911-
export function setupQueueAdvancedSuite({
912-
channelId,
913800
channelName,
914801
extraChannels = [],
915802
dirName,

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ import {
5858
addPermissionRequestToContext,
5959
arePatternsCoveredBy,
6060
pendingPermissionContexts,
61-
updatePermissionMessage,
6261
} from '../commands/permissions.js'
6362
import {
6463
showAskUserQuestionDropdowns,
@@ -2393,27 +2392,8 @@ export class ThreadSessionRuntime {
23932392
if (!pending) {
23942393
return
23952394
}
2396-
// Get the permission context before deleting it — needed to update the
2397-
// Discord message when a plugin (e.g. subagent-rate-limit-plugin) auto-
2398-
// rejected the permission instead of the user clicking a button.
2399-
const permissionContext = pendingPermissionContexts.get(pending.contextHash)
24002395
pendingPermissionContexts.delete(pending.contextHash)
24012396
threadPermissions.delete(properties.requestID)
2402-
2403-
if (permissionContext?.messageId) {
2404-
const statusText = properties.reply === 'reject'
2405-
? '❌ Permission **auto-rejected**'
2406-
: properties.reply === 'once'
2407-
? '✅ Permission **accepted**'
2408-
: properties.reply === 'always'
2409-
? '✅ Permission **accepted** (auto-approve similar requests)'
2410-
: `_Permission replied: ${properties.reply}_`
2411-
updatePermissionMessage({
2412-
context: permissionContext,
2413-
status: statusText,
2414-
})
2415-
}
2416-
24172397
if (threadPermissions.size === 0) {
24182398
pendingPermissions.delete(this.thread.id)
24192399
}

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

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

0 commit comments

Comments
 (0)