Skip to content

fix(daemon): block offline maintenance during convergence - #1465

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/offline-maintenance-daemon-guard
May 24, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/offline-maintenance-daemon-guard

Conversation

@Sinity

@Sinity Sinity commented May 24, 2026

Copy link
Copy Markdown
Owner

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

Problem: live deployment showed a foreground doctor repair racing the daemon's catch-up convergence and forcing session insight rebuilds into SQLite lock failures. That made the daemon appear stuck on a valid large Codex session even after the broad startup maintenance scans were removed.\n\nWhat changed: add a shared live-daemon guard for offline maintenance, return target-level repair failures from doctor/repair when polylogued is running, and surface the same blocker through maintenance replay envelopes. Dry-run previews remain allowed. The topology projection is refreshed for the new guard module.\n\nVerification:\n- 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\n- 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\n- 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\n- devtools verify --quick\n\nRef #1447
@coderabbitai

coderabbitai Bot commented May 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, we couldn't start this review because you've used your available PR reviews for now.

Your plan currently allows 1 review/hour. Refill in 25 minutes and 5 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: a68e38ba-b58d-4a2e-a9d4-cac946328cc9

📥 Commits

Reviewing files that changed from the base of the PR and between 2dc505c and c28e270.

📒 Files selected for processing (7)
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/maintenance/offline_guard.py
  • polylogue/maintenance/replay.py
  • polylogue/storage/repair.py
  • tests/unit/maintenance/test_idempotency.py
  • tests/unit/storage/test_repair.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/offline-maintenance-daemon-guard

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 7da2749 into master May 24, 2026
7 checks passed
@Sinity
Sinity deleted the feature/fix/offline-maintenance-daemon-guard branch May 24, 2026 02:26

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

ℹ️ 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/maintenance/offline_guard.py Resolved
Sinity added a commit that referenced this pull request May 24, 2026
## Summary

Stops schema-blocked daemon startup from launching any DB-opening
background work. The daemon can still expose degraded browser/API
surfaces, but a critical schema preflight now blocks the watcher,
periodic archive tasks, and the post-ingest converger.

## Problem

After deploying #1465, the live service correctly refused live ingest
because the archive metadata reported schema v12 against runtime v8, but
it still started the convergence engine and periodic loops. On the real
archive, `read_bytes` rose by about 1.17 GB in 5 seconds even though the
watcher was blocked. That defeats the schema preflight's purpose and can
keep the host under IO pressure.

## Solution

- Keep `run_daemon_services` from creating WAL, heartbeat,
convergence-debt, health, DB optimize, or status-snapshot tasks when
`watcher_blocked` is true.
- Keep the post-ingest `DaemonConverger` unconstructed under the same
schema-blocked state.
- Add a regression test proving the schema-blocked browser/API path
closes cleanly without starting DB background work.

Ref #1447

## Verification

- `pytest -q tests/unit/daemon/test_daemon_cli.py -q` -> `18 passed`
- `ruff check polylogue/daemon/cli.py
tests/unit/daemon/test_daemon_cli.py` -> `All checks passed!`
- `mypy polylogue/daemon/cli.py tests/unit/daemon/test_daemon_cli.py` ->
`Success: no issues found in 2 source files`
- `devtools verify --quick` -> `exit_code: 0`, `total_duration_s: 35.03`
- pre-push `devtools verify --quick` -> `exit_code: 0`,
`total_duration_s: 33.62`
@Sinity

Sinity commented Sep 30, 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.

  • 67.F044 / P2: fixed-already at the checked revision: Daemon residency is now determined by a nonblocking shared flock of the daemon pidfile at polylogue/maintenance/offline_guard.py:113-115, not by reading /proc. running_daemon_pid delegates to that lock-based probe at line 153, and the offline-maintenance boundary refuses a resident holder at lines 231-235, so the absence of /proc does not make a running daemon appear absent.

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