openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

perf(github): bound-concurrent batch summarise, keep ingest serial

Open mysma-9403 opened this issue 5 months ago • 1 comments

Summary

  • GitHub source-sync now summarises batches with bounded concurrency, while ingest stays serial (tree write order preserved).
  • A pure summarise_concurrency helper gates the fan-out by workload routing: cloud overlaps calls, local stays serial.
  • Cost accounting and tree ingest order are unchanged.

Problem

sync_source summarised and ingested one batch at a time:

for batch in batches {
    let output = summarise(batch).await;   // independent LLM round-trip
    ingest_summary(output).await;           // ordered write into shared source tree
}

The K summarise calls are independent of each other but ran strictly back-to-back, so a repo that batches into K groups paid K serial LLM round-trips before sync could finish. Only the ingest step actually needs ordering (it writes into the shared source tree).

Solution

  • Phase 1 — concurrent summarise. Build a summarise future per batch, materialize into a Vec (so the higher-ranked closure lifetime stays tied to the frame — avoids "implementation of FnOnce is not general enough"), and drive with futures::stream::iter(..).buffered(concurrency). buffered is ordered, so outputs[i] maps back to batches[i].
  • Phase 2 — serial fold + ingest. Zip batches with their outputs and, in order, fold cost (RealCostAccumulator::add_batch) and call ingest_summary. Identical to before.
  • Concurrency gate. summarise_concurrency(uses_local) returns 1 for a local model (single inference engine — concurrent calls would queue or oversubscribe VRAM) and GITHUB_SUMMARISE_CONCURRENCY = 4 for cloud. Driven by config.workload_uses_local("memory"). Pure + unit-tested.
  • The per-batch summarise-failure fallback (fallback_summary) is preserved inside each future.

Submission Checklist

  • [x] Tests added or updated (happy path + at least one failure / edge case) — summarise_concurrency covered for both local (serial) and cloud (fan-out) routing; existing batch/read-concurrency tests still pass.
  • [x] Diff coverage >= 80% — the substantive new decision (concurrency gating) is a pure unit-tested helper; the rest is the LLM/network-bound two-phase wrapper.
  • [x] N/A: Coverage matrix — behaviour-preserving perf change, no feature rows added/removed/renamed.
  • [x] N/A: feature IDs — no matrix feature affected.
  • [x] No new external network dependencies introduced (same summarise + ingest calls, just overlapped).
  • [x] N/A: manual smoke checklist — internal memory-sync path, no release-cut surface.
  • [x] N/A: no linked issue — proactive performance improvement.

Impact

  • Runtime: Rust core GitHub memory-sync. Overlaps up to 4 batch summarise calls for cloud providers; local models keep the old serial behaviour. Ingest order, cost accounting, and dedup unchanged.
  • Memory: holds all batch outputs before the ingest phase (bounded by batch count, same data already produced per batch).
  • No migration, security, or compatibility implications.

Related

  • Closes:
  • Follow-up PR(s)/TODOs:

AI Authored PR Metadata

Linear Issue

  • Key: N/A
  • URL: N/A

Commit & Branch

  • Branch: perf/github-bounded-summarise

Validation Run

  • [x] N/A: pnpm --filter openhuman-app format:check — no app/ changes
  • [x] N/A: pnpm typecheck — no TypeScript changes
  • [x] Focused tests: cargo test --lib memory_sync::sources::github (10 passed)
  • [x] Rust fmt/check: cargo fmt -p openhuman + cargo test --lib (compiled)
  • [x] N/A: Tauri fmt/check — no shell changes

Validation Blocked

  • command: N/A
  • error: N/A
  • impact: N/A

Behavior Changes

  • Intended behavior change: none (perf-only; cost + ingest order preserved)
  • User-visible effect: faster GitHub source sync for multi-batch repos on cloud memory routing

Parity Contract

  • Legacy behavior preserved: cost folded in batch order, ingest serial in batch order, summarise-failure fallback per batch, local model stays one-batch-at-a-time.
  • Guard/fallback/dispatch parity checks: summarise_concurrency(true) == 1 keeps the exact old serial path for local inference; buffered (not buffer_unordered) preserves ordering for cost and tree writes.

Duplicate / Superseded PR Handling

  • Duplicate PR(s): N/A
  • Canonical PR: N/A
  • Resolution: N/A

Summary by CodeRabbit

Release Notes

  • Refactor

    • Improved GitHub data synchronization performance with optimized concurrency management.
    • Enhanced separation of summarization and ingestion phases for better efficiency.
  • Tests

    • Added unit tests to verify concurrency behavior and data ingestion integrity.

mysma-9403 avatar Jun 06 '26 14:06 mysma-9403

Review Change Stack

📝 Walkthrough

Walkthrough

The GitHub sync pipeline is refactored to decouple concurrent summarization from ordered ingestion. After batching, per-batch summarizations execute with bounded concurrency (serial for local models, limited parallelism for cloud), using fallback_summary on failures. Results are collected, then cost accounting and ingestion proceed in batch order, preserving previous semantics while overlapping LLM calls where permitted.

Changes

GitHub sync concurrent summarization

Layer / File(s) Summary
Concurrency infrastructure and validation
src/openhuman/memory_sync/sources/github.rs
New GITHUB_SUMMARISE_CONCURRENCY constant and summarise_concurrency(uses_local: bool) helper return 1 for local workloads and GITHUB_SUMMARISE_CONCURRENCY for cloud. Unit tests verify serial execution for local models and parallel routing for cloud.
Concurrent summarization and ordered ingestion
src/openhuman/memory_sync/sources/github.rs
Import SummaryOutput. Replace single per-batch summarise loop with two-step pipeline: (1) collect summarization futures and run with buffered(concurrency) using fallback on errors; (2) zip outputs with batches for cost accounting and ordered ingest_summary in batch sequence.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 A sync that once rushed through summaries, now orchestrates in parallel,
Keeping local work serial, while cloud calls fan out like a spark,
Ingestion marches in order, cost accounting trails behind,
Two phases dancing together: concur, then collect, then fold. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'perf(github): bound-concurrent batch summarise, keep ingest serial' directly and accurately reflects the main changes in the PR, which introduces bounded concurrency for batch summarization while maintaining serial ingestion.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

coderabbitai[bot] avatar Jun 06 '26 14:06 coderabbitai[bot]