Repository navigation
fix(questions): stop background subagents denying the main thread's question (#340) - #345
Merged
Merged
Conversation
…g agent Background subagents report under their parent's session_id. Every per-session drain treated them as the parent, so while the main thread's AskUserQuestion card was up, a subagent's PostToolUse or SubagentStop (the wasWaiting sweep), its own PermissionRequest or question, or its hook socket dropping denied the question. Claude reports that as "Permission denied by hook" and falls back to asking in plain text (wxtsky#340). Each drain now takes an event filter, and every caller reacting to one agent's activity passes an agent_id match. Peer disconnects carry the agent_id of the connection that dropped, and leave the session waiting when another agent's request is still queued. Terminal answers still clear the card: the main thread's own PostToolUse matches its question. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Owner
|
Merged (1cecfc5) — thank you. Tracing the deny to |
wxtsky
added a commit
that referenced
this pull request
Sep 23, 2026
…333) With two sessions waiting on AskUserQuestion, answering the first card and then the second sent the second session the first answer - the report's "是否立即触发构建? → openURL 传裸路径". Root cause: QuestionBar kept its wizard state (current question index, collected answers, selection, typed text) in @State, and nothing tied that state to the request it was collected for. The card slot renders `case .questionCard(sid)` -> `QuestionBar(...)` with no `.id`, so when answering session A's card makes showNextPending() promote session B (surface .questionCard(A) -> .questionCard(B) in one transaction), SwiftUI keeps the same view and hands B the old @State. advance() never cleared collectedAnswers after the final submit, so B's answer was appended behind A's and B's card submitted [a1, b1]. answerQuestionMulti maps answers onto items by position, so B's only question got a1. The #310 session routing was right throughout: the right continuation received the wrong payload. The state has been unkeyed since the wizard was introduced, so this is not a regression of #310/#320/#345. - QuestionRequest gets a per-request `id`, and the card is `.id(q.id)`: each request gets a fresh view and fresh state. - The wizard state moves into QuestionWizardState, bound to that id. Recording for a different request starts over, and the final answer is not retained, so a retried submit cannot accumulate either. - answerQuestionMulti refuses an answer set that is not exactly one answer per question of the target request (count and question text) instead of mapping it by position, so a future view-state bug leaves the card waiting rather than answering another session's question. Tests reproduce the report end to end (two sessions, one wizard state carried across the card swap; on the old logic the second session gets "是否立即触发构建(含后续飞书通知)?: openURL 传裸路径"), and pin the wizard reducer, per-request card identity and the model-side refusal. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #340.
Problem
Background subagents report under their parent's
session_id. CodeIsland's per-session drains treated a subagent's events as the parent's, so while the main thread'sAskUserQuestioncard was on screen, the question was denied. Claude Code shows this asPermission denied by hook, and the agent then falls back to asking in plain text.Seen in the unified log: a question asked at 13:54:19 was denied 1.3 s later by a background agent's
SubagentStop:A long-running background agent sends events continuously, so every question in that session gets denied. That matches the "always denied" report in #340.
Every drain path had the same blind spot:
handleEventwasWaiting sweepPostToolUse,SubagentStop, …handlePermissionRequestPermissionRequesthandleAskUserQuestion/handleQuestionhandlePeerDisconnectFix
drainQuestions/drainPermissionstake an event filter, and each of the paths above passes anagent_idmatch. Requests stay mutually exclusive within one agent, as before.monitorPeerDisconnectcarries theagent_idof the connection. The session stays waiting if another agent's request is still queued.PostToolUse(AskUserQuestion)matches its question.This is the question-side counterpart of #147, which made the same change for permissions.
Tests
testSubagentActivityDoesNotDenyMainThreadQuestionfails onmainand passes with this change.testSubagentRequestsAndDisconnectsDoNotDenyMainThreadQuestioncovers the permission-request, question, and disconnect paths.AppStateGitBranchTests.testBranchRefreshesOnStopAfterSwitch, times out under full-suite load on unmodifiedmaintoo, and passes when run alone.🤖 Generated with Claude Code