Skip to content

test(python): the stop-hang's kill line names a read, not a landing; todo rows pin the swallowed stop - #2224

Open
wanderdev0 wants to merge 1 commit into
mainfrom
test/bench-stop-lost-stop
Open

wanderdev0 wants to merge 1 commit into
mainfrom
test/bench-stop-lost-stop

Conversation

@wanderdev0

@wanderdev0 wanderdev0 commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

What was wrong with the instrument

The python-bench-stop writer treated the interrupt slot leaving 2 as the stop landing. CPython's emscripten helper (_Py_CheckEmscriptenSignals_Helper in pyodide.asm.mjs) reads Py_EmscriptenSignalBuffer[0], stores 0 back, and only then calls PyErr_SetInterruptEx(2); Modules/signalmodule.c:1898 raises a KeyboardInterrupt only when get_handler(SIGINT) is neither ignore nor default. The slot therefore leaves 2 whenever the interpreter merely looks at it, and the CI hang's line, handler=1 beacon=1 stop=1 left2ms=22 answer=0, named a read, never a delivery.

Measured against the real python-worker.ts and dist/pyodide (3 runs each, hardened cells): the default handler raised KeyboardInterrupt 3/3 in 54–69 ms; signal.signal(SIGINT, SIG_IGN) ran the cell to its end 3/3 with the slot consumed; a Python handler that returns ran the handler and then the cell to its end, 3/3. The loss is deterministic, not a race. The earlier suspicion, that a stop written during a print callback is lost, was disproved: a synchronous write inside the postMessage hook delivered KeyboardInterrupt in _MlTee.write.

What this changes (tests only, no src/)

The writer's success is the CELL's own answer slot (P.answer), never the slot leaving 2. A stop consumed and not raised now fails at the writer's own 15 s line with every slot printed, and the line names the case: the slot was READ at Nms and the script never ended vs the slot still held 2 ... the interpreter never looked at it vs never reached its beacon. This is the corrected left2ms reading, in the kill line and in the comment beside the slots.

The loop row's script now reports through the chunk hook, the only place a frozen thread's account survives: the SIGINT handler it saw before the beacon (getsig, 1 for default_int_handler, 2 for anything else), that the beacon print returned (prep), that the loop's first iteration ran (loop), and whether its own sys.unraisablehook saw the interpreter drop a tripped signal (unraisable; the default hook would write into the cell's captured stderr, which a hang never returns). A patched Atomics.store counts the runtime's own zeros (wipes): clearInterrupt is the only writer of 0 in the product (python-worker.ts), and a completed cell is exactly 2, run()'s start and finally, which the row now asserts.

Two { todo } rows (owner flaky-ci) assert the wanted behaviour where a script swallows the stop. tests/python-lease-offscreen.test.mjs: the cell still ends at the 1 s backstop ({ how: "killed" }, restarted, names lost), and the message does not say most likely inside a C function. tests/python-lease.test.mjs: pyCancelText("killed") keeps names are lost and names no cause the sandbox did not report. Both are red today for exactly that reason and go green on the repair. Neither asserts that "KeyboardInterrupt is raised under SIG_IGN"; that test can never pass.

The repair is a separate PR, built by me (flaky-ci) after this lands: the offscreen document reads its own interrupt flag at kill time (still 2: the interpreter never looked, so a long step or a pure computation is the shape; zeroed and the cell did not end: the stop was consumed and not raised, so the script's own SIGINT handler swallowed it) and carries that reason in the kill answer, and pyCancelText plus the lease-offscreen wording say the case they know instead of "most likely inside a C function". The two todo rows are that PR's acceptance tests and neither may be weakened to pass.

The CI state this does not explain

The row passes locally with the handler at the beacon measured as default_int_handler (now asserted); the same row hung in CI at the same line. That discrepancy is still unexplained. The new slots name the state on a recurrence: getsig=2 means a non-default handler was installed before the beacon, so PyErr_SetInterruptEx cannot raise and the stop is genuinely unraisable; prep=0 means the beacon print never returned, so the hang is inside the print/WASM bridge rather than the loop; loop=0 with prep=1 means the print returned and control never reached the loop; unraisable=1 means a tripped signal was dropped as unraisable, the disappearing-stop case made visible; wipes=1 is the expected hang (run()'s start wipe only), and wipes=2 in a kill line would mean run() returned while the writer saw no answer, so the reply, not the stop, was lost.

Can a dialect cell set SIGINT without asking? Measured: no

Driven through the real membership gate (the fork's restricted.run_cell, the path the extension's inside try runs, src/python/python-dialect-run.ts, with the real dist/pyodide core) with four shapes: signal.signal(SIGINT, SIG_IGN), a handler that returns, restoring the default handler, and signal.getsignal alone. Every cell was refused with not in dialect: import 'signal' (line 1). So no cell that touches SIGINT is inside the dialect, and autoApprovePython (src/agent/auto-approve.ts) answers "ask" for anything outside the dialect before it looks at any other condition, including when autoApprovePython is on. A model's python_exec cell that wants to swallow the stop must reach the person's approval card first; after approval it runs as full Python, where signal.signal works. The unasked path to this shape is the person's own bench editor, whose script is their own code.

Severity

Both Stop paths in the product already kill at 1 s: the person's Stop (PY_INTERRUPT_KILL_MS = 1000, src/python/py-lease.ts:47) and the bench Stop (BENCH_STOP_KILL_MS = 1000, src/offscreen.ts:23), and the bench's message (BENCH_STOP_KILLED) does not blame a C function, asserted already in tests/python-bench-stop-offscreen.test.mjs:103 and :211. The unprotected drive is this suite's own direct call into python-worker.ts, and its 180 s file and cell guards name the phase that hangs. What the swallowed stop really costs is the run's namespace plus a message that misnames the cause; the two todo rows pin both.

Drafted by Claude Code · work: flaky-ci · session 309c99e2 · deepseek.deepseek-flash

🤖 Generated with Claude Code

…two todo rows assert the wanted backstop and message

CPython's emscripten helper zeroes the interrupt slot when it READS it and
only then asks PyErr_SetInterruptEx, which trips nothing while the script's
own SIGINT handler is ignore/default or returns (signalmodule.c:1898) - so
the CI hang's left2ms=22 named a read, never a delivery. The
python-bench-stop writer now treats the CELL's answer as success and fails
loud, slots included, when the slot was consumed and the script never
ended; the loop row's script reports, through the chunk hook, the SIGINT
handler it saw, the beacon's return, the loop's first iteration and any
unraisable it dropped, and a counter pins run()'s two own wipes.

Two { todo } rows assert the wanted behaviour when a script swallowed the
stop: the cell ends at the backstop, and neither the person's nor the
model's message names a cause the sandbox did not report ('most likely
inside a C function').

Co-Authored-By: Claude Code <noreply@anthropic.com>
@wanderdev0 wanderdev0 added the @python python_exec, the Pyodide sandbox, the Python bench label Dec 1, 2026

This branch has not been deployed

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

Labels

@python python_exec, the Pyodide sandbox, the Python bench

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant