Skip to content

Keep stdin open for empty resumed SDK MCP input - #1227

Draft
lakshminarayanannn wants to merge 1 commit into
anthropics:mainfrom
lakshminarayanannn:codex/fix-empty-resume-sdk-mcp-input
Draft

Keep stdin open for empty resumed SDK MCP input#1227
lakshminarayanannn wants to merge 1 commit into
anthropics:mainfrom
lakshminarayanannn:codex/fix-empty-resume-sdk-mcp-input

Conversation

@lakshminarayanannn

Copy link
Copy Markdown

Summary

  • keep stdin open when an empty async prompt resumes a conversation that still needs bidirectional control responses
  • preserve immediate close for new empty streams and prompt iterators that fail before writing
  • cover the deferred SDK MCP handshake and both resume-aware client paths

Fixes #1226

Root cause

The zero-message branch added in 0.2.140 called transport.end_input() directly. That is correct for a new empty conversation, but a resumed deferred SDK MCP tool can issue a control request without a new user message. Closing stdin first made the SDK control response fail and the CLI returned tool_deferred_unavailable.

Test plan

  • uv run python -m pytest tests/test_query.py::TestAsyncIterablePromptWithSdkMcpServers tests/test_query.py::TestCanUseToolKeepsStdinOpen::test_prompt_iterable_that_raises_immediately_closes_stdin -q — 7 passed
  • uv run python -m pytest tests/ — 1488 passed, 6 skipped
  • uv run python -m ruff check src/ tests/ scripts/ — passed
  • uv run python -m ruff format src/ tests/ scripts/ --check — passed
  • uv run python -m mypy src/ scripts/ — passed
  • repeated the full unit, lint, format, and typecheck gates from a fresh clone at eca4a1ca508f090d8a53aa6201f9c734da9c641b
  • ran the issue reproducer against current main: leg 2 returned tool_deferred_unavailable, is_error=True, duration_api_ms=0
  • ran the same reproducer with this patch: leg 1 returned tool_deferred; leg 2 returned end_turn, is_error=False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDK MCP tools unavailable when resuming with empty streaming input (regression in 0.2.140)

1 participant