From a7b1ee34ef3e17e56e9f0cc87f21e0d6a43553e9 Mon Sep 17 00:00:00 2001 From: goodboy Date: Thu, 23 Apr 2026 18:30:11 -0400 Subject: [PATCH] Restore fn-arg `_runtime_vars` in `trio_proc` teardown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During the Phase A extraction of `trio_proc()` out of `spawn._spawn` into its own submod, the `debug.maybe_wait_for_debugger(child_in_debug=...)` call site in the hard-reap `finally` got refactored from the original `_runtime_vars.get('_debug_mode', ...)` (the fn parameter — the dict that was constructed by the *parent* for the *child*'s `SpawnSpec`) to `get_runtime_vars().get(...)` (a global getter that returns the *parent's* live `_state`). Those are semantically different — the first asks "is the child we just spawned in debug mode?", the second asks "are *we* in debug mode?". Under mixed-debug-mode trees the swap can incorrectly skip (or unnecessarily delay) the debugger-lock wait during teardown. Revert to the fn-parameter lookup and add an inline `NOTE` comment calling out the distinction so it's harder to regress again. Deats, - `spawn/_trio.py`: `child_in_debug=get_runtime_vars().get(...)` → `child_in_debug=_runtime_vars.get(...)` at the `debug.maybe_wait_for_debugger(...)` call in the hard-reap block; add 4-line `NOTE` explaining the parent-vs-child distinction. - `spawn/__init__.py`: drop trailing whitespace after the `'mp_forkserver'` docstring bullet. - `ai/prompt-io/prompts/subints_spawner.md`: drop duplicated `with` in `"as with with subprocs"` prose (copilot grammar catch). Review: PR #444 (Copilot) https://github.com/goodboy/tractor/pull/444#pullrequestreview-4165928469 (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- ai/prompt-io/prompts/subints_spawner.md | 2 +- tractor/spawn/__init__.py | 2 +- tractor/spawn/_trio.py | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ai/prompt-io/prompts/subints_spawner.md b/ai/prompt-io/prompts/subints_spawner.md index 4911a930..08d38684 100644 --- a/ai/prompt-io/prompts/subints_spawner.md +++ b/ai/prompt-io/prompts/subints_spawner.md @@ -24,7 +24,7 @@ Part of this work should include, is happening under the hood with how cpython implements subints. * default configuration should encourage state isolation as with - with subprocs, but explicit public escape hatches to enable rigorously + subprocs, but explicit public escape hatches to enable rigorously managed shm channels for high performance apps. - all tests should be (able to be) parameterized to use the new diff --git a/tractor/spawn/__init__.py b/tractor/spawn/__init__.py index 3f363889..cb9be559 100644 --- a/tractor/spawn/__init__.py +++ b/tractor/spawn/__init__.py @@ -29,7 +29,7 @@ coroutine registered in `_spawn._methods`): - `._mp`: the stdlib `multiprocessing` backend variants — driven by the `mp.context` bound to `_spawn._ctx`: * `'mp_spawn'`, - * `'mp_forkserver'` + * `'mp_forkserver'` Entry-point helpers live in `._entry`/`._mp_fixup_main`/ `._forkserver_override`. diff --git a/tractor/spawn/_trio.py b/tractor/spawn/_trio.py index bdb97c75..3b425256 100644 --- a/tractor/spawn/_trio.py +++ b/tractor/spawn/_trio.py @@ -246,7 +246,11 @@ async def trio_proc( await proc.wait() await debug.maybe_wait_for_debugger( - child_in_debug=get_runtime_vars().get( + # NOTE: use the child's `_runtime_vars` + # (the fn-arg dict shipped via `SpawnSpec`) + # — NOT `get_runtime_vars()` which returns + # the *parent's* live runtime state. + child_in_debug=_runtime_vars.get( '_debug_mode', False ), header_msg=(