Repository navigation
refactor: split ingest pipeline runtimes - #297
Conversation
📝 WalkthroughWalkthroughAll three pipeline service files have been refactored to extract common logic into specialized helper functions, improving code organization and reducing duplication across conversation processing, ingestion, and planning workflows without altering public entity signatures. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@polylogue/pipeline/services/ingest_batch.py`:
- Around line 887-908: The helper _apply_ingest_batch_summary currently mutates
ParseResult._changed_conversation_ids directly; avoid touching the internal
attribute by adding a small public mutator on ParseResult (e.g.,
extend_changed_conversation_ids or append_changed_conversation_ids) and use that
from _apply_ingest_batch_summary instead of accessing _changed_conversation_ids,
or alternatively rename the attribute to changed_conversation_ids if it is
intended to be part of the module API and update all callers accordingly; update
the call site in _apply_ingest_batch_summary to call the new public method (or
the renamed attribute) and keep the rest of the aggregation logic the same.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: e2e812b4-61d6-49be-a1af-39d6e2d7b1e4
📒 Files selected for processing (3)
polylogue/pipeline/services/ingest_batch.pypolylogue/pipeline/services/ingest_worker.pypolylogue/pipeline/services/planning_runtime.py
| def _apply_ingest_batch_summary(result: ParseResult, batch_summary: _IngestBatchSummary) -> None: | ||
| result.parse_failures += batch_summary.parse_failures | ||
| result.processed_ids.update(batch_summary.processed_ids) | ||
| result._changed_conversation_ids.extend(batch_summary.changed_conversation_ids) | ||
| for key, value in batch_summary.counts.items(): | ||
| if key in result.counts: | ||
| result.counts[key] += value | ||
| for key, value in batch_summary.changed_counts.items(): | ||
| if key in result.changed_counts: | ||
| result.changed_counts[key] += value | ||
|
|
||
|
|
||
| def _progressed_raw_count(batch_summary: _IngestBatchSummary) -> int: | ||
| return sum(1 for outcome in batch_summary.outcomes.values() if outcome.had_conversations and outcome.error is None) | ||
|
|
||
|
|
||
| def _successful_raw_ids(batch_summary: _IngestBatchSummary) -> set[str]: | ||
| return { | ||
| raw_id | ||
| for raw_id, outcome in batch_summary.outcomes.items() | ||
| if outcome.had_conversations and raw_id not in batch_summary.failed_raw_ids | ||
| } |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Minor: _apply_ingest_batch_summary reaches into result._changed_conversation_ids.
Not introduced by this PR (the underscore-prefixed attribute predates it), but this is a good opportunity to either (a) expose a small extend_changed_conversation_ids(...) method on ParseResult, or (b) rename the attribute to drop the leading underscore if it is effectively part of the module-level API used here and by the enriched summary flow. Keeping the current access works, but it leaves ingest_batch.py coupled to ParseResult's internal representation.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@polylogue/pipeline/services/ingest_batch.py` around lines 887 - 908, The
helper _apply_ingest_batch_summary currently mutates
ParseResult._changed_conversation_ids directly; avoid touching the internal
attribute by adding a small public mutator on ParseResult (e.g.,
extend_changed_conversation_ids or append_changed_conversation_ids) and use that
from _apply_ingest_batch_summary instead of accessing _changed_conversation_ids,
or alternatively rename the attribute to changed_conversation_ids if it is
intended to be part of the module API and update all callers accordingly; update
the call site in _apply_ingest_batch_summary to call the new public method (or
the renamed attribute) and keep the rest of the aggregation logic the same.
## Summary - Split `build_ingest_plan` into focused helpers for stage flags, early plan summaries, parse backlog planning, and final count construction. - Split ingest batch processing into typed lifecycle helpers for sync setup, worker-result consumption, commit/flush, parse-result application, and observation construction. - Split ingest worker materialization into named DB tuple builders for conversations, messages, content blocks, stats, attachments, and action events. - Preserve existing SQL, worker process, cursor, raw-state, and session-product refresh behavior while making each lifecycle boundary explicit. ## Problem The ingest path had several path-dependent long functions where independent concerns were interleaved: stage planning, source scanning, worker result waiting, DB writes, parent/child conversation drainage, raw-state updates, metrics observation, and DB tuple construction. That shape made future changes risky because a small edit had to reason through the whole function body. ## Solution Introduced small typed helper boundaries around the existing ingest runtime contracts. Planning now delegates independent plan modes and count projection. Batch ingest now names the sync lifecycle phases and async result projection. Worker materialization now exposes tuple construction as stable, local builder functions instead of embedding every row shape in the main transform path. ## Verification - `ruff check --fix polylogue/pipeline/services/planning_runtime.py` - `ruff format polylogue/pipeline/services/planning_runtime.py` - `mypy polylogue/pipeline/services/planning_runtime.py tests/unit/pipeline/test_parsing_service.py` - `pytest -q tests/unit/pipeline/test_parsing_service.py` - `pytest -q tests/unit/pipeline/test_parsing_service.py tests/unit/pipeline/test_run_sources.py tests/unit/cli/test_run_int.py tests/unit/cli/test_run.py` - `ruff check --fix polylogue/pipeline/services/ingest_batch.py` - `ruff format polylogue/pipeline/services/ingest_batch.py` - `mypy polylogue/pipeline/services/ingest_batch.py tests/unit/pipeline/test_ingest_batch.py tests/unit/pipeline/test_run_sources.py` - `pytest -q tests/unit/pipeline/test_ingest_batch.py tests/unit/pipeline/test_run_sources.py tests/unit/pipeline/test_parsing_service.py` - `ruff check --fix polylogue/pipeline/services/ingest_worker.py` - `ruff format polylogue/pipeline/services/ingest_worker.py` - `mypy polylogue/pipeline/services/ingest_worker.py tests/unit/pipeline/test_ingest_batch.py tests/unit/pipeline/test_prepare_records.py` - `pytest -q tests/unit/pipeline/test_ingest_batch.py tests/unit/pipeline/test_prepare_records.py tests/unit/pipeline/test_run_sources.py` - `mypy polylogue tests` - `devtools verify --quick` Ref #281
The ingest path had several path-dependent long functions where independent concerns were interleaved: stage planning, source scanning, worker result waiting, DB writes, parent/child conversation drainage, raw-state updates, metrics observation, and DB tuple construction. A small edit had to reason through the whole function body. Splits `build_ingest_plan` into focused helpers for stage flags, early plan summaries, parse backlog planning, and final count construction. Splits ingest batch processing into typed lifecycle helpers for sync setup, worker-result consumption, commit/flush, parse-result application, and observation construction. Splits ingest worker materialization into named DB tuple builders for conversations, messages, content blocks, stats, attachments, and action events. Preserves existing SQL, worker process, cursor, raw-state, and session-product refresh behavior while making each lifecycle boundary explicit. Verification: ruff + mypy + pytest over planning / ingest_batch / ingest_worker paths; devtools verify --quick green. Ref #281
The ingest path had several path-dependent long functions where independent concerns were interleaved: stage planning, source scanning, worker result waiting, DB writes, parent/child conversation drainage, raw-state updates, metrics observation, and DB tuple construction. A small edit had to reason through the whole function body. Splits `build_ingest_plan` into focused helpers for stage flags, early plan summaries, parse backlog planning, and final count construction. Splits ingest batch processing into typed lifecycle helpers for sync setup, worker-result consumption, commit/flush, parse-result application, and observation construction. Splits ingest worker materialization into named DB tuple builders for conversations, messages, content blocks, stats, attachments, and action events. Preserves existing SQL, worker process, cursor, raw-state, and session-product refresh behavior while making each lifecycle boundary explicit. Verification: ruff + mypy + pytest over planning / ingest_batch / ingest_worker paths; devtools verify --quick green. Ref #281
The ingest path had several path-dependent long functions where independent concerns were interleaved: stage planning, source scanning, worker result waiting, DB writes, parent/child conversation drainage, raw-state updates, metrics observation, and DB tuple construction. A small edit had to reason through the whole function body. Splits `build_ingest_plan` into focused helpers for stage flags, early plan summaries, parse backlog planning, and final count construction. Splits ingest batch processing into typed lifecycle helpers for sync setup, worker-result consumption, commit/flush, parse-result application, and observation construction. Splits ingest worker materialization into named DB tuple builders for conversations, messages, content blocks, stats, attachments, and action events. Preserves existing SQL, worker process, cursor, raw-state, and session-product refresh behavior while making each lifecycle boundary explicit. Verification: ruff + mypy + pytest over planning / ingest_batch / ingest_worker paths; devtools verify --quick green. Ref #281
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Bumps [pytest-benchmark](https://github.com/ionelmc/pytest-benchmark) from 5.2.3 to 5.3.0. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/ionelmc/pytest-benchmark/releases">pytest-benchmark's releases</a>.</em></p> <blockquote> <h2>v5.3.0</h2> <ul> <li>Added --benchmark-precision and --benchmark-confidence: instead of a fixed number of rounds, stop once the mean's relative margin of error falls below the given fraction. Contributed by Aarni Koskela in <a href="https://redirect.github.com/ionelmc/pytest-benchmark/pull/318">ionelmc/pytest-benchmark#318</a>.</li> <li>Added compare --between mode. Example: pytest-benchmark compare --between=min 0001 0002. Contributed by Aarni Koskela in <a href="https://redirect.github.com/ionelmc/pytest-benchmark/pull/302">ionelmc/pytest-benchmark#302</a>.</li> <li>Modernized the CI/linting and added spellchecking. Contributed by Aarni Koskela in <a href="https://redirect.github.com/ionelmc/pytest-benchmark/pull/304">ionelmc/pytest-benchmark#304</a>, <a href="https://redirect.github.com/ionelmc/pytest-benchmark/pull/306">ionelmc/pytest-benchmark#306</a> and <a href="https://redirect.github.com/ionelmc/pytest-benchmark/pull/319">ionelmc/pytest-benchmark#319</a>.</li> <li>Defer the xdist auto-disable warning until a benchmark fixture is collected. Contributed by xlyyddy in <a href="https://redirect.github.com/ionelmc/pytest-benchmark/pull/317">ionelmc/pytest-benchmark#317</a> (fixes <a href="https://redirect.github.com/ionelmc/pytest-benchmark/issues/65">ionelmc/pytest-benchmark#65</a>).</li> <li>Replaced deprecated argparse.FileType. Contributed by Sophia Castellarin in <a href="https://redirect.github.com/ionelmc/pytest-benchmark/pull/310">ionelmc/pytest-benchmark#310</a>.</li> <li>Fixed various spelling/typos. Contributed by Daniel Holth and Hugo van Kemenade in <a href="https://redirect.github.com/ionelmc/pytest-benchmark/pull/297">ionelmc/pytest-benchmark#297</a> and <a href="https://redirect.github.com/ionelmc/pytest-benchmark/pull/299">ionelmc/pytest-benchmark#299</a>.</li> <li>Cleaned up various dead code. Contributed by Hugo van Kemenade in <a href="https://redirect.github.com/ionelmc/pytest-benchmark/pull/300">ionelmc/pytest-benchmark#300</a> and <a href="https://redirect.github.com/ionelmc/pytest-benchmark/pull/301">ionelmc/pytest-benchmark#301</a>.</li> <li>CI now tests only with latest Pytest (now 9.1.1), Python 3.10-3.14 and PyPy 3.11.</li> </ul> </blockquote> </details> <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/ionelmc/pytest-benchmark/blob/master/CHANGELOG.rst">pytest-benchmark's changelog</a>.</em></p> <blockquote> <h2>v5.3.0 (2026-08-23)</h2> <ul> <li>Added <code>--benchmark-precision</code> and <code>--benchmark-confidence</code>: instead of a fixed number of rounds, stop once the mean's relative margin of error falls below the given fraction. Contributed by Aarni Koskela in <code>[#318](ionelmc/pytest-benchmark#318) <https://github.com/ionelmc/pytest-benchmark/pull/318></code>_.</li> <li>Added <code>compare --between</code> mode. Example: <code>pytest-benchmark compare --between=min 0001 0002</code>. Contributed by Aarni Koskela in <code>[#302](ionelmc/pytest-benchmark#302) <https://github.com/ionelmc/pytest-benchmark/pull/302></code>_.</li> <li>Modernized the CI/linting and added spellchecking. Contributed by Aarni Koskela in <code>[#304](ionelmc/pytest-benchmark#304) <https://github.com/ionelmc/pytest-benchmark/pull/304></code><em>, <code>[#306](ionelmc/pytest-benchmark#306) <https://github.com/ionelmc/pytest-benchmark/pull/306></code></em> and <code>[#319](ionelmc/pytest-benchmark#319) <https://github.com/ionelmc/pytest-benchmark/pull/319></code>_.</li> <li>Defer the xdist auto-disable warning until a benchmark fixture is collected. Contributed by xlyyddy in <code>[#317](ionelmc/pytest-benchmark#317) <https://github.com/ionelmc/pytest-benchmark/pull/317></code>_ (fixes <code>[#65](ionelmc/pytest-benchmark#65) <https://github.com/ionelmc/pytest-benchmark/issues/65></code>_).</li> <li>Replaced deprecated argparse.FileType. Contributed by Sophia Castellarin in <code>[#310](ionelmc/pytest-benchmark#310) <https://github.com/ionelmc/pytest-benchmark/pull/310></code>_.</li> <li>Fixed various spelling/typos. Contributed by Daniel Holth and Hugo van Kemenade in <code>[#297](ionelmc/pytest-benchmark#297) <https://github.com/ionelmc/pytest-benchmark/pull/297></code>_ and <code>[#299](ionelmc/pytest-benchmark#299) <https://github.com/ionelmc/pytest-benchmark/pull/299></code>_.</li> <li>Cleaned up various dead code. Contributed by Hugo van Kemenade in <code>[#300](ionelmc/pytest-benchmark#300) <https://github.com/ionelmc/pytest-benchmark/pull/300></code>_ and <code>[#301](ionelmc/pytest-benchmark#301) <https://github.com/ionelmc/pytest-benchmark/pull/301></code>_.</li> <li>CI now tests only with latest Pytest (now 9.1.1), Python 3.10-3.14 and PyPy 3.11.</li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/ionelmc/pytest-benchmark/commit/07d519672687402e6c3fac1a543fbefd810d1e5b"><code>07d5196</code></a> Bump version: 5.2.3 → 5.3.0</li> <li><a href="https://github.com/ionelmc/pytest-benchmark/commit/accf7331e22c0ede38ffa72081c38f3469e0c9b5"><code>accf733</code></a> Add some details on <a href="https://redirect.github.com/ionelmc/pytest-benchmark/issues/304">#304</a>.</li> <li><a href="https://github.com/ionelmc/pytest-benchmark/commit/417dd9fa275e8b9d62c469e676cdb7546d2c4b8f"><code>417dd9f</code></a> Really update the changelog.</li> <li><a href="https://github.com/ionelmc/pytest-benchmark/commit/898acb34430c99ad877e94c52c8b90256a3bb4a8"><code>898acb3</code></a> Update changelog and plan release.</li> <li><a href="https://github.com/ionelmc/pytest-benchmark/commit/9cc7ef0bb1ad3785a46834b24660562dd48e4a0b"><code>9cc7ef0</code></a> Defer xdist warning until benchmark collection (<a href="https://redirect.github.com/ionelmc/pytest-benchmark/issues/65">#65</a>)</li> <li><a href="https://github.com/ionelmc/pytest-benchmark/commit/ef485506f04d5510831fdbdee5be7014f4726a93"><code>ef48550</code></a> Some minor skel updates: test only against latest pytest; bump linting/format...</li> <li><a href="https://github.com/ionelmc/pytest-benchmark/commit/88eaea957d1685f604a5835555d2ce5dbec1ac29"><code>88eaea9</code></a> Add --benchmark-precision for adaptive rounds (opt-in)</li> <li><a href="https://github.com/ionelmc/pytest-benchmark/commit/3b83d127127de74d9f71a3a78e5f661fac044950"><code>3b83d12</code></a> Update and freeze GHA actions</li> <li><a href="https://github.com/ionelmc/pytest-benchmark/commit/4b7662fbfba046eb92dd183e005e8708ac81e6cd"><code>4b7662f</code></a> Fix ruff complaints</li> <li><a href="https://github.com/ionelmc/pytest-benchmark/commit/26b011361d2c41f529a73833e1be8d3a565600fa"><code>26b0113</code></a> Remove Taplo lint (unmaintained)</li> <li>Additional commits viewable in <a href="https://github.com/ionelmc/pytest-benchmark/compare/v5.2.3...v5.3.0">compare view</a></li> </ul> </details> <br /> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Summary
build_ingest_planinto focused helpers for stage flags, early plan summaries, parse backlog planning, and final count construction.Problem
The ingest path had several path-dependent long functions where independent concerns were interleaved: stage planning, source scanning, worker result waiting, DB writes, parent/child conversation drainage, raw-state updates, metrics observation, and DB tuple construction. That shape made future changes risky because a small edit had to reason through the whole function body.
Solution
Introduced small typed helper boundaries around the existing ingest runtime contracts. Planning now delegates independent plan modes and count projection. Batch ingest now names the sync lifecycle phases and async result projection. Worker materialization now exposes tuple construction as stable, local builder functions instead of embedding every row shape in the main transform path.
Verification
ruff check --fix polylogue/pipeline/services/planning_runtime.pyruff format polylogue/pipeline/services/planning_runtime.pymypy polylogue/pipeline/services/planning_runtime.py tests/unit/pipeline/test_parsing_service.pypytest -q tests/unit/pipeline/test_parsing_service.pypytest -q tests/unit/pipeline/test_parsing_service.py tests/unit/pipeline/test_run_sources.py tests/unit/cli/test_run_int.py tests/unit/cli/test_run.pyruff check --fix polylogue/pipeline/services/ingest_batch.pyruff format polylogue/pipeline/services/ingest_batch.pymypy polylogue/pipeline/services/ingest_batch.py tests/unit/pipeline/test_ingest_batch.py tests/unit/pipeline/test_run_sources.pypytest -q tests/unit/pipeline/test_ingest_batch.py tests/unit/pipeline/test_run_sources.py tests/unit/pipeline/test_parsing_service.pyruff check --fix polylogue/pipeline/services/ingest_worker.pyruff format polylogue/pipeline/services/ingest_worker.pymypy polylogue/pipeline/services/ingest_worker.py tests/unit/pipeline/test_ingest_batch.py tests/unit/pipeline/test_prepare_records.pypytest -q tests/unit/pipeline/test_ingest_batch.py tests/unit/pipeline/test_prepare_records.py tests/unit/pipeline/test_run_sources.pymypy polylogue testsdevtools verify --quickRef #281