Repository navigation
fix(daemon): remove broad startup maintenance scans - #1464
Conversation
Problem: live deployment of #1463 still pushed IO PSI above 30% during catch-up. The daemon launched PRAGMA optimize immediately and scheduled an exact FTS invariant repair loop 30 seconds after start, causing broad reads on a 46G archive while catch-up was already active. What changed: defer PRAGMA optimize until the daily maintenance interval has elapsed, and remove the automatic exact FTS invariant repair loop from the always-on daemon. FTS freshness for live work remains enforced by startup structural readiness plus targeted changed-conversation convergence repair; full exact invariant audits belong to explicit maintenance, not runtime catch-up. Verification: pytest tests/unit/daemon/test_daemon_cli.py tests/unit/daemon/test_convergence_stages.py -q; ruff check polylogue/daemon/cli.py tests/unit/daemon/test_daemon_cli.py; mypy polylogue/daemon/cli.py tests/unit/daemon/test_daemon_cli.py; devtools verify --quick. Ref #1447
📝 WalkthroughWalkthroughDaemon maintenance task scheduling is refactored to separate startup optimization from periodic background work: the periodic DB optimization task now sleeps 24 hours before each check, status snapshot monitoring is integrated into maintenance tasks, and FTS repair background task is removed. ChangesDaemon maintenance task scheduling and optimization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 59f2acf928
ℹ️ 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".
## Summary Blocks offline maintenance repair/cleanup paths while a live `polylogued` pidfile points at an actual daemon process, and surfaces that refusal through both `doctor --repair` and `polylogue maintenance run` envelopes. Dry-run previews remain allowed. ## Problem During the #1447 live deployment pass after #1464, a foreground `polylogue doctor --repair --target session_insights` process appeared while `polylogued` was catching up a large Codex session. The repair process held the SQLite lock and daemon insight convergence failed with `OperationalError: database is locked`, leaving the latest live ingest attempt stuck in `running/convergence` until shutdown. That is not valid daemon convergence behavior; offline repair must not race the live daemon-owned writer. ## Solution - Add `polylogue.maintenance.offline_guard` to verify a `daemon.pid` belongs to a live `polylogued` process. - Make `storage.repair.run_selected_maintenance` return target-level failures instead of starting offline repair/cleanup when the daemon is live. - Make maintenance replay return a typed failed operation with `OfflineMaintenanceBlocked` failure samples under the same condition. - Refresh topology generated surfaces for the new module. This preserves daemon scope: the daemon still owns live convergence and should drain valid inputs; out-of-band offline repair now requires stopping the daemon first. ## Verification - `pytest tests/unit/storage/test_repair.py tests/unit/maintenance/test_idempotency.py tests/unit/sources/test_live_batch_convergence.py tests/unit/daemon/test_ingest_worker_handoff.py -q` → `22 passed in 2.91s` - `ruff check polylogue/maintenance/offline_guard.py polylogue/storage/repair.py polylogue/maintenance/replay.py tests/unit/storage/test_repair.py tests/unit/maintenance/test_idempotency.py` → `All checks passed!` - `mypy polylogue/maintenance/offline_guard.py polylogue/storage/repair.py polylogue/maintenance/replay.py tests/unit/storage/test_repair.py tests/unit/maintenance/test_idempotency.py` → `Success: no issues found in 5 source files` - `devtools verify-file-budgets` → `file-size budgets: clean` - `devtools verify-topology` → `realized=829 declared=829 blocking=False` - `devtools render-all --check` → passed - `devtools verify --quick` → `exit_code: 0`, `total_duration_s: 36.4` - pre-push `devtools verify --quick` → `exit_code: 0`, `total_duration_s: 34.44` Ref #1447
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Removes broad automatic maintenance scans from the daemon startup/catch-up path.
PRAGMA optimizenow waits for the daily maintenance interval before first execution, and the daemon no longer starts an exact FTS invariant repair loop 30 seconds after launch.Problem
Live validation of deployed Polylogue
cc0bf5bastill showed unsafe host IO during catch-up:polylogued.servicestarted from/nix/store/10lqh6vbj0b5grkww4iqkvhlipjx2wj7-python3.13-polylogue-0.1.0/bin/polylogued.changed_messages=208and368, both under 5s), so source parse/write was no longer the primary issue.full avg10=31.72%, with processread_bytes=12,176,195,584and only ~341 MB RSS.PRAGMA optimizeimmediately and also schedules exact FTS invariant checking after 30 seconds. On this archive the DB file is 46G, so these broad reads run concurrently with catch-up and dominate host IO.Solution
The always-on daemon now avoids broad maintenance reads during startup/catch-up:
PRAGMA optimizesleeps for its 24h maintenance interval before the first pass.Full exact FTS invariant audits remain explicit maintenance/lab work rather than a background daemon loop. This does not reduce daemon convergence scope: valid changed source files still ingest and converge; the change only removes unrelated broad maintenance scans from the runtime path.
Verification
pytest tests/unit/daemon/test_daemon_cli.py tests/unit/daemon/test_convergence_stages.py -q->29 passed in 0.32sruff check polylogue/daemon/cli.py polylogue/daemon/convergence_stages.py tests/unit/daemon/test_daemon_cli.py tests/unit/daemon/test_convergence_stages.py->All checks passed!mypy polylogue/daemon/cli.py polylogue/daemon/convergence_stages.py tests/unit/daemon/test_daemon_cli.py tests/unit/daemon/test_convergence_stages.py->Success: no issues found in 4 source filesdevtools verify --quick-> passed in36.05sbefore pushdevtools verify --quick-> passed in33.85sRef #1447