Repository navigation
Description
Analysis baseline: main @ 3ec3455 — 9 November 2026.
Priority: P2
Context / Current Behavior
The appliance already starts the controller/Caddy before PostgreSQL and Valkey so valid persisted routes can recover independently of their readiness. Rust owns verified active snapshot/fence recovery, bounded Caddy child-exit recovery, ACME renewal, DDNS and Docker observation. These are existing strengths.
Unexpected death of any supervised child still causes root supervisor failure and ordered appliance-wide teardown. A dead Bun process therefore leads to controller/Caddy shutdown; a new worker process alone does not change this contract. A hung but alive Bun process is different: shell kill -0 monitoring does not detect it. Podman health policy can kill/restart an unhealthy appliance; Docker Compose's restart policy alone does not provide the same unhealthy-to-restart bridge.
Caddy is controller-owned and shares its Unix identity. Normal shutdown drains it; controller SIGKILL may temporarily orphan it because kill_on_drop is a Rust cleanup behavior, not a kernel parent-death guarantee.
Problem Statement
Management-plane failure can unnecessarily disrupt otherwise working proxy/native tasks. Safe component restart requires explicit ownership, failure classification, health, credential restoration and maintenance rules. Generic "restart web/controller independently" logic could start duplicate Caddy processes or resume writers during backup/restore.
Proposed Architecture / Solution
First define a component/fault/state matrix and the supported continuity contract. Then implement only safe, measured individual recovery paths within the existing single-container appliance. Preserve appliance-wide fail-stop behavior when recovery cannot prove singleton ownership, compatible state or a safe maintenance checkpoint.
Separate web readiness, proxy readiness and worker progress. This issue is the foundation before any promise of Rust background availability through Bun failure.
Implementation Scope
- Map normal/maintenance/startup/shutdown behavior for web, controller, Caddy, PostgreSQL, Valkey, root backup agent and managed CrowdSec supervisor.
- Test crash versus hang/unreachable dependency separately. Rust's recovery loop normally runs every five seconds with failure backoff up to 60 seconds; it detects Caddy child exit but can skip functional probing when the child looks alive. Decide bounded native functional-health/progress detection rather than treating PID existence as health.
- Specify restart eligibility, attempts/backoff/jitter, circuit breaker/escalation and observable partial degradation per component. Keep intentional stop distinct from unexpected failure.
- Evaluate safe web-only restart with existing worker fencing and DB connections; separately evaluate controller failure/Caddy ownership rather than reusing web policy.
- Resolve old Caddy identity/process-group/socket ownership before any replacement controller starts; never race two owners or reuse a PID-only proof.
- Preserve persisted-snapshot authority, pending-activation fence, active revision probe, private admin sockets and last-known-good traffic on failed apply.
- Account for external CrowdSec's management-supplied credentials on cold initialization; managed mode's native recovery must not be generalized to every provider.
- Preserve root-authorized backup Caddy handoff, exporter singleton/timeout rules, destructive restore journal/writer fences, key reload and final readiness proof.
- Align Docker/Podman health and stop/restart policy across supported Debian/Fedora AMD64/ARM64 packages without adding mandatory infrastructure/processes.
Security and Reliability Considerations
Keep separate web/controller/PostgreSQL/CrowdSec identities, private state directories and narrow backup socket commands. Caddy and controller are not separate security principals; document that actual boundary. No process gets broader file/secret permissions to simplify restart.
A surviving Caddy cannot renew certificates itself because automatic HTTPS is disabled; prove controller task continuity separately. Valkey remains ephemeral auth/rate-limit/realtime support, not durable recovery authority. Backup/restore may intentionally stop consumers; never reinterpret that pause as a crash and restart writers beside an orphaned exporter.
Acceptance Criteria
- An explicit matrix defines supported outcomes for web TERM/KILL/hang, controller TERM/KILL/hang, Caddy exit/live hang, PostgreSQL/Valkey failure and maintenance interruption.
- Before implementation, set numeric recovery/restart limits and declare which failures must preserve existing proxy/native-task progress versus require safe appliance restart.
- In supported isolated-web failure cases, external HTTP/HTTPS probes and relevant Rust progress markers demonstrate the declared continuity; report any interruption honestly.
- Controller recovery proves singleton Caddy/process/socket ownership, rejects unsafe persisted state and cannot start a duplicate runtime.
- Restart storms are bounded and escalate visibly; liveness, readiness and worker degradation remain distinct.
- Startup retains the already implemented pre-database/cache route recovery; management auth/readiness gates remain intact.
- Backup/restore and failed/interrupted destructive maintenance retain writer fencing, singleton exporter/agent, credential reload and truthful final success.
- Matched failure measurements report outage/recovery time, traffic errors and total resource overhead separately for supported Docker/Podman delivery variants.
- No Bun-crash independence is advertised until the relevant complete fault scenario passes; Caddy traffic-reset issue bug(scale): concurrent Caddy configuration updates reset proxy traffic #171 remains independently tracked.
Testing Requirements
Extend existing Rust runtime recovery/shutdown/Caddy maintenance tests and real appliance boundary/backup tests. Use short isolated 60–180-second fault cases with external traffic, process start-time identity, revision and Rust progress observation. Include orphaned controller/Caddy handling, occupied sockets, hung admin/probe, degraded dependencies, exhausted restart budget, restore in flight and failure between state replacement and restart confirmation. Reuse #397 exact-revision fixtures and existing native packaging checks; do not start release soaks automatically.
Dependencies / Related Issues
#158 already established pre-PostgreSQL/Valkey route recovery; #159 already aligned request draining and is not reopened. #401 supplies ownership boundaries, #395 supplies safe web-worker drain/maintenance contracts and #396/#397 supply measurements/fault fixtures. #402 and #398 consume this isolation decision before claiming autonomous monitoring or process-extraction benefits. This issue owns process-level recovery, not a replacement for domain job idempotency or Caddy's data path.
Relevant Source Files
- docker/production/entrypoint.sh
- docker/production/Dockerfile
- docker/production/backups/supervisor.sh
- docker/production/backups/agent.ts
- docker/web/healthcheck.ts
- docker/web/serve.ts
- docker-compose.yml
- packaging/linux/rentnerproxy.container.in
- packaging/linux/rentnerproxy
- core/src/runtime/lifecycle.rs
- core/src/runtime/configuration.rs
- core/src/runtime/engine.rs
- core/src/runtime/engine/maintenance.rs
- core/src/runtime/crowdsec/configuration.rs
- core/src/server/handlers/health.rs
- web/src/server/Foundation/health.service.ts
- core/tests/private/runtime/recovery.rs
- core/tests/private/runtime_shutdown.rs
- core/tests/private/caddy_shutdown.rs
- docker/production/tests/runtime-boundaries.sh
- docker/production/tests/backups.sh
Activity