Skip to content

refactor(pipeline): split ingest_batch.py — 8 concerns in 1295 lines, 32 commits in 6 months #781

Closed

Description

@Sinity

Problem

pipeline/services/ingest_batch.py is the most diseased file in the codebase. 1,295 lines packing 8 distinct concerns: DB connection management, topological sorting, write operations, worker pool dispatch, result processing, FTS trigger lifecycle, raw state updates, and session insight refresh. 32 commits in 6 months (5 fixes, 11 refactors). FTS trigger management has been broken and patched multiple times.

Sync/async divergence in the same file: _process_ingest_batch_sync uses sync sqlite3, refresh_session_insights_bulk uses aiosqlite. Two different DB access patterns.

Proposed split

pipeline/services/ingest_batch/
  __init__.py          # process_ingest_batch
  models.py            # protocols, dataclasses, SQL constants
  topo_sort.py         # parent-child conversation ordering
  db_write.py          # _write_conversation, _open_sync_connection
  worker_pool.py       # ProcessPoolExecutor dispatch
  result_pipeline.py   # _drain_ingest_result, _consume_ingest_results
  batch_async.py       # async orchestration
  state_updates.py     # raw state persistence
  session_refresh.py   # refresh_session_insights_bulk

Acceptance criteria

  • FTS trigger management extracted to storage/fts/ as a context manager
  • Worker dispatch separated from DB write orchestration
  • Each split module under 300 lines
  • No regression in existing ingest tests
  • Sync/async DB access unified on one approach per module

Ref: deep audit R1/R3, #772. Ref #730 (fragile areas).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions