Repository navigation
fix(code-sdk-python): README stream loop keeps item.started deltas; SyncMCode raises once in a running loop - #590
Merged
Conversation
… quiet SyncMCode in a running loop
- README streaming example reads contentDelta from any agent_message item event
(the CLI puts the first delta on item.started) and uses event.get("item") so
pyright's default mode passes.
- SyncMCode/SyncThread called inside a running event loop raise one RuntimeError,
close the un-run coroutine, and close() no longer raises a second error.
- Annotate MCodeError.items.
1anZhang
approved these changes
Nov 4, 2026
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.
Two problems found while testing minimax-code-sdk 0.1.0 from PyPI against mcode 0.6.5 and a real model.
A. README streaming example loses text
The CLI can put the first (or only)
contentDeltaof anagent_messageonitem.started. The README loop only readitem.updated, so it missed that text. A short reply printed nothing at all:event["item"]in the same example also fails pyright's default mode (reportTypedDictNotRequiredAccess).Fix: the README example now uses
event.get("item")and readscontentDeltafrom anyagent_messageitem event, the same wayexamples/streaming.pyalready does. I left the event stream itself alone and did not add a syntheticitem.updatedevent: the README and the TS SDK both promise events "passed through unchanged", the TS types already saycontentDeltacan be onitem.started, and a synthetic event would need an inventedsequence. The TS README example readsitem.completed, so it doesn't have this problem.B. SyncMCode inside a running event loop raised twice
with SyncMCode() as c: c.start_thread().run("x")insideasync defraised the expected RuntimeError. Then__exit__->close()raised a second RuntimeError, andcoroutine 'Thread.run' was never awaited/coroutine 'sleep' was never awaitedwarnings were left behind.Fix: the sync wrappers check for a running loop before they run anything. They close the coroutine that didn't run and raise one RuntimeError that points to the async API. In that case
close()just closes the private loop without running it.Also:
MCodeError.itemsis now annotated aslist[ThreadItem].Tests
test_readme_streaming_loop_keeps_delta_on_item_started: fake CLI sends the delta onitem.started, and the README loop gets"Hello".test_sync_client_inside_running_loop_raises_once: exactly one RuntimeError and no RuntimeWarning. This test fails on main.uv sync --locked,ruff check,ruff format --check,mypy, andpytest -W errorall pass (59 passed, 3 skipped). Opt-in e2e streaming against a real model passes.Out of scope
There is a separate CLI-side problem. A workspace mismatch on
--session, or a model that isn't available, endsmcode exec(exit 4) withoutexec.completed, and the message ends with "Retry after the connection recovers", which is misleading. The SDK then reports "ended without a result". That is tracked separately.No version bump and no release.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.