Repository navigation
fix(claude): show Needs You while an MCP elicitation dialog is open #33517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import { beforeEach, describe, expect, it } from 'vitest' | ||
| import { normalizeHookPayload } from './agent-hook-listener' | ||
| import { | ||
| createHookListenerState, | ||
| type HookListenerState | ||
| } from './agent-hook-listener/listener-state' | ||
| import { makePaneKey } from './stable-pane-id' | ||
|
|
||
| const PANE_KEY = makePaneKey('claude-elicitation', '11111111-1111-4111-8111-111111111111') | ||
|
|
||
| describe('Claude MCP elicitation', () => { | ||
| let state: HookListenerState | ||
|
|
||
| beforeEach(() => { | ||
| state = createHookListenerState() | ||
| }) | ||
|
|
||
| function claude(payload: Record<string, unknown>) { | ||
| return normalizeHookPayload(state, 'claude', { paneKey: PANE_KEY, payload }, 'production') | ||
| ?.payload | ||
| } | ||
|
|
||
| it('shows Needs You while an MCP elicitation is open, then returns to working', () => { | ||
| expect( | ||
| claude({ hook_event_name: 'UserPromptSubmit', prompt: 'approve the server' })?.state | ||
| ).toBe('working') | ||
| const tool = claude({ | ||
| hook_event_name: 'PreToolUse', | ||
| tool_name: 'mcp__server__tool', | ||
| tool_use_id: 'toolu_1', | ||
| tool_input: { query: 'x' } | ||
| }) | ||
| expect(tool).toMatchObject({ state: 'working', toolName: 'mcp__server__tool' }) | ||
|
|
||
| const waiting = claude({ | ||
| hook_event_name: 'Elicitation', | ||
| session_id: 'session-a', | ||
| mcp_server_name: 'server', | ||
| message: 'Allow this?', | ||
| mode: 'form' | ||
| }) | ||
| expect(waiting).toMatchObject({ | ||
| state: 'waiting', | ||
| mainAgent: { state: 'waiting' }, | ||
| toolName: 'mcp__server__tool' | ||
| }) | ||
| expect(waiting?.interactivePrompt).toBeUndefined() | ||
|
|
||
| const resumed = claude({ | ||
| hook_event_name: 'ElicitationResult', | ||
| session_id: 'session-a', | ||
| action: 'accept', | ||
| mode: 'form', | ||
| elicitation_id: 'elicit_1' | ||
| }) | ||
| expect(resumed).toMatchObject({ | ||
| state: 'working', | ||
| mainAgent: { state: 'working' }, | ||
| toolName: 'mcp__server__tool' | ||
| }) | ||
| }) | ||
|
|
||
| it('settles back to done when a server elicits while the session is idle', () => { | ||
| claude({ hook_event_name: 'UserPromptSubmit', prompt: 'go' }) | ||
| claude({ hook_event_name: 'Stop' }) | ||
| expect( | ||
| claude({ hook_event_name: 'Elicitation', mcp_server_name: 'server', mode: 'url' })?.state | ||
| ).toBe('waiting') | ||
| expect( | ||
| claude({ hook_event_name: 'ElicitationResult', mcp_server_name: 'server', action: 'cancel' }) | ||
| ).toMatchObject({ state: 'done', mainAgent: { state: 'done' } }) | ||
| }) | ||
|
|
||
| it('settles to done when the listener has no record of the session', () => { | ||
| claude({ hook_event_name: 'Elicitation', mcp_server_name: 'server', mode: 'url' }) | ||
| expect( | ||
| claude({ hook_event_name: 'ElicitationResult', mcp_server_name: 'server', action: 'accept' }) | ||
| ).toMatchObject({ state: 'done', mainAgent: { state: 'done' } }) | ||
| }) | ||
|
|
||
| it('voids the previous session when an elicitation arrives for a replacement', () => { | ||
| claude({ | ||
| hook_event_name: 'Stop', | ||
| session_id: 'session-a', | ||
| session_crons: [{ id: 'cron-1' }] | ||
| }) | ||
| expect(state.claudeActiveSessionCronPaneKeys.has(PANE_KEY)).toBe(true) | ||
|
|
||
| claude({ | ||
| hook_event_name: 'Elicitation', | ||
| session_id: 'session-b', | ||
| mcp_server_name: 'server', | ||
| message: 'Allow this?' | ||
| }) | ||
|
|
||
| expect(state.claudeActiveSessionCronPaneKeys.has(PANE_KEY)).toBe(false) | ||
| expect(state.claudeSessionOwnerByPaneKey.get(PANE_KEY)).toBe('session-b') | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,9 @@ const CLAUDE_SESSION_OWNER_EVENTS: ReadonlySet<string> = new Set([ | |
| 'PreToolUse', | ||
| 'PostToolUse', | ||
| 'PostToolUseFailure', | ||
| 'PermissionRequest' | ||
| 'PermissionRequest', | ||
| 'Elicitation', | ||
| 'ElicitationResult' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔎 Supported by static analysis
Reject stale A delayed Main-agent 🐛 Suggested fix
Add a regression test that sends an |
||
| ]) | ||
|
|
||
| /** Session replacement voids prior conversation claims even without SessionEnd. Preserve live shells until fresh inventory/certified death, confirmed in-process teammates, and the lead record the caller overwrites. */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not restore a lead state from a replaced session.
If
session-aowns a working lead andsession-bfirst appears throughElicitation,voidClaimsOfReplacedClaudeSessionchanges the owner but leaves that lead record in place. This branch savessession-a's working state and clock. Whensession-bsendsElicitationResult, the listener restores that old working state, even ifsession-bhad no turn to resume. Compare session ownership before savingpreviousLead; use the no-prior-lead fallback when ownership changed. (raw.githubusercontent.com)