Repository navigation
fix(daemon): record lifecycle heartbeats and termination forensics - #2802
Conversation
|
Warning Review limit reached
Next review available in: 56 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (17)
✨ Finishing Touches🧪 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: 3447f67a5d
ℹ️ 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".
Adversarial self-review — iteration 1Findings and corrections:
Verification:
What survived scrutiny: the liveness probe remains process-local and DB-free; |
Adversarial self-review — iteration 2Findings and fixes:
Verification:
What survived scrutiny: criterion 5 is intentionally not treated as closed. |
Adversarial self-review — iteration 3Findings and fixes:
Verification:
What survived scrutiny: SIGTERM still writes normal forensics when OPS is |
Adversarial self-review — iteration 4 (zero findings)Full Final acceptance-criteria matrix
Verification that protects these claims:
|
Problem: daemon exits could leave only a stale pidfile and a stopped log, with no durable signal, clean-stop, or heartbeat evidence. What changed: add the disposable ops-tier daemon_lifecycle ledger; persist start, periodic heartbeat, signal, and stop transitions; make status use heartbeat freshness; expose the process-local heartbeat age in /healthz/live; and dump all thread stacks before SIGTERM/SIGINT exits. Compatibility: the pidfile remains the single-instance lock. Existing systemd modules already restart failures with a five-second backoff.
Preserve the full handler values returned by Python's signal API while casting only at the restoration boundary, so strict typing matches the runtime contract.
Log an unreadable lifecycle ledger and report its state as unknown so status does not silently collapse an operational failure into absence.
Schedule the disposable lifecycle heartbeat independently of index statistics and convergence so schema-blocked API/health surfaces retain an honest running claim.
Run lifecycle heartbeats through the daemon writer coordinator even when schema preflight blocks archive maintenance. Classify SIGINT as a signal and exercise the real read-only daemon process through SIGTERM shutdown.
Problem: lifecycle startup could strand its pidfile on an OPS failure,\nand the synchronous signal path inherited a 30-second SQLite busy timeout.\nStatus also read lifecycle state twice and could publish contradictory data.\n\nWhat changed: clean up failed lifecycle startup, use a bounded existing-OPS\nwrite for signal forensics, and derive status liveness from one snapshot.\n\nRef polylogue-peo.
Use the health model from its defining module so the status snapshot\nregression test remains strict-mypy clean.\n\nRef polylogue-peo.
The lifecycle signal test measures an OS-level SQLite lock timeout; a frozen\nclock cannot advance that external contention.\n\nRef polylogue-peo.
Problem: final shutdown bookkeeping could still wait on a locked OPS tier,\nand the schema-blocked test did not prove lifecycle scheduling.\n\nWhat changed: skip nonessential shutdown events for terminating signals, bound\nthe final lifecycle stop, and cover real locked-OPS process exit plus lifecycle\ntask scheduling.\n\nRef polylogue-peo.
Keep signal-termination cleanup type-safe after the bounded shutdown path.\n\nRef polylogue-peo.
14337b0 to
086f2c2
Compare
…807,2780,2790,2791,2795,2802,2806,2809 uwk3, jph5 (rigor-contracts #2783), bby.17 (web-cockpit #2793), dmp (terminal-note #2801), ra3w (basetemp-fix #2807), r4no/bkff/r2kb (extension-redesign #2780) fully satisfied — closed. nhjs (#2793), peo (daemon-forensics #2802), 4g3n (#2780), 67ac/212.11 (demo-corpus #2795), rsad (mcp-ergonomics #2790, real gaps remain per 5-iteration adversarial cap), 9e5.8.4/jnj.7 (provider-origin #2806), mrxt/37t.12/p5g/rxdo.4 (annotation-judgment #2791), s7ae.8/20d.2 (live-performance-2 #2809) partially satisfied — noted with disposition, left open. Also discovered and documented the actual root cause of this session's recurring bead-revert incidents: bd reimports the live database from .beads/issues.jsonl on every CLI invocation, so a write not immediately exported is lost the moment the next bd command runs. Every mutation in this commit was individually export-verified against that behavior. Co-Authored-By: Claude <[email protected]>
|
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
Adds durable daemon-lifecycle forensics and a heartbeat-based liveness claim.
Ref polylogue-peo.
Problem
A daemon termination could leave only a stopped log and a stale pidfile. The
operator could not distinguish a clean stop, SIGTERM, or a vanished process,
and the status surface could still claim that the daemon was running.
Solution
ops.dbdaemon_lifecycleledger for process start,heartbeat, signal, and stop state.
stacks through
faulthandler, record the signal, and then exit normallythrough daemon cleanup.
daemon write coordinator. The synchronous signal-handler write is a
best-effort pre-exit fallback with a real 500ms SQLite busy timeout.
missing or blocked derived tier does not make a living daemon appear gone.
derives status liveness from one lifecycle snapshot to avoid shutdown races.
runningfrom a fresh durable heartbeat rather thanthe pidfile; exposes lifecycle state and heartbeat age in the payload.
heartbeat_age_sto/healthz/livewithout adding DB I/Oto that probe.
inventory.
The upstream Nix and Home Manager daemon modules already specify
Restart=on-failureandRestartSec=5s; no systemd change was needed.Acceptance criteria
daemon_lifecycle, signal handlers, atexit sentinel, focused real-daemon SIGTERM test/healthz/livetestsnix/module.nixandnix/hm-module.nixservice directivespolylogue-bby.1closed with merged PR #2673 / commit5479beab143(128 + 15), records the signal/stop row, and emits a stack dump. The observed exit144is not ordinary SIGTERM by POSIX signal numbering and remains an external harness/systemd incident for evidence collection; the original serving/convergence death has not been reproduced.Verification
env TMPDIR=/realm/tmp/polylogue-daemon-forensics-tests POLYLOGUE_PYTEST_BASETEMP_ROOT=/realm/tmp/polylogue-daemon-forensics-tests devtools test tests/unit/daemon/test_daemon_status.py::test_build_daemon_status_uses_one_lifecycle_snapshot tests/unit/daemon/test_daemon_lifecycle.py::test_signal_write_does_not_wait_for_the_normal_writer_timeout tests/unit/daemon/test_daemon_cli.py::test_lifecycle_start_failure_releases_pidfile tests/integration/test_daemon_resilience.py::test_sigterm_read_only_daemon_records_forensics4 passed.temporary archive, sends SIGTERM, and reads the production
ops.dbrow;the lock test holds a real SQLite write lock and proves the handler does
not inherit the ordinary 30-second busy wait.
devtools verify --quickhygiene, and degrade-loudly checks all passed.