Skip to content

[Windows] The Python SDK's process layer is never exercised on Windows: 25 test cases are skipped, and a cancelled run is reported as an internal failure instead of a cancellation #620

Open

Description

@Ralle1976

Labels requested: bug, needs-triage, cli

Product or interface

Source build or repository tooling — the Python SDK minimax-code-sdk (0.1.1 on PyPI) that starts, cancels and reaps the mcode CLI on the host.

Version

  • Source: main @ 3c21163 (repository version 0.7.2), tag v0.7.2 = c6c7f28
  • SDK package: minimax-code-sdk 0.1.1 (PyPI, published 2026-11-17), source tag code-sdk-python-v0.1.1
  • Python 3.12.10 (Windows) / 3.11.2 (Linux), Node.js v24.18.0 (Windows) / v20.20.2 (Linux), pnpm 9.15.0

Platform

Windows

OS version and architecture

Windows 11 x64 (build 26200)

Issue area

Build / CI / source distribution

What happens

The Windows leg of the Python SDK workflow is green, but it never starts a CLI process. The whole fake-CLI test suite is skipped on Windows, so the process layer of the SDK — spawn, stream, cancel, timeout, reap — has never run on the platform where it behaves differently. Two consequences:

1. The Windows CI line proves nothing about the SDK's process handling.
packages/code-sdk-python/tests/conftest.py:14 skips every test that uses the fake_env fixture:

if sys.platform == "win32":
    pytest.skip("the fake CLI is a POSIX script; Windows runs the resolver and option tests")

That is 25 test cases in packages/code-sdk-python/tests/test_sdk.py (22 of its 27 test functions). The whole suite reports 34 passed, 30 skipped on Windows, and the 3 remaining skips are the opt-in end-to-end tests. The other Windows coverage is the launcher resolution (tests/test_cli.py) and the release checks (tests/test_release_check.py); neither starts a process. The workflow comment says the same ( .github/workflows/python-sdk.yml:28: "fake-CLI process tests are POSIX-only").

2. A cancelled Turn is reported as a failed run on Windows, and as a cancellation on Linux and macOS.
This is the part the skipped suite hides. packages/code-sdk-python/src/minimax_code/thread.py:244 stops the CLI with a hard kill on Windows, because Windows has no signals between processes:

if sys.platform == "win32":
    self.proc.terminate()      # TerminateProcess -> exit code 1
else:
    self.proc.send_signal(signal.SIGTERM)   # exit code -15

packages/code-sdk-python/src/minimax_code/errors.py:129 maps that exit code to an error, and the mapping only knows the cancellation exit codes 130 and "negative means killed by a signal" (errors.py:155). On Windows the exit code is 1, so the run is reported as an internal failure:

Linux / macOS Windows
CLI stopped with SIGTERM (exit -15) TerminateProcess (exit 1)
SDK raises MCodeAbortError: The MCode run was cancelled. MCodeRunError: The MCode run ended without a result: exit code 1 (status="failed", category="internal")

The TypeScript SDK, which the Python SDK states it mirrors (packages/code-sdk-python/src/minimax_code/thread.py:1), handles this case explicitly — packages/code-sdk/src/exec-process.ts:323:

if (this.abortRequested && code !== 2) {
  this.fail(new MCodeAbortError('The MCode run was cancelled.', details));
  return;
}

The Python SDK has no equivalent of abortRequested, so on Windows the cancellation is indistinguishable from a CLI crash. MCodeAbortError is a documented error type of the package (packages/code-sdk-python/README.md:127) and is what a user gets for the same action on Linux and macOS.

