Skip to content

fix(sources): corroborate catch-up cursor skips against index presence - #3223

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/emx2-catchup-index-corroboration
Jul 20, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/emx2-catchup-index-corroboration

Conversation

@Sinity

@Sinity Sinity commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Summary

Watcher catch-up's hot-skip fast path trusted ops.db ingest cursors as
proof of full materialization without ever checking whether index.db
actually holds the corresponding session. This PR adds a corroboration
check that demotes cursor-trust skips to "needed" when the index tier
cannot back up the claim.

Problem

polylogue-emx2 (Finding 8 of perf-investigation-2026-07-18): after an
index reset/rebuild, source.db retained 14,879 ingest cursors
recording "acquired and parsed", but index.db started empty.
_needs_work_from_state's hot-skip fast path (byte-size +
content-fingerprint match) never checked whether the index actually
held a materialized session for the cursor's raw — it skipped every
one of those files outright, leaving 100% of the restore drain to the
1-per-30s background conveyor.

PRs #3129 and #3193 (merged, both linked to this bead) fixed a related
but distinct bug: batch.py was misclassifying a raw with a
pending/decided membership arbitration as a full-ingest failure. That
repaired the accounting after a file was resubmitted for ingest, but
never addressed the original finding — the cursor-trust fast path in
the watcher still never consulted the index at all. This PR closes
that remaining gap.

Solution

polylogue/sources/live/watcher.py:

  • _archived_cursor_reconciliation_scope now computes, once per
    catch-up planning pass (reusing its already-shared source.db/index.db
    connections), whether the index tier is globally uncorroborated:
    _index_lacks_all_corroboration returns True when source.db
    holds at least one successfully parsed raw row but index.db's
    sessions table is completely empty — the exact post-reset
    signature from Finding 8.
  • _needs_work_from_state (the prior single-purpose decision method,
    renamed _needs_work_from_state_uncorroborated) now wraps that
    logic: when it would skip a file and the index is flagged
    uncorroborated, a cheap per-candidate existence check
    (_cursor_skip_corroborated_by_index, reusing the existing
    _archived_cursor_row raw→session join) decides whether to honor the
    skip or demote it to "needed".
  • The gate defaults to trusted (no behavior change) whenever the index
    has any session at all, so the common healthy case adds zero extra
    queries.
  • Demoted files re-enter the normal batch ingest path, which is already
    content-hash idempotent, so no bytes are re-acquired for unchanged
    files.

Verification

  • devtools test tests/unit/sources/test_live_catchup_planning.py:
    19 passed (16 pre-existing + 3 new).
  • devtools test tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_watcher_catchup_order.py tests/unit/sources/test_live_watcher_locking.py: 101 passed.
  • mypy --strict polylogue/sources/live/watcher.py tests/unit/sources/test_live_catchup_planning.py: no issues found.
  • devtools verify --quick: exit 0.
  • Anti-vacuity: reverted only the production fix (kept the new tests)
    and reran the suite — test_catch_up_demotes_hot_skip_cursor_when_index_holds_no_sessions
    failed with the exact live symptom (plan.needed == () instead of
    the healthy-cursor file), and
    test_catch_up_index_lacks_all_corroboration_detects_empty_index_with_parsed_raw
    failed with AttributeError for the missing method. Restoring the
    fix turned both green.
  • Not run: full devtools verify --all / integration suite (out of
    scope for a focused fix; the touched-file testmon selection above is
    the relevant net).

Ref polylogue-emx2

Problem

polylogue-emx2 (Finding 8 of perf-investigation-2026-07-18): watcher
catch-up trusted ops.db ingest_cursor rows as proof of full
materialization. After an index reset/rebuild, source.db retained
14,879 cursors recording "acquired and parsed", but index.db started
empty. `_needs_work_from_state`'s hot-skip fast path (byte-size +
content-fingerprint match) never checked whether the index actually
held a materialized session for the cursor's raw -- it skipped the
file outright, leaving 100% of the restore drain to the 1-per-30s
background conveyor.

PRs #3129 and #3193 (merged) fixed a related but distinct bug: batch.py
was misclassifying a raw with a pending/decided membership arbitration
as a full-ingest failure. That repaired the accounting *after* a file
was resubmitted for ingest, but never addressed the original finding --
the cursor-trust fast path in the watcher still never consults the
index at all.

Solution

`polylogue/sources/live/watcher.py`:
- `_archived_cursor_reconciliation_scope` now computes, once per
  catch-up planning pass (reusing its already-shared source.db/index.db
  connections), whether the index tier is globally uncorroborated:
  `_index_lacks_all_corroboration` returns True when source.db holds at
  least one successfully parsed raw row but index.db's `sessions` table
  is completely empty -- the exact post-reset signature from Finding 8.
- `_needs_work_from_state` (renamed inner decision logic to
  `_needs_work_from_state_uncorroborated`) now wraps that logic: when it
  would skip a file and the index is flagged uncorroborated, a cheap
  per-candidate existence check (`_cursor_skip_corroborated_by_index`,
  reusing the existing `_archived_cursor_row` raw->session join) decides
  whether to honor the skip or demote it to "needed".
- The gate defaults to trusted (no behavior change) whenever the index
  has any session at all, so the common case adds zero queries.
- Demoted files re-enter the normal batch ingest path, which is already
  content-hash idempotent, so no bytes are re-acquired for unchanged
  files (AC: "no re-acquisition of unchanged bytes").

Verification

- `devtools test tests/unit/sources/test_live_catchup_planning.py`:
  19 passed (16 pre-existing + 3 new).
- `devtools test tests/unit/sources/test_live_watcher.py
  tests/unit/sources/test_live_watcher_catchup_order.py
  tests/unit/sources/test_live_watcher_locking.py`: 101 passed.
- `mypy --strict polylogue/sources/live/watcher.py
  tests/unit/sources/test_live_catchup_planning.py`: no issues.
- `devtools verify --quick`: exit 0 (ruff format/check, mypy, render
  all, topology/layering/manifests/doc-commands/etc. all ok).
- Anti-vacuity: reverted only the watcher.py fix (kept the new tests)
  and reran `test_catch_up_demotes_hot_skip_cursor_when_index_holds_no_sessions`
  -- it failed with the exact live symptom (`plan.needed == ()` instead
  of the healthy-cursor file), and
  `test_catch_up_index_lacks_all_corroboration_detects_empty_index_with_parsed_raw`
  failed with `AttributeError` for the missing method. Restoring the
  fix turned both green.

Ref polylogue-emx2
@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: 24 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: d4092814-c12f-4697-9e89-6af30c51af93

📥 Commits

Reviewing files that changed from the base of the PR and between 3353376 and 92617b3.

📒 Files selected for processing (2)
  • polylogue/sources/live/watcher.py
  • tests/unit/sources/test_live_catchup_planning.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/emx2-catchup-index-corroboration

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:

  • Fixes the actual Finding-8 gap: the cursor-trust fast path in _needs_work_from_state never consulted index.db; fix(sources): stop miscounting deferred membership as a full-ingest failure #3129/fix(sources): fail closed on decided ambiguous membership, not just NULL #3193 fixed a downstream misclassification, not this. The wrapper design (delegate byte/fingerprint decision, then corroborate skips only) leaves every 'needed' decision untouched.
  • Zero-cost healthy path: the global gate _index_lacks_all_corroboration is two LIMIT-1 existence probes once per catch-up scan, false whenever the index holds any session — per-file corroboration only runs in the post-reset signature state.
  • Fail-safe direction is right: transient sqlite errors during corroboration return True (no spurious re-ingest); paths with no parsed raw are treated as corroborated (unrelated cursor kinds unaffected); demotion re-enters the normal content-hash-idempotent ingest path, so no re-acquisition of unchanged bytes and no cursor deletion.
  • Known limitation, acceptable: gate is global (index fully empty), not per-source — matches the live incident (14,879 cursors vs empty index); a partial per-source gap is a natural follow-up, honestly flagged.
  • Anti-vacuity proven: production fix reverted with tests kept → exact live symptom reproduced (plan.needed == ()).

Verification per PR body: 19+101 focused tests green, mypy --strict clean, quick-gate green. Merging.

@Sinity
Sinity merged commit 56ef439 into master Jul 20, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the feature/fix/emx2-catchup-index-corroboration branch July 20, 2026 19:42

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 92617b3555

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

Comment thread polylogue/sources/live/watcher.py Resolved
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 70.F082 / P1: fixed-already at the checked revision: Each cursor-based skip now checks the materialized coverage of that exact path at polylogue/sources/live/watcher.py:675. A session restored for another path does not satisfy this check, so a partially rebuilt index cannot disable corroboration for the remaining files.

Only the rows listed above are dispositioned. Held findings remain open.

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