Skip to content

Windows port validation: full native support (validates Discussion #165) - #186

Closed
MattBetancourt wants to merge 8 commits into
googlecolab:mainfrom
MattBetancourt:windows-port-validation-2026-10-25
Closed

MattBetancourt wants to merge 8 commits into
googlecolab:mainfrom
MattBetancourt:windows-port-validation-2026-10-25

Conversation

@MattBetancourt

Copy link
Copy Markdown

Summary

Independent validation of the complete Windows port published in Discussion #165 (arlinamid/cursor/windows-tty-drive-mount-8411 @ 0f3ad51, 9 commits, +2973/-276 vs a84e094). Merges cleanly onto current main (4025416) with zero conflicts.

Upstream policy (CONTRIBUTING.md) declines external PRs, so this is filed as a validation record for the maintainers' review queue: the code exists on the linked fork, this PR carries the independent test evidence.

What was validated (not authored here)

All credit to @arlinamid (Discussion #165): Win32 raw console (terminal.py, msvcrt + VT), SSH quoting/devnull/SIGHUP-less, colab edit temp-dir fix, Windows $EDITOR handling, /dev/tty->CONIN$, % ProxyCommand escaping, piped-console fixes, drivemount handshake threading.

Evidence (2026-10-25)

  • Windows suite: 464 passed / 2 skipped (skips: POSIX-only termios, tests/test_console.py:47,94) — native Windows 11 build 26200 / Python 3.12.10, exact match to author's 464/2 claim.
  • Linux suite (same commit, Ubuntu 6.17 / Python 3.12.3): 462 passed / 4 skipped (skips: Windows-only CommandLineToArgvW tests). Same 466 total, complementary skips, zero failures both sides.
  • Windows live smoke (--auth adc): new -s win-smoke READY (~7s) -> exec returned hello from colab: Linux-6.6.122+ -> stop terminated, zero sessions remaining.
  • Parity: 1:1 except update --install (still refused, intentional) and shebang (Unix-only by construction). Known near-parity: resize polls at 0.4s instead of SIGWINCH; ssh --proxy-mode --rm teardown may not fire on Windows.

Known non-goals (author-listed)

update --install self-update gate and shebang workflow intentionally unported.

References

cursoragent and others added 8 commits October 7, 2026 17:44
Interactive colab console on cmd.exe and PowerShell no longer depends on
termios. It enables ANSI processing, switches the console to raw input,
and translates Windows scan codes to the sequences a POSIX tty would send.
colab ssh --proxy-mode reads stdin with a blocking os.read and quotes its
ProxyCommand for cmd.exe.

colab drivemount passes timeout_ms=600000 so the kernel does not abandon
the browser consent step at 120s, runs the handshake off the websocket
thread, opens the consent URL, and explains the multi-account HTTP 400
instead of dumping Google's HTML error page.

Co-authored-by: János Rózsavölgyi <arlinamid@users.noreply.github.com>
`colab edit` kept the local copy in an open NamedTemporaryFile. On Windows
an open NamedTemporaryFile cannot be opened again, so the download, the
hash and the editor all failed with PermissionError. The download error
was swallowed, so without the hash crash the editor would have been given
an empty file and saving would have overwritten the remote file.

Use a path inside a TemporaryDirectory instead, named after the remote
file so editors pick the right syntax, and create it empty when the
remote file does not exist.

Tested: new regression tests fail without the fix and pass with it on
Windows; full suite passes on Linux (384); live on Windows against a CPU
runtime, editing an existing and a new remote file round-trips correctly
and no temp directories are left behind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ndows

ProxyCommand (bug fix)
OpenSSH expands %-tokens (%h, %p, ...) in ProxyCommand before running it,
on POSIX and on Windows. A session name or identity path containing '%'
either failed ("unknown key %x") or was silently rewritten ('a%h' became
'a<host>'). _proxy_command now writes '%' as '%%'. Checked against OpenSSH
10.5p1 (WSL) and OpenSSH_for_Windows_9.5p2.

The same check showed that OpenSSH for Windows does not run ProxyCommand
through cmd.exe: 'a&echo INJECTED' arrives as one literal argument. It
goes to CreateProcess and is split with the MSVCRT rules, which is what
subprocess.list2cmdline targets, so the code was right and only the
comments were wrong. Comments updated.

Tests (Windows: 30 failed + 1 hang -> 389 passed, 2 POSIX-only skips)
- ProxyCommand round-trip: undo %-escaping, then split with shlex on POSIX
  and CommandLineToArgvW on Windows. New cases: cmd metacharacters, '%',
  '%h'. The '%' cases fail without the fix above.
- REPL: run each test inside a prompt_toolkit app session with pipe input
  and DummyOutput; a PromptSession needs a console on Windows.
- SIGHUP: patch with create=True, expect only the signals the platform
  has, and drive the teardown with SIGTERM where SIGHUP does not exist.
- --help ordering: skip wrapped description lines (blank command column);
  Rich renders one column narrower on Windows.
- Console: pin the POSIX branch in the TTY-EOF test (on Windows it blocked
  in msvcrt.getwch) and add a test for the Windows key path.

Linux: 391 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Piped `colab console`
tmux on the runtime sends terminal queries when it attaches (DA1 ESC[c,
DA2 ESC[>c, XTVERSION ESC[>q, OSC 10/11 color queries). The local terminal
answers them by typing the reply into its own input. With piped stdin the
CLI is not reading that input, so the replies could never reach the remote
side and were left behind for the next reader: on Windows they showed up
in the next command's prompt (ESC[?61;...c ESC[>0;10;1c). This is not
Windows-specific; it follows from piped stdin.

When stdin is not a TTY, the console now drops terminal queries from the
remote output (TerminalQueryFilter), holding back a sequence cut across
websocket messages. Interactive sessions are unchanged, because there the
replies do flow back to tmux.

Measured in a ConPTY terminal: 41 console input events (the DA1 and DA2
replies) left after a piped console before, none after.

`colab edit` with a Windows $EDITOR
click.edit splits $VISUAL/$EDITOR with POSIX shlex on every platform
(pallets/click#3840), so `python D:\x\editor.py` became `D:xeditor.py`.
On Windows, when one of those variables is set, `colab edit` now splits it
with CommandLineToArgvW, resolves the program with shutil.which (so .cmd
launchers like VS Code's `code` work), and runs it itself. POSIX and
click's own default editor still go through click.edit.

Tests: query filter (each tmux query, kept sequences, chunk splits,
flush), console filters only when piped, Windows command-line splitting
(Windows-only), editor launch on Windows and fallback to click. Windows:
416 passed, 2 skipped. Linux: 414 passed, 4 skipped. Live on Windows: an
unquoted backslash EDITOR path edits an existing and a new remote file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After piped stdin hit EOF, the console sent "exit\n" and closed the
websocket itself a fixed 0.5s later (PIPED_EOF_GRACE_SECONDS). On a freshly
started runtime the first attach often needs 0.5-1s before the shell
answers, so the client closed first and nothing came back.

Traced with timestamps on fresh CPU runtimes (one attach each):
- 0.5s grace: 1 of 3 got its output; twice the client closed before any
  output arrived.
- 5s wait: 3 of 3; output arrived 0.1-0.8s after "exit", and the backend
  closed the websocket itself every time (tmux "[exited]", then on_close).

The backend closes the socket once bash and tmux exit, after the last
output, so the handler now waits for that close (_closed, set by
on_close). It only closes from the client side after
PIPED_EOF_CLOSE_TIMEOUT_SECONDS (30s), as a fallback for a backend that
never closes; as with `echo cmd | ssh host`, a piped command running
longer than that is cut off.

With the fix, 3 of 3 fresh-runtime runs got their output (one arrived
1.08s after "exit"), and the backend closed the socket each time.

Also corrects the docs entry that said OpenSSH for Windows runs the
ProxyCommand through cmd.exe (it uses CreateProcess), and documents the
piped-mode terminal query filter from a0ea62e.

Tests: new test that the client waits for the server-side close; the
existing EOF test now covers the fallback close. Windows: 417 passed,
2 skipped. Linux: 415 passed, 4 skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sions

`colab stop` from another terminal, while `colab exec` (or repl, run,
drivemount) was running against the same session, ended the running
command with a jupyter_kernel_client traceback:

    RuntimeError: Connection was lost.

ColabRuntime now turns that error into SessionConnectionLost, and the
`colab` entry point prints one line with exit code 1: "Session 'X' was
stopped, so the running command ended." when the session is gone
locally, otherwise "Lost the connection to session 'X' ... check it with
`colab status -s X`".

The same commands also saved the session back to sessions.json in their
`finally` blocks, after `colab stop` had removed it, leaving a stopped
session behind locally. They now use StateStore.update_if_present, which
writes under the same lock only if the session is still recorded.

Six ColabRuntime constructions did not pass session_name, so the first
live run printed "Session 'None'"; they now pass it (it is otherwise only
used for history logging, which those call sites do not enable).

Live (WSL, CPU runtime): a 2-minute `colab exec`, stopped after 15s from
another process, printed "[colab] Session 'losttest' was stopped, so the
running command ended." with exit code 1, and sessions.json stayed empty.
Tests: Windows 423 passed, 2 skipped; Linux 421 passed, 4 skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…exit on errors

`colab exec -f nb.ipynb` always ran every code cell top to bottom, kept
going after a cell raised, and exited 0 either way, so a script could not
tell that a notebook had failed. A missing file or an unreadable notebook
ended in a traceback.

- --cells SPEC runs only the selected code cells, in the given order.
  SPEC is a comma-separated list of code-cell numbers (from 1, markdown
  cells not counted), ranges (2-5), #@title values or cell ids; an
  unknown or ambiguous entry is an error (exit 2) before anything runs.
- --stop-on-error stops at the first cell with an error output. The
  partial outputs are still saved to <name>_output.ipynb.
- exec exits 1 when the code, or any notebook cell, produced an error
  output, and lists the failed cells.
- --check runs a local pre-flight before anything is sent: notebook
  validation, --cells resolution and a syntax check of each selected
  cell (IPython !cmd, %magic, `x = !cmd` and top-level await accepted,
  %% cell magics skipped, line numbers kept). If it fails, nothing runs
  (exit 2). --check-only does the same and prints the plan without a
  session. Works for .py files too.
- A missing file or unreadable notebook prints one line.

Cell selection and the pre-flight live in colab_cli/notebook.py.

Behavior change: exec now exits 1 when the executed code raises; the
existing test that expected 0 was updated.

Live (WSL, CPU runtime): --check on a notebook with a syntax error
reported "cell 2 (Broken), line 2: expected ':'" and ran nothing (exit 2);
a 3-cell notebook whose cell 2 raises ran all cells and exited 1; with
--stop-on-error it stopped after cell 2; --cells "Three,1" ran cell 3,
then cell 1; a missing file printed "File not found" (exit 1).

Tests: 33 new. Windows: 463 passed, 2 skipped. Linux: 461 passed,
4 skipped (two cross-process timing tests in test_state.py failed in
one run and passed on rerun; this change does not touch state.py).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nbformat gives new cells random 8-hex-digit ids, and about 2% of them
are all digits. --cells reads an entry that looks like a number or a
range as one, so such a cell cannot be selected by its id; that is the
intended precedence (numbers are the common case), but it was not
documented, and test_select_by_cell_id used a random id and failed when
the id happened to be all digits (seen once on Linux).

- The test now uses a fixed id, plus a new test pinning that numbers and
  ranges win over look-alike ids.
- --cells help, the select_cells docstring, README and docs say so.

Correction to 29f8bfb's message: its Linux line ("461 passed") was not
a clean run. The run it was based on had 459 passed and 2 cross-process
timing failures in test_state.py, and a rerun at 29f8bfb hit this flaky
test. With this commit: Windows 464 passed, 2 skipped; Linux 462 passed,
4 skipped; the notebook tests passed 20 of 20 repeated runs on Linux.
The live results in 29f8bfb's message were re-run with English-titled
notebooks and match it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@google-cla

google-cla Bot commented Oct 25, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@MattBetancourt

Copy link
Copy Markdown
Author

Withdrawing — validation will live in the discussion thread instead.

@MattBetancourt
MattBetancourt deleted the windows-port-validation-2026-10-25 branch October 25, 2026 05:34
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.

3 participants