Skip to content

fix(demo): stop demo seed parsing from spawning a real process pool - #3221

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/demo-seed-parse-pool-nondeterminism
Jul 20, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/demo-seed-parse-pool-nondeterminism

Conversation

@Sinity

@Sinity Sinity commented Jul 20, 2026

Copy link
Copy Markdown
Owner

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_overlays reported 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) calls parse_sources_archive without pinning a worker count, so the demo's ~9 sources / couple dozen files went through parse_sources_archive's ambient ProcessPoolExecutor path (default up to cpus-1 real 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 in parse_sources_archive's as_completed loop by except Exception: failed += 1; ...continue (archive_ingest.py:299-306) — silently dropping that file's sessions with only a logger.error line, 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_archive gains an optional parse_workers: int | None = None keyword that overrides the ambient/env-resolved worker count for one call. None preserves existing behavior for every other caller (real ingest, daemon, other tests).
  • polylogue/demo/seed.py: seed_demo_archive now calls parse_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 passed
  • Two new regression tests exercise the real production route (not mocks of their own claim):
    • test_parse_workers_override_bypasses_process_pool spies on the actual ProcessPoolExecutor construction inside parse_sources_archive: parse_workers=1 never constructs it (sequential branch), parse_workers=3 constructs it with exactly max_workers=3. Anti-vacuity: reverting the max(1, parse_workers) override in parse_sources_archive back to always calling _parse_worker_count() makes this test fail with TypeError: parse_sources_archive() got an unexpected keyword argument 'parse_workers' (confirmed by temporarily reverting and re-running).
    • test_seed_demo_archive_forces_sequential_parse_workers spies on the demo seeder's real parse_sources_archive call via a delegating wrapper (archive tiers are still populated by genuine ingest) and asserts parse_workers=1 is always passed. Anti-vacuity: reverting the seed.py call site fails this test with assert None == 1 (confirmed by temporarily reverting and re-running).
  • tests/unit/demo/test_demo_seed_verify.py repeated 3× under POLYLOGUE_PYTEST_WORKERS=8 xdist → 9/9 passed each run (no flakes observed).
  • mypy --strict on all 4 touched files → Success: no issues found in 4 source files.
  • devtools verify --quick → exit_code: 0 (all 16 static/generated gates green, including ruff 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).
  • Pre-push hook's own devtools verify --quick baseline ran again and passed (exit_code: 0).
  • Not run: the parent bead's (polylogue-b054.1.1) full 20-isolated + 20-xdist repetition proof and two-consecutive-8-worker-seed-testmon-run proof (AC4/AC5 of that broader bead) — out of scope for this narrower child bead's root-cause fix. The demo test file itself was run repeatedly under xdist as targeted evidence the specific mechanism identified here is addressed; it does not substitute for the parent bead's broader harness-level proof obligation.

Residual risk

This fixes the demo-seeding-specific instance of the swallowed-pool-failure hazard. The underlying except Exception: failed += 1; continue pattern in parse_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

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]>
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 27 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 38006e2d-853c-4230-a1b9-e14c7c69b435

📥 Commits

Reviewing files that changed from the base of the PR and between 93a5388 and bae721a.

📒 Files selected for processing (4)
  • polylogue/demo/seed.py
  • polylogue/pipeline/services/archive_ingest.py
  • tests/unit/demo/test_demo_seed_verify.py
  • tests/unit/pipeline/test_archive_ingest_commit_batching.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/demo-seed-parse-pool-nondeterminism

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Sinity

Sinity commented Jul 20, 2026

Copy link
Copy Markdown
Owner Author

Coordinator review stand-in (CodeRabbit rate-limited — no findings produced).

Read the full diff. Assessment:

  • Root cause is real and the fix removes it structurally: demo seeding routed a ~dozen-file fixed corpus through the ambient spawn-based ProcessPoolExecutor (up to cpus-1 workers), and the pool driver's except Exception: failed += 1; continue silently drops a failed file's sessions — under 8-worker xdist each test worker spawned its own sub-pool, making transient BrokenProcessPool/spawn failures both likely and invisible. Pinning parse_workers=1 takes the sequential branch: no pool is ever constructed, so demo determinism no longer depends on host pressure.
  • Override is surgically scoped: keyword-only param, None preserves the exact prior env/cpu resolution for every real ingest caller; max(1, ...) guards nonsense values.
  • Tests are non-vacuous: the pool-bypass test spies on the actual ProcessPoolExecutor construction and both branches are exercised (parse_workers=1 → no pool; parse_workers=3 → pool with exactly 3); the seeder test spies through a delegating wrapper so the genuine ingest route still runs. Both confirmed failing against pre-fix code per PR body.
  • AC honesty: the bead's broader stress-harness/20+20-rep proof is explicitly reported as not run — that belongs to the parent harness scope; noted in the bead close.

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.

@Sinity
Sinity merged commit 3353376 into master Jul 20, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the feature/fix/demo-seed-parse-pool-nondeterminism branch July 20, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant