fix(code-runtime-python): bind the _done_with_value entry name and correct the residual documentation

Addresses the review's registration-text accuracy findings:
- _run binds _done_with_value into a local (done_with_value_bound) before the
  program runs, closing the __main__._done_with_value = boom success-rewrite
  vector; a regression test rebinds it and returns a legitimate value, asserting
  the success survives.
- README (en + zh): the CPU-recheck bullet now states the recheck runs
  unconditionally after the program returns (a pre-return overrun dies there as
  a timeout) and the false-success window is only a trap-SIGXCPU program that
  passes the recheck and overruns during the settlement flush/encode; the
  encoder-deps residual rationale is replaced with the actual one (bash-equivalent
  trust, verdict still delivered via the send_done fallback frame) and names the
  now-bound entry; the t.join() deadlock bullet fixes the subject/object (the
  main coroutine joins the worker, blocking the pump's main event loop).
- The portable-identifier-seam architecture note no longer claims the Python
  backend does not exist.
- Settlement note (en + zh) registers the entry-name binding and the new test.
- All pairings re-recorded; corpus-wide verify-translation-pairing passes 1004.
This commit is contained in:
Chinesezjc
2026-08-31 14:40:35 +08:00
committed by Tianyi Cui
parent e6b23e829b
commit 96597c5ed8
11 changed files with 50 additions and 19 deletions
@@ -3145,6 +3145,29 @@ describe('PythonCodeRuntime — hostile peer', () => {
expect(result.value).toBe('released')
}, 15_000)
it('keeps a successful completion when _done_with_value is rebound', async () => {
// `_run` calls `_done_with_value(value, max_value_bytes)` after the program
// returns. The name is a module global, and this bootstrap IS `__main__`, so
// `__main__._done_with_value = boom` as a program statement would otherwise
// be resolved at call time and a legitimate success would be rewritten into
// an `exception`. `_run` now binds `done_with_value_bound = _done_with_value`
// before the program runs, so the entry name is immune; the run must still
// report the success value.
const { runtime } = await setup({ maxWallMs: 10_000 })
const result = await runtime.run({
program: [
'import __main__',
'def boom(*a, **k):',
' raise RuntimeError("hijacked")',
'__main__._done_with_value = boom',
'return 1',
].join('\n'),
bindings: [],
})
expect(result.error).toBeUndefined()
expect(result.value).toBe(1)
}, 15_000)
it('round-trips an exactly representable large integer through a binding echo', async () => {
// The reply serializer must print BigInt digits for a beyond-safe
// integral double: String(2**60) emits a rounded form, and the child