Skip to content

fix(daemon): back off failed live ingest paths - #1467

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/live-failed-backoff
May 24, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/live-failed-backoff

Conversation

@Sinity

@Sinity Sinity commented May 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

Failed live-ingest paths now retry through live_cursor backoff instead of being immediately requeued from batch metrics. The daemon can still converge every source file, but a failing catch-up group no longer turns into a half-second disk hot loop.

Problem

After the #1466 deploy, polylogued reached real catch-up and processed the large Codex chunks, then repeatedly logged batching 305 changed file(s) and requeued 305 failed file(s) for live retry. /proc/$pid/io reached ~23 GB of reads and IO PSI full avg10 hit ~24%, while live_cursor had zero failed rows. That means retry state was bypassing the durable cursor/backoff mechanism.

The sampled failed paths were valid-ish Antigravity/Hermes inputs and parsed successfully in a fresh temp archive, so the correct fix is not scope reduction or quarantine.

Ref #1447

Solution

  • Add CursorStore.list_failed_records() so the watcher can inspect failed cursor rows with their retry timestamps.
  • Replace direct metrics failed_paths requeueing with cursor-owned retry scheduling.
  • Schedule due failed paths back into pending work, and create one delayed wake-up for the next next_retry_at so convergence continues without hot polling.
  • Cancel the failed-retry wake-up with pending watcher tasks on stop/cancel.
  • Update catch-up/live watcher tests to assert backed-off failures are not immediately requeued and only due failures re-enter pending work.

Verification

  • pytest -q tests/unit/sources/test_live_catchup_planning.py tests/unit/sources/test_live_watcher.py -> 65 passed
  • ruff check polylogue/sources/live/watcher.py polylogue/sources/live/cursor.py tests/unit/sources/test_live_catchup_planning.py tests/unit/sources/test_live_watcher.py -> pass
  • mypy polylogue/sources/live/watcher.py polylogue/sources/live/cursor.py tests/unit/sources/test_live_catchup_planning.py tests/unit/sources/test_live_watcher.py -> pass
  • devtools verify --quick -> exit_code 0, total_duration_s 37.93
  • pre-push devtools verify --quick -> exit_code 0, total_duration_s 35.40

Summary by CodeRabbit

  • New Features
    • Added automatic retry scheduling for failed files with deadline-aware retry timing. Failed files are now queued only when their retry deadline is reached, preventing immediate requeue bursts.

Review Change Stack

Problem: the live watcher requeued batch failed_paths directly, so a failing catch-up group could loop every debounce interval without creating live_cursor failure rows or honoring backoff. On the live archive this produced repeated 305-file batches and severe IO PSI while the daemon made no progress.\n\nWhat changed: failed source retries are now cursor-owned. The watcher scans failed live_cursor records, schedules due failures back into pending work, and sleeps until the next retry timestamp for backed-off failures. Catch-up and live flush paths no longer translate metrics failed_paths into immediate pending work.\n\nVerification:\n- pytest -q tests/unit/sources/test_live_catchup_planning.py tests/unit/sources/test_live_watcher.py -> 65 passed\n- ruff check polylogue/sources/live/watcher.py polylogue/sources/live/cursor.py tests/unit/sources/test_live_catchup_planning.py tests/unit/sources/test_live_watcher.py -> pass\n- mypy polylogue/sources/live/watcher.py polylogue/sources/live/cursor.py tests/unit/sources/test_live_catchup_planning.py tests/unit/sources/test_live_watcher.py -> pass\n- devtools verify --quick -> exit_code 0\n\nRef #1447
@coderabbitai

coderabbitai Bot commented May 24, 2026 •

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

LiveWatcher now implements a backoff-based retry scheduler for previously failed files. It queries failed cursor records via CursorStore.list_failed_records(), computes which failures are due for retry based on next_retry_at timestamps, and schedules asyncio tasks to wake and rescan at the next eligible deadline. Retry integration is triggered after catch-up completion, chunk ingestion, and batch flush, replacing immediate requeue logic. Tests verify deferred retry behavior and timestamp-based eligibility.

Changes

Live File Retry Scheduler

Layer / File(s) Summary
Failed records data access
polylogue/sources/live/cursor.py
New CursorStore.list_failed_records() queries non-excluded failed cursor rows, ordered by next_retry_at with NULLs first, returning CursorRecord objects.
Retry scheduler state, lifecycle, and logic
polylogue/sources/live/watcher.py
LiveWatcher.__init__ initializes failed_retry_wakeup_task and failed_retry_deadline state. cancel_pending() cancels retry tasks. Core helpers _schedule_failed_retry_scan(), _schedule_failed_retry_wakeup(), _wake_failed_retries(), and _cancel_failed_retry_task() compute due failures, manage asyncio wakeup timing, and update pending ingestion paths. Refactored _retry_due() and new _parse_retry_at() parse ISO timestamps, normalize naive datetimes to UTC, and determine retry eligibility.
Watcher flow integration points
polylogue/sources/live/watcher.py
_schedule_failed_retry_scan() is called after initial catch-up completion, after each catch-up chunk ingestion, and after flushing debounced live-file batches, replacing earlier immediate requeue behavior.
Test updates for retry behavior
tests/unit/sources/test_live_catchup_planning.py
Imports sqlite3, timedelta, and FrozenClock for direct SQLite cursor manipulation and deterministic time control. test_catch_up_does_not_immediately_requeue_failed_paths (renamed from test_catch_up_requeues_failed_paths_for_live_retry) verifies failed paths are deferred. New test_flush_pending_does_not_hot_requeue_backed_off_failure asserts _flush_pending() increments failure_count and sets a non-null next_retry_at. Updated test_failed_retry_scan_requeues_only_due_failures directly sets past and future next_retry_at timestamps in the live_cursor table and verifies only due failures are requeued.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Sinity/polylogue#762: Introduced cursor failure/backoff fields (failure_count, next_retry_at) and methods (mark_failed, reset_failures) that this PR directly uses for retry scheduling.
  • Sinity/polylogue#541: Original implementation of polylogue/sources/live/cursor.py and polylogue/sources/live/watcher.py that this PR extends with CursorStore.list_failed_records() and scheduled retry logic.
  • Sinity/polylogue#1460: Concurrent modification of polylogue/sources/live/watcher.py's failure-retry flow, moving from LiveBatchMetrics.failed_paths immediate requeue to CursorStore failed-record scheduled scanning.

🐰 A watcher learns the art of patience fine,
No longer rushing failures back in line,
It queries failed records by the clock,
Wakes only when their retry deadlines unlock,
Now backoff timers guide the way—
Retries happen on a wiser day! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(daemon): back off failed live ingest paths' is concise, specific, and directly summarizes the main change: implementing backoff logic for failed live ingest paths.
Description check ✅ Passed The PR description covers all required template sections: Summary, Problem, Solution, Verification, and omits Changelog (appropriate for internal refactoring), with clear technical details and exact test commands provided.
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.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/live-failed-backoff

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.

@Sinity
Sinity merged commit 154232c into master May 24, 2026
5 of 6 checks passed
@Sinity
Sinity deleted the feature/fix/live-failed-backoff branch May 24, 2026 03:05

@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: e0d482b41f

ℹ️ 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 added a commit that referenced this pull request May 24, 2026
Summary

Defers expensive session-insight rebuilds for very large source files while they are still actively appending, without reducing daemon convergence scope. Archive writes and targeted FTS repair still run immediately; insight convergence becomes durable debt until the source is quiet.

Problem

After #1467 was deployed, the failed-file hot requeue loop stopped, but live monitoring still showed severe physical reads on tiny appends to huge active Codex sessions. source_payload_read_bytes was only a few KB per attempt while /proc PID io showed roughly 2.36 GB of reads over 10s, pointing at derived session insight rebuilds rehydrating whole conversations on every append.

Solution

- Add a 64 MiB / 60s quiet-window guard to the daemon insights stage.
- Return convergence debt, not success, when a huge source is still hot so the daemon must still converge once the file quiets.
- Mark this expected deferral with a fixed 60s retry cadence instead of exponential failure backoff.
- Shorten the daemon's convergence-debt retry loop from 10 minutes to 60 seconds.
- Add focused coverage for hot large deferral, quiet large rebuild, small active rebuild, and fixed retry scheduling.

Verification

- pytest -q tests/unit/daemon/test_convergence_stages.py tests/unit/daemon/test_daemon_convergence.py tests/unit/daemon/test_daemon_cli.py tests/unit/sources/test_live_catchup_planning.py -> 45 passed
- pytest -q tests/unit/sources/test_live_watcher.py -> 60 passed
- devtools verify --quick -> exit_code 0, total_duration_s 34.58
- pre-push devtools verify --quick -> exit_code 0, total_duration_s 34.61

Ref #1447
@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.F079 / P1: fixed-already at the checked revision: The replacement file-intake queue retains attempted but unacknowledged paths even without a durable failure cursor. polylogue/operations/intake_adapters.py:339-355 assigns those paths a local retry deadline, so a deferred append no longer disappears merely because failure_count was not incremented.

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