Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: leogrox/python-sdk
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: leogrox/python-sdk
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: fix/stdio-stderr-relay-156
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 2 commits
  • 5 files changed
  • 2 contributors

Commits on Oct 3, 2026

  1. Relay server stderr to errlog streams that cannot take a descriptor

    stdio_client handed errlog straight to the spawn, which only works for a
    real file. In Jupyter the server's stderr never reached the notebook:
    ipykernel's sys.stderr reports a copy of the terminal behind the notebook
    on Linux and macOS, and no descriptor at all on Windows, where the spawn
    failed. io.StringIO, pytest's capsys and logging shims failed the same way.
    
    A file is still handed to the server as before. Any other text stream now
    gets the server's stderr through a pipe that a task copies into
    errlog.write(). Shutdown waits, bounded, for that pipe to reach EOF before
    closing it, so what the server writes while exiting is kept. A rejected
    write loses only its own chunk and is logged once, and the pipe is always
    read to the end so a chatty server never blocks on it.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    leogrox and claude committed Oct 3, 2026
    Configuration menu
    Copy the full SHA
    0daf750 View commit details
    Browse the repository at this point in the history
  2. Harden the stderr relay against cancellation and failing streams

    A cancelled caller also cancelled the relay, so nothing read the pipe
    during shutdown: a server writing more than a pipe buffer on its way out
    blocked, missed the grace period and was killed, and its last lines were
    lost. The relay is now shielded like the stdout drain; shutdown still ends
    it by closing the pipe.
    
    Reporting a failed write could itself end the session when errlog is a
    broken sys.stderr, because logging's last-resort handler writes there and
    lets the ValueError escape. That report is now best effort.
    
    Binary streams such as io.BytesIO go to the spawn again, which rejects them
    up front, instead of failing at the first line of server stderr.
    
    errlog is flushed once when the relay ends rather than after every chunk.
    In a real kernel, flushing Jupyter's stream from the event loop costs about
    0.8 ms per call against 4.5 us for the write, and that stream already
    flushes itself every 0.2 s.
    
    New tests pin the cancellation case, undecodable and split characters,
    errlog=None (as under pythonw) and DEVNULL going to the spawn unchanged,
    binary streams rejected at spawn, and a broken sys.stderr.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    leogrox and claude committed Oct 3, 2026
    Configuration menu
    Copy the full SHA
    380b771 View commit details
    Browse the repository at this point in the history
Loading