Repository navigation
fix(demo): stop demo seed parsing from spawning a real process pool - #3221
Conversation
Problem: polylogue-b054.1.1.1 observed a nondeterministic demo-archive declared-construct-below-minimum failure under an 8-worker xdist run. seed_demo_archive's parse_sources_archive call did not pin a worker count, so the small fixed demo corpus (~9 sources, a couple dozen files) went through parse_sources_archive's ambient ProcessPoolExecutor path (default up to cpus-1 real spawn subprocesses). Under pytest-xdist every one of the (up to 8) test worker processes independently spawns its own sub-pool, so a demo seed under load competes for CPU/memory with many other concurrent pools. A per-file worker task failure there (BrokenProcessPool, transient spawn/OOM) is caught by the pool driver's `except Exception: failed += 1; continue` and silently drops that file's sessions with only a log line -- no raised error -- matching the bead's observed symptom exactly (a demo fixture file's content vanishing under load with no test-visible signal until construct-coverage happened to depend on it). Solution: add an optional `parse_workers` override to parse_sources_archive (polylogue/pipeline/services/archive_ingest.py) that pins the worker count for one call, independent of the ambient POLYLOGUE_INGEST_PARSE_WORKERS/cpu-count resolution. seed_demo_archive now passes parse_workers=1, so demo seeding always takes the sequential for-loop path and never constructs a subprocess pool for this fixed-size synthetic corpus -- the pool exists to overlap CPU-bound parse with I/O-bound writes on real bulk archives, and buys nothing at demo scale while adding host-load-dependent nondeterminism. Two new regression tests exercise the real production route: - test_parse_workers_override_bypasses_process_pool (tests/unit/pipeline/test_archive_ingest_commit_batching.py) spies on the actual ProcessPoolExecutor construction inside parse_sources_archive and proves parse_workers=1 never constructs it while parse_workers=3 does, with the exact worker count threaded through. Reverting the `max(1, parse_workers)` override in parse_sources_archive fails this test with TypeError/unexpected-pool-construction. - test_seed_demo_archive_forces_sequential_parse_workers (tests/unit/demo/test_demo_seed_verify.py) spies on the demo seeder's real parse_sources_archive call (via a delegating wrapper, so the archive tiers are still populated by genuine ingest) and asserts parse_workers=1 is always passed. Reverting the seed.py call site fails this test with `assert None == 1`. Verification: - devtools test tests/unit/demo/test_demo_seed_verify.py tests/unit/pipeline/test_archive_ingest_commit_batching.py tests/unit/scenarios/test_demo_archive_convergence.py -> 20 passed - Both new tests independently confirmed to fail against the pre-fix code (anti-vacuity check, reverted then restored). - tests/unit/demo/test_demo_seed_verify.py repeated 3x under POLYLOGUE_PYTEST_WORKERS=8 xdist -> 9/9 passed each run. - mypy --strict on all 4 touched files -> Success, no issues found. - devtools verify --quick -> exit_code 0 (all 16 static/generated gates green, including ruff format/check). - Not run: the parent bead's full 20-isolated + 20-xdist repetition proof and the two-consecutive-8-worker-seed-testmon-run proof (polylogue-b054.1.1 AC4/AC5 scope) -- out of scope for this narrower child bead's root-cause fix; the demo test file itself was run repeatedly under xdist as evidence the specific mechanism is addressed. Ref polylogue-b054.1.1.1 Co-Authored-By: Claude <[email protected]>
|
Warning Review limit reached
Next review available in: 27 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Coordinator review stand-in (CodeRabbit rate-limited — no findings produced). Read the full diff. Assessment:
Verification per PR body: 20 focused tests green, 3× repeated 8-worker xdist runs of the demo file 9/9 each, mypy --strict clean, quick-gate green. Merging. |
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QUsH3Rhq6oAZpYPWcsZqnZ
Summary
The demo seeder now forces sequential (single-worker) parsing instead of routing its fixed, small fixture corpus through a real subprocess
ProcessPoolExecutor.Problem
polylogue-b054.1.1.1 observed a nondeterministic demo-archive failure under an 8-worker xdist run:
tests/unit/demo/test_demo_seed_verify.py::test_demo_verify_reports_missing_overlaysreported at least one declared construct below its minimum, but the exact node and its same-worker predecessors pass in isolation — load/order/leaked-process-state, not a deterministic mismatch.seed_demo_archive(polylogue/demo/seed.py) callsparse_sources_archivewithout pinning a worker count, so the demo's ~9 sources / couple dozen files went throughparse_sources_archive's ambientProcessPoolExecutorpath (default up tocpus-1real spawn subprocesses,polylogue/pipeline/services/process_pool.py). Under pytest-xdist, every one of the (up to 8) test worker processes independently spawns its own sub-pool — up to dozens of concurrent subprocesses competing for CPU/memory on the host for a corpus that pooling was never meant to help (pooling exists to overlap CPU-bound parse with I/O-bound writes on real bulk archives,polylogue/pipeline/services/archive_ingest.py:59-65).A per-file worker task failure under that load (
BrokenProcessPool, transient spawn/OOM) is caught inparse_sources_archive'sas_completedloop byexcept Exception: failed += 1; ...continue(archive_ingest.py:299-306) — silently dropping that file's sessions with only alogger.errorline, no raised error. This is a plausible, reproducible mechanism for exactly the observed symptom: a demo fixture file's content occasionally vanishing under host load with no test-visible signal, until construct-coverage happened to depend on the missing content.Solution
polylogue/pipeline/services/archive_ingest.py:parse_sources_archivegains an optionalparse_workers: int | None = Nonekeyword that overrides the ambient/env-resolved worker count for one call.Nonepreserves existing behavior for every other caller (real ingest, daemon, other tests).polylogue/demo/seed.py:seed_demo_archivenow callsparse_sources_archive(..., parse_workers=1), so demo seeding always takes the sequential for-loop branch and never constructs a subprocess pool for this fixed-size synthetic corpus — removing the host-load dependency entirely for this path.Verification
devtools test tests/unit/demo/test_demo_seed_verify.py tests/unit/pipeline/test_archive_ingest_commit_batching.py tests/unit/scenarios/test_demo_archive_convergence.py→ 20 passedtest_parse_workers_override_bypasses_process_poolspies on the actualProcessPoolExecutorconstruction insideparse_sources_archive:parse_workers=1never constructs it (sequential branch),parse_workers=3constructs it with exactlymax_workers=3. Anti-vacuity: reverting themax(1, parse_workers)override inparse_sources_archiveback to always calling_parse_worker_count()makes this test fail withTypeError: parse_sources_archive() got an unexpected keyword argument 'parse_workers'(confirmed by temporarily reverting and re-running).test_seed_demo_archive_forces_sequential_parse_workersspies on the demo seeder's realparse_sources_archivecall via a delegating wrapper (archive tiers are still populated by genuine ingest) and assertsparse_workers=1is always passed. Anti-vacuity: reverting theseed.pycall site fails this test withassert None == 1(confirmed by temporarily reverting and re-running).tests/unit/demo/test_demo_seed_verify.pyrepeated 3× underPOLYLOGUE_PYTEST_WORKERS=8xdist → 9/9 passed each run (no flakes observed).mypy --stricton all 4 touched files →Success: no issues found in 4 source files.devtools verify --quick→exit_code: 0(all 16 static/generated gates green, includingruff format/ruff check,render all, topology/layering/closure-matrix, schema roundtrip, manifests, ci-workflows, doc-commands, docs-coverage, test-infra-currency, test-clock-hygiene, pytest-timeout-overrides, degrade-loudly).devtools verify --quickbaseline ran again and passed (exit_code: 0).Residual risk
This fixes the demo-seeding-specific instance of the swallowed-pool-failure hazard. The underlying
except Exception: failed += 1; continuepattern inparse_sources_archive's pool branch still silently drops content on any real-archive ingest under the same failure conditions (BrokenProcessPool, worker OOM) — that is intentional production resilience (one bad file shouldn't kill a bulk ingest run) and out of this bead's scope, but it means the same class of silent-drop could still occur for real (non-demo) multi-worker ingests under host pressure. No new tracking item filed for that, since it is an existing, documented (log-line) behavior, not something this change introduces or regresses.Ref polylogue-b054.1.1.1