Steps to reproduce

  1. Run the Python SDK test suite on a Windows host and read the skip reasons:

    python -m pytest packages/code-sdk-python/tests -q -rs
    SKIPPED [1] tests/test_sdk.py:39: the fake CLI is a POSIX script; Windows runs the resolver and option tests
    ... (25 test cases)
    34 passed, 30 skipped
    
  2. Reproduce the divergence. Save this as repro_cancel.py in the repository root and run python repro_cancel.py (needs Node.js, the mcode CLI is a Node program anyway):

    import asyncio
    import os
    import pathlib
    import sys
    
    sys.path.insert(0, "packages/code-sdk-python/src")
    
    from minimax_code import MCode, MCodeError, MCodeOptions
    
    FAKE = pathlib.Path("fake-mcode.js")
    FAKE.write_text(
        "if (process.argv[2] === '--version') { console.log('0.7.2'); process.exit(0); }\n"
        "process.stdout.write(JSON.stringify({schemaVersion: 1, type: 'exec.started',"
        " sequence: 1, timestampMs: 0, runId: 'r', sessionId: 's', turnId: 't'}) + '\\n');\n"
        "setInterval(() => {}, 1000);\n",
        encoding="utf-8",
    )
    
    
    async def main() -> None:
        client = MCode(MCodeOptions(bin=str(FAKE.resolve()), env=dict(os.environ)))
        streamed = await client.start_thread().run_streamed("hi")
        try:
            async for event in streamed:
                if event["type"] == "exec.started":
                    streamed.cancel()
        except MCodeError as error:
            print(f"{type(error).__name__}: {error}")
            print(f"  status={getattr(error, 'status', None)!r} exit_code={error.exit_code!r}")
        finally:
            FAKE.unlink()
    
    
    asyncio.run(main())

    The same script and the same SDK code on Linux and on Windows:

    # Linux (Debian 12, Python 3.11.2, Node v20.20.2)
    MCodeAbortError: The MCode run was cancelled.
      status=None exit_code=-15
    
    # Windows 11 x64 (build 26200), Python 3.12.10, Node v24.18.0
    MCodeRunError: The MCode run ended without a result: exit code 1
      status='failed' exit_code=1
    

Expected and actual behavior

  • Expected: a cancelled Turn raises MCodeAbortError on every platform, as the TypeScript SDK does and as the README documents. The Windows CI leg exercises the SDK's process layer.
  • Actual: on Windows the cancellation raises MCodeRunError with status="failed" and category="internal", and no CI job ever starts a CLI process on Windows, so the difference was never observed.

Two more details of the same root cause, both inside the skipped suite:

  • os.kill(pid, signal.SIGINT) terminates the process on Windows with exit code 2 instead of raising SIGINT in it, and os.kill(pid, signal.SIGTERM) terminates it with exit code 15. Neither runs the child's signal handler. Measured on Windows 11:

    call exit code handler ran
    os.kill(pid, SIGINT) 2 no
    os.kill(pid, SIGTERM) 15 no
    proc.terminate() 1 no
    proc.kill() 1 no

    tests/test_sdk.py:303 relies on the SIGINT delivery, so it cannot hold on Windows; the same is true for the pkill -INT helper at tests/test_sdk.py:167.

  • The timeout backstop kills the CLI with a signal number on POSIX and with exit code 1 on Windows, so the assertion exit_code < 0 at tests/test_sdk.py:214 cannot hold there either.

Redacted error summary

MCodeRunError: The MCode run ended without a result: exit code 1
  status='failed' exit_code=1

What I prepared

A branch that runs the fake-CLI suite on Windows. It is pushed on my fork as test/python-sdk-windows-coverage (commit 65f2ff3, one commit on top of 3c21163). I cannot open a pull request myself — the API refuses cross-repository pull requests for my account — so the branch is the handover.

  • new: packages/code-sdk-python/tests/fake_mcode.mjs — a Node port of tests/fake_mcode.py, scenario by scenario. Windows cannot execute a shebang script (CreateProcess rejects it with WinError 193), and the SDK only starts .exe, .com and .js entries there (packages/code-sdk-python/src/minimax_code/_cli.py:82), so the fake CLI needs an entry the SDK can launch. A .mjs entry is started as node <entry>.
  • packages/code-sdk-python/tests/conftest.py — the fake_env fixture picks the platform's fake CLI instead of skipping the suite.
  • packages/code-sdk-python/tests/test_sdk.py — the three POSIX-specific expectations become platform aware; the two tests that need a signal delivered to another process stay POSIX-only, with a reason.
  • .github/workflows/python-sdk.yml — the Windows leg gets Node.js, and the comment about POSIX-only tests is corrected.
  • release/public-source.json — regenerated for the new file.

Result on Windows 11 x64, CPython 3.12.10, pytest -W error with PYTHONWARNDEFAULTENCODING=1:

59 passed, 5 skipped in 8.02s      # was: 34 passed, 30 skipped

ruff check, ruff format --check and mypy are clean. The 5 remaining skips are the 3 opt-in end-to-end tests and the 2 tests that need POSIX signal delivery.

The branch contains no production-code change: it only measures and pins the current Windows behaviour. The error-class divergence above is a separate question — mirroring packages/code-sdk/src/exec-process.ts:323 in _Exec/error_for_exit would make a cancelled Turn raise MCodeAbortError on Windows as well. I did not include that in the branch because it changes the semantics of a published package.

Before submitting

  • I have searched existing issues.
  • I have included my version and removed sensitive information.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions