Skip to content

fix(daemon): defer incomplete live appends - #1460

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

Sinity merged 1 commit into
masterfrom
feature/fix/live-append-deferral

Conversation

@Sinity

@Sinity Sinity commented May 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

Prevents hot JSONL session files from falling back to full ingest when the watcher observes a partial trailing line, and requeues failed live/catch-up paths for the normal retry loop.

Problem

Live deployment of #1459 proved #1447 is still open: catch-up reached watching, but a Codex file then triggered slow_write ... changed_messages=10309 ... elapsed_s=81.76, drove IO PSI full avg10 to ~55%, and left the daemon in D-state. The append planner was treating a grown tail with no complete newline as "not appendable", which sent an actively-written JSONL file into full ingest instead of waiting for the writer to finish the line.

Solution

  • Add an explicit deferred-append sentinel for incomplete JSONL tails.
  • Keep deferred paths out of full ingest and report them as retryable failed paths.
  • Requeue failed catch-up and live-drain paths into the existing pending watcher loop.
  • Return LiveBatchMetrics from LiveWatcher._ingest_files so callers can act on retryable failures.
  • Add regression coverage for incomplete append deferral and failed catch-up requeue.

Ref #1447

Verification

  • pytest tests/unit/sources/test_live_catchup_planning.py tests/unit/sources/test_live_batch_support.py tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_watcher_locking.py tests/unit/sources/test_live_hot_session_convergence.py -q → 83 passed
  • ruff check polylogue/sources/live/batch.py polylogue/sources/live/batch_support.py polylogue/sources/live/watcher.py tests/unit/sources/test_live_catchup_planning.py tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_batch_support.py tests/unit/sources/test_live_hot_session_convergence.py → passed
  • mypy polylogue/sources/live/batch.py polylogue/sources/live/batch_support.py polylogue/sources/live/watcher.py tests/unit/sources/test_live_catchup_planning.py tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_batch_support.py tests/unit/sources/test_live_hot_session_convergence.py → passed
  • devtools verify-file-budgets → clean
  • devtools verify --quick → exit_code 0, total_duration_s 37.8

Summary by CodeRabbit

  • Bug Fixes

    • File ingestion now automatically retries failed paths during live processing, improving reliability.
  • Refactor

    • Improved batch processing to better handle incomplete file appends and optimized scheduling logic for pending files.
  • Tests

    • Added comprehensive test coverage for deferred append behavior and failed file retry mechanisms.

Review Change Stack

Problem: deployed live catch-up still allowed a hot Codex JSONL file to fall back to full ingest when the watcher observed a partial trailing line. That replay rewrote thousands of rows, drove severe IO PSI, and stranded transient catch-up failures until restart.

What changed: append planning now distinguishes incomplete append tails from true non-appendable files, reports them as retryable failed paths, and keeps them out of full ingest. Catch-up and live pending drains now requeue failed paths so transient locks or incomplete writer flushes are retried by the normal watcher loop.

Verification: ruff check polylogue/sources/live/batch.py polylogue/sources/live/watcher.py tests/unit/sources/test_live_catchup_planning.py tests/unit/sources/test_live_watcher.py; mypy polylogue/sources/live/batch.py polylogue/sources/live/watcher.py tests/unit/sources/test_live_catchup_planning.py tests/unit/sources/test_live_watcher.py; pytest tests/unit/sources/test_live_catchup_planning.py tests/unit/sources/test_live_watcher.py::test_append_plan_defers_when_tail_has_no_complete_line tests/unit/sources/test_live_watcher.py::test_incomplete_append_is_requeued_not_full_ingested tests/unit/sources/test_live_watcher.py::test_append_plan_reads_only_completed_tail tests/unit/sources/test_live_watcher_locking.py -q.

Ref #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

Implements a deferred-append and retry mechanism to handle incomplete file appends during batch ingestion. Files with incomplete content (no trailing newline) are marked for later retry instead of being treated as full-ingest candidates, enabling automatic re-processing when more data arrives.

Changes

Deferred append and retry mechanism for incomplete file ingestion

Layer / File(s) Summary
Deferred append sentinel definition
polylogue/sources/live/batch_support.py
Private sentinel class _DeferredAppend and singleton instance _DEFER_APPEND represent incomplete append state.
Append plan deferral detection
polylogue/sources/live/batch.py
_append_plan returns sentinel when file tail lacks usable content, replacing prior None behavior; return type updated.
Batch ingest deferred path tracking
polylogue/sources/live/batch.py
Deferred paths accumulated separately during append planning, then merged into retry/failed accounting during finalization for unified metrics.
Watcher metrics capture and scheduling
polylogue/sources/live/watcher.py
_ingest_files returns LiveBatchMetrics instead of None; new _requeue_failed_paths helper and centralized _ensure_pending_scheduled() for debounce scheduling.
Watcher retry integration in catch-up and live paths
polylogue/sources/live/watcher.py
Both catch-up chunking and live flushing immediately requeue failed paths from metrics; scheduler ensures activation after catch-up.
Unit tests for append defer and requeue behavior
tests/unit/sources/test_live_batch_support.py
New tests verify _append_plan returns sentinel when tail incomplete, and incomplete appends are re-queued not fully ingested; existing assertions tightened.
Catch-up requeue test coverage
tests/unit/sources/test_live_catchup_planning.py
Bounded-chunk test stubs _ingest_files and verifies batching; new test verifies failed paths are re-queued into pending_paths for retry.
Test type annotation adjustments
tests/unit/sources/test_live_*.py
Type-ignore directives updated to allow assignment-level suppression for _ingest_files mock and plan object casting for field assertions.

Sequence Diagram(s)

sequenceDiagram
  participant Watcher
  participant _ingest_files
  participant BatchProcessor
  participant _requeue_failed_paths
  participant pending_set
  Watcher->>_ingest_files: call with file batch
  _ingest_files->>BatchProcessor: ingest_files()
  BatchProcessor-->>_ingest_files: metrics with failed_paths
  _ingest_files-->>Watcher: return metrics
  Watcher->>_requeue_failed_paths: pass metrics
  _requeue_failed_paths->>pending_set: re-add failed_paths
  _requeue_failed_paths-->>Watcher: done
  Watcher->>Watcher: _ensure_pending_scheduled()
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Sinity/polylogue#1429: Both PRs modify the live append-ingest flow in polylogue/sources/live/batch.py (append planning/grouping and ingest outcome accounting), so the deferred-append/retry changes in the main PR are code-level related to the retrieved PR's restructuring of append plan batching and memory-bounded ingest.

Poem

A rabbit hops through file append flows,
When tails run short, deferral grows—
Retry paths spring back alive,
Incomplete content waits to thrive,
Batch metrics guide where retries go! 🐰📝

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the primary change: deferring incomplete live appends instead of falling back to full ingest.
Description check ✅ Passed The description covers all required template sections: Summary (1-3 sentences), Problem (necessity explained), Solution (modules and changes detailed), Verification (exact commands and test results), and no Risks section needed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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-append-deferral

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 55f5698 into master May 24, 2026
5 of 6 checks passed
@Sinity
Sinity deleted the feature/fix/live-append-deferral branch May 24, 2026 00:43
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