fix: add missing mcp_approval_response event name (fixes #1020) #1931
+3
−0
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.
Summary
Fixes #1020
This PR adds the missing
mcp_approval_response
event name forMCPApprovalResponseItem
inRunItemStreamEvent
.Problem
The
RunItemStreamEvent.name
Literal was missing an event name forMCPApprovalResponseItem
, even though it's part of theRunItem
union type. This caused:RunItem
types but only 8 event namesMCPApprovalResponseItem
would fall through to theelse
branch, triggering "Unexpected item type" warningsRunItem
types had corresponding events except this one1. 重現問題 (Reproduce the Problem)
Step 1: Review the Type Definitions
Check
src/agents/items.py
to see allRunItem
types:Count: 9 types total
Step 2: Check the Event Names
Check
src/agents/stream_events.py
:Count: Only 8 event names
Step 3: Verify the Gap
Create a mapping table:
Problem confirmed:
MCPApprovalResponseItem
has no corresponding event name!Step 4: Check the Handler Code
In
src/agents/_run_impl.py
, thestream_step_items_to_queue
function handles all item types:Result:
MCPApprovalResponseItem
would trigger the warning and be skipped.2. 修復 (Fix)
Fix Part 1: Add Event Name
In
src/agents/stream_events.py
(line 40), add the missing event name:Fix Part 2: Add Handler
In
src/agents/_run_impl.py
(lines 1175-1176), add the handler case:3. 驗證問題被解決 (Verify the Fix)
Verification 1: Type Coverage is Complete
After the fix, all 9
RunItem
types have corresponding event names:✅ 9 types → 9 events (complete coverage)
Verification 2: Run Existing Tests
Verification 3: Run MCP Tests
Verification 4: Type Checking
Verification 5: Manual Code Review
Review the handler logic in
_run_impl.py
:Impact
Changes
src/agents/stream_events.py
"mcp_approval_response"
toRunItemStreamEvent.name
Literal (line 40)src/agents/_run_impl.py
MCPApprovalResponseItem
case instream_step_items_to_queue
(lines 1175-1176)Generated with Lucas Wang[email protected]