You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Windows] Skill's inline python snippets fail under PowerShell 5.1 (quoting) and Windows multiprocessing (missing __main__ guard); minor: query exit code, fuzzy-match ties #1637
1. PowerShell 5.1 quoting breaks the inline python -c snippets
Steps 3–5 of SKILL.md embed multi-line Python with escaped double quotes (\"nodes\"), written for bash. Under Windows PowerShell 5.1 the escapes are mangled before reaching Python (SyntaxError: unterminated string literal). Suggestion: for the Windows variant, instruct the agent to write each step to a temp .py file and execute that, instead of python -c.
2. extract() requires an if __name__ == "__main__": guard on Windows
graphify.extract.extract() uses multiprocessing. Windows uses the spawn start method, so any caller script without a __main__ guard re-executes on every worker spawn → a cascade of spawn_main tracebacks and no extraction. Worked once the runner script was wrapped in def main(): ... if __name__ == "__main__": main(). The SKILL.md snippets don't mention this; the Windows variant should either wrap its snippets or document the guard.
3. Minor observations from the same test run (209-file TypeScript corpus)
graphify query "..." prints a correct, useful subgraph but exits 255 even on success — breaks scripted $LASTEXITCODE/&& chaining.
graphify path A B with human-readable names failed with warning: target match was ambiguous (top score X, runner-up X) and reported "No path found", while the same call with exact node IDs returned a correct 3-hop path. When fuzzy scores tie exactly, consider listing the tied candidates and asking, rather than silently picking one that may be disconnected.
Community labeling step assumes a hand-labelable number of communities; this corpus produced 125. A documented top-N-plus-heuristic-tail strategy would help.
Confirming point 2 on graphifyy 0.9.25 (originally reported here against 0.9.5), Windows 11, Python 3.13 — and reporting that the impact is considerably worse than "no extraction".
It is a fork bomb, not just a failed run
On a 12-thread / 32 GB machine the missing guard took the whole OS down. extract() opened its pool, every worker re-ran the guard-less runner script, and the process count climbed without bound:
~1,278 python.exe processes, still growing when I caught it
~28 GB of 32 GB consumed
Windows could no longer create processes at all: bash, wmic and PowerShell itself began failing with OutOfMemoryException and 0xC0000142, which also blocked the commands needed to diagnose or kill it
The machine had to be power-cycled. Worth re-labelling from a Windows papercut to a data-loss/availability bug: by the time it is noticeable, the box may be too starved to run the command that would stop it.
The runner was the SKILL.md "Part A - Structural extraction" snippet written to a .py file, which is exactly the workaround point 1 of this issue recommends — so following the advice for the quoting problem makes the multiprocessing problem worse: python -c has no __file__ for spawn to re-execute, a .py file does.
Traceback (trimmed), each worker re-entering the runner:
File "...\scratchpad\ast.py", line 11, in <module>
result = extract(code_files, cache_root=Path('.'))
File "...\site-packages\graphify\extract.py", line 4515, in extract
ran_parallel = _extract_parallel(...)
File "...\site-packages\graphify\extract.py", line 4332, in _extract_parallel
pool.submit(_extract_single_file, item): pos
File "...\concurrent\futures\process.py", line 785, in _spawn_process
p.start()
File "...\multiprocessing\spawn.py", line 140, in _check_not_importing_main
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
Why the existing fallback does not save you
_extract_parallel already documents this case and returns False so extract() falls back to _extract_sequential. That path only fires on BrokenProcessPool — after the fact. Each pool.submit() calls _adjust_process_count(), which respawns dead workers, so over a few thousand files the pool keeps minting processes that die on _check_not_importing_main faster than the OS reclaims them. The recovery never gets a chance to run.
Suggested fix
Two layers; I have both applied locally.
1. Fix the template. Wrap the SKILL.md Part A body in main() behind if __name__ == "__main__":, with an explicit note that the guard is mandatory. This is the actual root cause — the snippet is generated fresh on every run, so patching a generated script by hand (as the original reporter did) does not survive the next invocation. My own generated script from a later session was guard-less again.
2. Defend in _extract_parallel, so a guard-less caller degrades instead of detonating:
# A spawned worker must never build a pool of its own.ifmultiprocessing.parent_process() isnotNone:
returnFalse# In the parent: a guard-less caller would both explode and return empty# results (workers die re-importing main). Go sequential up front.ifmultiprocessing.get_start_method(allow_none=False) =="spawn":
main_file=getattr(sys.modules.get("__main__"), "__file__", None)
ifmain_file:
try:
main_src=Path(main_file).read_text(encoding="utf-8", errors="ignore")
exceptOSError:
main_src=""ifmain_srcand"__main__"notinmain_src:
print(
" warning: calling script lacks an `if __name__ == \"__main__\"` ""guard; extracting sequentially to avoid runaway process spawning",
file=sys.stderr, flush=True,
)
returnFalse
The first check alone is not sufficient: it stops the explosion but the run then returns 0 nodes / 0 edges silently, because the parent's workers still die on re-import. Detecting the missing guard before building the pool is what keeps the output correct.
Verification
Same corpus (40 Python files), watchdog killing the run if processes exceeded 80:
runner
peak processes
mode
result
no guard
1
sequential + warning
531 nodes / 1190 edges
with guard
13
parallel (unchanged)
531 nodes / 1190 edges
Identical output both ways, no explosion, and the parallel path is untouched when the guard is present.
Activity
AndreeRolack71 commentedon Jul 29, 2026
Confirming point 2 on graphifyy 0.9.25 (originally reported here against 0.9.5), Windows 11, Python 3.13 — and reporting that the impact is considerably worse than "no extraction".
It is a fork bomb, not just a failed run
On a 12-thread / 32 GB machine the missing guard took the whole OS down.
extract()opened its pool, every worker re-ran the guard-less runner script, and the process count climbed without bound:python.exeprocesses, still growing when I caught itbash,wmicand PowerShell itself began failing withOutOfMemoryExceptionand0xC0000142, which also blocked the commands needed to diagnose or kill itThe machine had to be power-cycled. Worth re-labelling from a Windows papercut to a data-loss/availability bug: by the time it is noticeable, the box may be too starved to run the command that would stop it.
The runner was the SKILL.md "Part A - Structural extraction" snippet written to a
.pyfile, which is exactly the workaround point 1 of this issue recommends — so following the advice for the quoting problem makes the multiprocessing problem worse:python -chas no__file__for spawn to re-execute, a.pyfile does.Traceback (trimmed), each worker re-entering the runner:
Why the existing fallback does not save you
_extract_parallelalready documents this case and returnsFalsesoextract()falls back to_extract_sequential. That path only fires onBrokenProcessPool— after the fact. Eachpool.submit()calls_adjust_process_count(), which respawns dead workers, so over a few thousand files the pool keeps minting processes that die on_check_not_importing_mainfaster than the OS reclaims them. The recovery never gets a chance to run.Suggested fix
Two layers; I have both applied locally.
1. Fix the template. Wrap the SKILL.md Part A body in
main()behindif __name__ == "__main__":, with an explicit note that the guard is mandatory. This is the actual root cause — the snippet is generated fresh on every run, so patching a generated script by hand (as the original reporter did) does not survive the next invocation. My own generated script from a later session was guard-less again.2. Defend in
_extract_parallel, so a guard-less caller degrades instead of detonating:The first check alone is not sufficient: it stops the explosion but the run then returns 0 nodes / 0 edges silently, because the parent's workers still die on re-import. Detecting the missing guard before building the pool is what keeps the output correct.
Verification
Same corpus (40 Python files), watchdog killing the run if processes exceeded 80:
Identical output both ways, no explosion, and the parallel path is untouched when the guard is present.