Skip to content

feat(core): Pipeline + Batcher primitives (Step 1.1d)#50

Merged
officialCodeWork merged 1 commit into
mainfrom
build/phase-1/step-1.1d-pipeline-batcher-primitives
May 24, 2026
Merged

feat(core): Pipeline + Batcher primitives (Step 1.1d)#50
officialCodeWork merged 1 commit into
mainfrom
build/phase-1/step-1.1d-pipeline-batcher-primitives

Conversation

@officialCodeWork

Copy link
Copy Markdown
Owner

Summary

  • Adds Pipeline (rag_core.pipeline) — composable async DAG with bounded queues, per-stage worker counts, and natural backpressure. Joiner tasks per stage transition cleanly handle different upstream/downstream worker counts; on_error="fail" / "skip" policies; optional error_handler callback.
  • Adds Batcher[Req, Resp] (rag_core.batcher) — DataLoader-pattern middleware that coalesces concurrent load(req) calls into one batched batch_fn(reqs) invocation. Size trigger (max_batch_size) + time trigger (max_wait_ms, default 5 ms). Per-request asyncio.Future for isolated error propagation; flush() for deterministic shutdown.
  • Both use PEP-695 generic syntax. CancelledError is intentionally allowed to propagate everywhere so structured cancellation tears the pipeline down cleanly.
  • rag-core 0.5.0 → 0.6.0.

Step 1.1d of the Phase 1 refactor window (1.1a–1.1f). Unblocks Step 1.10 (write path), Step 1.2 (connectors framework), and the future Embedder / Reranker / LLM adapters that will sit under the Batcher per the performance.md reviewer checklist.

Tests

  • 22 new tests: 8 covering Batcher (coalescing, size/time triggers, error propagation, length-mismatch, flush, validation) and 14 covering Pipeline (one-to-one, none-drops, list fan-out, multi-stage chain, per-stage concurrency, bounded-queue backpressure, fail/skip error policies, source-exception surfacing, duplicate-name rejection, Stage validation, default queue sizing, early-break cleanup).
  • Full repo: 549 passed, 1 skipped.
  • task lint clean; mypy --strict clean for new files (two pre-existing rag_observability import-resolution warnings in rag_core.logging / rag_core.events shims are unchanged from main).

Documentation

Per the per-PR docs requirement (CLAUDE.md):

Tracker

Test plan

  • uv run pytest packages/core/tests/test_batcher.py packages/core/tests/test_pipeline.py -x
  • uv run pytest tests/ packages/ -k "not integration" (549 passed)
  • uv run ruff check . clean
  • uv run mypy packages/core/ apps/gateway/ clean for new files
  • Schema regeneration (PYTHONPATH=packages/core/src:packages/observability/src uv run python -m rag_core.gen_schemas dist/schemas/) — no drift

🤖 Generated with Claude Code

Adds the two cross-cutting concurrency primitives the rest of Phase 1
will build on:

- ``Pipeline`` (``rag_core.pipeline``) — composable async DAG with
  bounded queues, per-stage worker counts, and natural backpressure.
  Stage functions return one item, a ``list[...]`` for fan-out, or
  ``None`` to drop. ``on_error="fail"`` / ``"skip"`` policies; optional
  ``error_handler`` callback. Joiner tasks per stage transition handle
  the different upstream/downstream worker counts cleanly (one ``_DONE``
  sentinel per next-stage worker, never more, never fewer).
- ``Batcher[Req, Resp]`` (``rag_core.batcher``) — DataLoader-pattern
  middleware that coalesces concurrent ``load(req)`` calls into one
  ``batch_fn(reqs)`` invocation. Size trigger (``max_batch_size``) and
  time trigger (``max_wait_ms``, default 5 ms). Per-request
  ``asyncio.Future`` keeps error propagation isolated; ``flush()``
  forces deterministic shutdown.

Both primitives use PEP-695 generic syntax. CancelledError is
intentionally allowed to propagate in every layer so structured
cancellation tears the pipeline down cleanly.

Tests: 22 new (8 Batcher + 14 Pipeline) covering coalescing, size /
time triggers, error propagation, length-mismatch handling, fan-out,
filter, backpressure, per-stage worker concurrency, fail / skip
error policies, source-exception surfacing, and early-break cleanup.
Full suite: 549 passed, 1 skipped.

Documentation
-------------
- New: docs/architecture/pipeline-batcher.md — design, usage, internals,
  extension points.
- Updated: docs/reference/rag-core.md (Concurrency primitives section),
  docs/README.md (index entries), docs/architecture/performance.md
  (cross-link).

Step 1.1d of the Phase 1 refactor window (1.1a–1.1f). Unblocks Step 1.10
(write-path), Step 1.2 (connectors framework), and the future Embedder /
Reranker / LLM adapters that will sit under the Batcher per the
performance.md reviewer checklist.

``rag-core`` 0.5.0 → 0.6.0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@officialCodeWork
officialCodeWork merged commit 9bae750 into main May 24, 2026
11 checks passed
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