← Back to Pull requests

plan/168: device daemon self-healing + app-triggered repair #115

Open
unknown opened this pull request with 339 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 22, 2026 23:48 UTC
Author

plan/168: device daemon self-healing + app-triggered repair

What

Closes the 2026-11-22 incident class: a wedged device daemon (alive process,
stuck event loop) left room device dark for 5.5 h with no repair path — all
control verbs run inside the target's pi process, which a wedged loop never
processes. Relay unchanged.

Three detection/repair layers plus the app UX:

1. Supervisor ping loop — pipe-pings every RPC child every 30 s; 2
consecutive misses (≈60 s) → kill + respawn (--continue keeps the
conversation). Fastest layer; works even with the relay down.
2. daemon_control action verb (restart/status) — a live daemon
answers itself (acks first, then exit 1 → supervisor crash-respawn). When
room device is dark, the keeper now holds it control-only (connects
without roomMeta, never appears as a session, yields to the real daemon
on hello) so the phone can ask the supervisor to bounce the child.
Kill-switch allow_remote_session_control:false refuses both paths.
3. Watchdog — supervisor probed with a real {"op":"status"} pipe
round-trip (3 fails → kill + restart; a connect-only probe false-OKs a
wedged loop). The daemon refreshes registry lastSeenAt on its 60 s tick;
stale >5 min → bounce ONLY the device child (10 min cooldown, never the
whole supervisor, never the plan/159 backoff state).
4. App — Projects screen diagnoses failures (no relay vs "Device daemon
offline on <peer>"), auto-repairs ONCE per visit (10 s grace → restart →
≤10 s re-announce wait → single list_projects retry), then falls back
to a Retry restart button.

Evidence (live replays, 2026-11-23)

  • Wedged daemon (NtSuspendProcess): ping miss 1/2 → 2/2 → kill +

  • respawn, room re-announced ≈41 s (budget ≤90 s); keeper released the
    claim on the daemon's hello.
  • Wedged supervisor (suspended): watchdog probe FAIL 1/3 → 3/3 over

  • ≈98 s → kill + restart ≈105 s; the old daemon followed via stdio-EOF,
    clean respawn, relay untouched.

    Tests

  • pi-extension: suites green (7 known pre-existing env-sensitive flakes,

  • exonerated vs main by A/B).
  • app: full suite +1122 green; analyze shows only the 4 pre-existing infos.

  • New: 8 protocol + 3 repository round-trip + 7 viewmodel (fakeAsync) + 2
    widget tests.
  • Drive-by fix: ConnectionManager.dispose() now cancels the online-recheck

  • periodic timer (leak exposed by the new tests).

    Docs

  • PROTOCOL.md — "Device daemon control (plan/168)": dual serving paths,

  • kill-switch, request/reply shapes.
  • pi-extension/docs/daemon.md §3b — self-healing layers; outage window for

  • the incident class: hours → minutes.
  • Root + app changelogs [Unreleased].
  • Diff: 339 lines (+254 / -85) across 4 files Reviewer: github-actions[bot] Review duration: 11m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.42) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 339 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.349
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #115"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.3% (MEDIUM) · Higher = larger blast radius
    42.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.1% · Safe to merge
    24.1%