Repository navigation
Conversation
The parse pool was created with no mp_context, so on Linux it used fork. An MCP server creates the pool from a process that already runs threads, among them the stdio reader holding sys.stdin's lock; a forked worker inherits that lock held and deadlocks in multiprocessing's _close_stdin() before running any task. The start-up scan then never processes a file and the server never reaches query_ready. Measured in a Linux container (py-spy: every worker in _close_stdin); with a spawn context the same session was query_ready in 13.8 s. indexing_coordinator._ensure_mp_start_method() sets the global start method, but the realtime/MCP path can create the pool before it runs, so the pool now carries its own spawn context, as batch_processor and the per-file timeout worker already do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
looks good |
One conflict, in chunkhound/pipeline_bridge.py _get_parse_pool: chunkhound#487 on main added initializer=exit_when_parent_dies to the same ProcessPoolExecutor call this branch gave mp_context=multiprocessing.get_context("spawn"). Kept both arguments and this branch's comment. exit_when_parent_dies is a module-level function, so it pickles under spawn. Both arguments are load-bearing: without mp_context, test_parse_pool_is_created_with_a_spawn_context fails; without the initializer, chunkhound#487's test_parse_pool_worker_exits_when_parent_is_killed fails. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@HananKavitzAmat thanks for the look. I merged Upstream's CI test matrix (Ubuntu, macOS, Windows) passed on this tree on my fork before I pushed here. 🤖 Generated with Claude Code |
VakninAriel
left a comment
There was a problem hiding this comment.
Code Review — PR #493
Verdict: ✅ Approve
Summary
On Linux versions that default to fork, the MCP startup parse pool could inherit a lock held by the stdio reader thread and hang before processing any files. At the reviewed pinned head, this PR explicitly supplies a spawn multiprocessing context when constructing that pool instead of relying on platform defaults or earlier global initialization.
What's good
- The fix is applied directly at ProcessPoolExecutor construction, so this pool no longer depends on whether another startup path has already set the global multiprocessing method.
- The new test checks the context actually supplied to the executor and asserts spawn, making the regression detectable even on systems whose default is already spawn.
Freshness warning: Package freshness checked 2026-11-11T15:38:58.574960+00:00: STALE: included heads/eligibility changed; see overview and freshness audit before posting. This report applies only to its pinned SHA.
| Severity | Count |
|---|---|
| 🔴 Critical | 0 |
| 🟠 High | 0 |
| 🟡 Medium | 0 |
| 🟢 Minor | 0 |
Findings
No retained findings. This is not a guarantee that the code is defect-free.
Review metadata and audit
Draft review for human approval. Nothing has been posted to GitHub.
Pinned head SHA: f28be4db338a0b322cb32bb0f3d5d825198625fb
Package freshness checked 2026-11-11T15:38:58.574960+00:00: STALE: included heads/eligibility changed; see overview and freshness audit before posting. This report applies only to its pinned SHA.
PR: #493
Title: fix(pipeline): parse pool always starts workers with spawn (MCP start-up scan hangs on Linux)
Author: fstrasz · Branches: fix/parse-pool-spawn → main
Diff merge base: 42c5711
Review scope: Full main...HEAD contribution, merge base 42c5711 through pinned head f28be4d; both changed files, module-level worker/config pickling, parse_batch_callback, CLI/MCP entry points and related timeout-worker spawn usage. One commit directly above the merge base. No stacked implementation changes in this diff.
Eligibility: Bug fix addressing existing behavior; no new feature.
Overall assessment (audit only)
No actionable introduced defects found. Explicit spawn context is a minimal fix for fork-after-threads worker startup and preserves lazy pool reuse and task pickling contracts. Isolated threaded pool smoke passed; native integration remains unverified.
Strength evidence
- {"strength_index": 0, "path": "chunkhound/pipeline_bridge.py", "source": "pr-493.pinned.diff", "detail": "_get_parse_pool passes mp_context=multiprocessing.get_context('spawn') while retaining the existing lazy pool construction."}
- {"strength_index": 1, "path": "tests/contracts/test_parse_pool_spawn_context.py", "source": "pr-493.pinned.diff", "detail": "test_parse_pool_is_created_with_a_spawn_context captures mp_context and asserts get_start_method() == 'spawn'; it is an explicit-context contract, not an end-to-end deadlock reproduction."}
Verification
- Reconciler: git -C /tmp/chunkhound-pr-reviews-20261111/pr-493 rev-parse HEAD matched manifest; git diff --check 42c5711 f28be4d and git status --short exited 0 with no output. Both completed reports were read. All assistant-message provider/model/responseModel identities, successful runner statuses, valid provenance, pinned heads and report SHA256 values were checked; two distinct response models confirmed.
- Astra: timeout 120s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync pytest tests/contracts/test_parse_pool_spawn_context.py tests/contracts/test_parse_pool_reused.py -p no:cacheprovider --basetemp=/tmp/chunkhound-pr-493-astra-a1-5gds8hrz/pytest-pool --timeout=30 -> exit 2, two native-import collection errors, zero tests collected.
- Astra: timeout 120s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync mypy chunkhound --cache-dir=/tmp/chunkhound-pr-493-astra-a1-5gds8hrz/mypy-cache -> exit 1, 993 errors in 89 files (373 checked). git show 42c5711:chunkhound/pipeline_bridge.py > /tmp/chunkhound-pr-493-astra-a1-5gds8hrz/pipeline_bridge.base.py; repeat with --shadow-file chunkhound/pipeline_bridge.py /tmp/chunkhound-pr-493-astra-a1-5gds8hrz/pipeline_bridge.base.py --cache-dir=/tmp/chunkhound-pr-493-astra-a1-5gds8hrz/mypy-base-cache -> exit 1, byte-identical diagnostics (cmp exit 0).
- Astra and reconciler: timeout 40s env UV_PROJECT_ENVIRONMENT=/home/e119870/views/g/my_chunkhound/.venv PYTHONDONTWRITEBYTECODE=1 uv run --no-sync python /tmp/chunkhound-pr-493-astra-a1-5gds8hrz/pool_smoke.py -> exit 0. Extracted _get_parse_pool executes work in a spawned child when invoked from a thread with global fork selected, reuses the child, and leaves global start method unchanged.
- Sonnet reported the same 993 mypy errors in 89 files without baseline comparison, and its spawn/reuse pytest selection failed with two native-import collection errors. No passing native contract claim is made.
Limitations
- Native-dependent tests did not execute successfully: the shared environment lacks chunkhound_native.chunkhound_native. No native build, dependency installation, network call, source edit or environment repair was performed. CI is only the captured green snapshot, not a fresh run.
- Supplemental probes extract production definitions and use real external libraries/processes with simplified surrounding state. They are not end-to-end native indexing or MCP verification.
- The original Linux MCP stdin-lock deadlock and reported query-ready timings were not reproduced. The supplemental smoke does not run the real parser or MCP startup.
- CI is a captured snapshot, not a fresh run or a guarantee of current branch status.
- Model identities are verified declarations supplied by the reconciler; the renderer does not inspect raw reports or provenance events.
Disposition of discarded / merged findings
- Neither reviewer proposed an actionable defect. Discarded throwaway-test atexit registrations as harmless idempotent cleanup, not a user-visible regression.
- Spawn importability and startup overhead are real constraints but already exercised by existing spawn paths and supported platform entry points; no newly failing supported caller or unacceptable measured overhead was established.
- PR #492 separately replaces this accessor with a lease-based constructor. If integrating both branches, preserve this explicit spawn choice in the resulting constructor; that overlap is integration advice, not a defect in this pinned diff.
Independent reviewer provenance
- sonnet — provider: amat-tfy; requested model: standard-chat-dev/claude-sonnet-5.5; verified response model: aws-aidev-models/us.anthropic.claude-sonnet-5-5. Identity evidence · Raw report
- astra — provider: amat-tfy; requested model: frontier-chat-dev/gpt-6-astra; verified response model: gpt-6-astra. Identity evidence · Raw report
CI snapshot
Captured: 2026-11-11T14:18:23.581921+00:00. Eligibility green: True. Counts: {"SKIPPED": 2, "SUCCESS": 23}
- site-build: SUCCESS (COMPLETED)
- site-build-validation (ubuntu-latest): SUCCESS (COMPLETED)
- site-build-validation (macos-latest): SUCCESS (COMPLETED)
- site-build-validation (windows-latest): SUCCESS (COMPLETED)
- rust-checks (ubuntu-latest): SUCCESS (COMPLETED)
- rust-checks (macos-latest): SUCCESS (COMPLETED)
- rust-checks (windows-latest): SUCCESS (COMPLETED)
- native-wheel-smoke-arm64: SUCCESS (COMPLETED)
- native-dev-macos: SUCCESS (COMPLETED)
- watchman-runtime-validation (ubuntu-latest, 3.14): SUCCESS (COMPLETED)
- watchman-runtime-validation (windows-latest, 3.14): SUCCESS (COMPLETED)
- tests (ubuntu-latest, 3.14, 1): SUCCESS (COMPLETED)
- tests (ubuntu-latest, 3.14, 2): SUCCESS (COMPLETED)
- tests (ubuntu-latest, 3.14, 3): SUCCESS (COMPLETED)
- tests (macos-latest, 3.14, 1): SUCCESS (COMPLETED)
- tests (macos-latest, 3.14, 2): SUCCESS (COMPLETED)
- tests (macos-latest, 3.14, 3): SUCCESS (COMPLETED)
- tests (windows-latest, 3.14, 1): SUCCESS (COMPLETED)
- tests (windows-latest, 3.14, 2): SUCCESS (COMPLETED)
- tests (windows-latest, 3.14, 3): SUCCESS (COMPLETED)
- old-linux-wheel-smoke (Ubuntu 20.04 (glibc 2.31), UBUNTU_20_04_IMAGE, ca-certificates curl, 3.12): SUCCESS (COMPLETED)
- old-linux-wheel-smoke (Ubuntu 22.04 + Python 3.10, UBUNTU_22_04_IMAGE, ca-certificates curl pytho...: SUCCESS (COMPLETED)
- watchman-rollout-gate: SUCCESS (COMPLETED)
- pages-artifact: SKIPPED (COMPLETED)
- deploy: SKIPPED (COMPLETED)
Reviewed by Ariel Vaknin via pi.dev
Brings in the 12 commits merged to main since this branch was last updated, including chunkhound#534's rust-checks fix. No conflicts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolves the conflict with chunkhound#492 (parse-pool idle shrink, 00f4421) in chunkhound/pipeline_bridge.py. chunkhound#492 removed _get_parse_pool(); the pool is now created only in _new_parse_pool_locked(), so this PR's spawn mp_context and its comment move there, and the lease code is upstream's. tests/contracts/test_parse_pool_spawn_context.py called the removed _get_parse_pool(): it now creates the pool through a lease and resets it with _shut_down_parse_pool_at_exit(), as upstream's parse-pool tests do. Its assertions are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
On Linux,
chunkhound mcpcan stay atfiles_processed: 0/query_ready: falseforever after start-up.The parse pool in
pipeline_bridge._get_parse_pool()is created with nomp_context, so it uses the platform default, which on Linux (Python < 3.14) isfork. An MCP server creates the pool from a process that already runs threads, among them the stdio reader that holdssys.stdin's lock. A forked worker inherits that lock in the held state and blocks inmultiprocessing.util._close_stdin()before it runs any task. The parse thread then waits on the worker's future forever.indexing_coordinator._ensure_mp_start_method()sets the global start method to spawn, but the realtime/MCP start-up path can create this pool before that function runs.chunkhound indexis not affected, because it creates the pool before any such thread exists.Evidence
Measured in a Linux container (Debian trixie, Python 3.12) with a one-file scratch project and
realtime_backend: watchdog:py-spy dumpof a parse worker showed_close_stdin (multiprocessing/util.py)underProcessPoolExecutor._spawn_process/ForkProcess. The server's parse thread was inFuture.resultunderparse_batch_callback.is_scanning: true, files_processed: 0after 120 s.mp_context=get_context("spawn"):query_readyin 13.8 s (2 files, 13 chunks).Windows and macOS already default to spawn, which is why this only shows up on Linux.
Change
_get_parse_pool()passesmp_context=multiprocessing.get_context("spawn"), the same choicebatch_processor.pyand the per-file timeout worker in this module already make.Test
tests/contracts/test_parse_pool_spawn_context.pyrecords themp_contextthe pool is constructed with and asserts its start method isspawn. It checks the context the pool is given, not the platform default, so it fails before the fix on every OS. A real fork deadlock can't be reproduced on a Windows CI runner. The existingtest_parse_pool_reused.pystill passes.Broader run (Windows 11, Python 3.12, serial). This was on our fork branch, which carries the same change on top of other pending fixes.
tests/contracts+tests/realtime+tests/test_realtime_*.py: 272 passed, 38 skipped, 1 failed. The one failure wastests/contracts/test_rust_pipeline_indexes_pdf.py::TestRustPipelineIndexesPdf::test_pdf_file_is_stored_as_chunks("zero pdf chunks"), and the evidence says it is load-flaky, not related to this change: the box was running a largenpm installat the time. That test passed alone without the change (1/1) and with it (2/2), and a full rerun oftests/contractswith the change passed 127/127 (4 skipped). On Windows the pool already used spawn, so this change doesn't alter Windows behaviour.Update after #495 and #487
main. fix(parse): pool and timeout workers exit when their parent dies #487 addedinitializer=exit_when_parent_diesto the sameProcessPoolExecutor(...)call. The pool now passes both arguments, and both are load-bearing: withoutmp_context,test_parse_pool_is_created_with_a_spawn_contextfails; without the initializer, fix(parse): pool and timeout workers exit when their parent dies #487'stest_parse_pool_worker_exits_when_parent_is_killedfails.chunkhound/utils/stdio_lines.py), not a thread holdingsys.stdin's lock. So the specific deadlock above was measured on the code before Migrate MCP SDK 1.16 → 2.x with a single dispatch point #495, and I haven't re-measured it on currentmain. The change is still the right default for this pool: it is created inside a process that runs threads, whereforkis unsafe in general (Python 3.12+ warns about it, and 3.14 stops using it as the Linux default), and it was the only pool in this module not already using spawn.mp_context=multiprocessing.get_context("spawn")to_get_parse_pool. Whichever merges first, the other's change to that line is already onmain._get_parse_pool()and creates the pool inside a lease that shuts it down when idle. Whichever of the two merges second needsmainmerged in, and the spawn context moves into perf(parse): shut the parse pool down after 60 s with no batch in flight #492's pool creation. I'll do that merge.🤖 Generated with Claude Code, reviewed by FStrasz