Repository navigation
Description
Decision (12 November 2026): keep hybrid production ownership. The completed twelve-case/twelve-window experiment, numerical no-go and scoped follow-up sequence are recorded in the final decision. No production migration is performed.
Analysis baseline: main @ 3ec3455 — 9 November 2026. Priority: P2 — Architecture / Investigation ## Context / Current Behavior Current monitoring is hybrid: Bun/PostgreSQL own policies, schedules, leases, revision/context checks, observations and incident state; Rust handles requested active-upstream probes. The native diagnostic result distinguishes unknown/busy/stale from actual host failure. There is no autonomous Rust monitoring scheduler or monitoring database client. Other native tasks already persist/recover from controller-owned state, but they cannot be assumed to remain running through Bun death under the current appliance supervisor. #392 addresses the present hybrid capacity problem; this issue evaluates ownership and continuity after those bottlenecks are understood. ## Problem Statement Monitoring stops when Bun cannot coordinate checks. An autonomous scheduler may improve continuity or resource use, but adds policy synchronization, durable state, result delivery and permission/revision consistency costs. Moving only the loop into Rust does not settle these problems or guarantee outage notifications during a management failure. ## Proposed Architecture / Solution Compare two complete designs against an optimized hybrid baseline, rather than comparing Rust to today's known one-worker bottleneck. | Concern | A — Hybrid | B — Autonomous Rust runtime | | --- | --- | --- | | Scheduling/admission | Bun with PostgreSQL policies/leases | Rust owns bounded schedule/execution lifecycle | | Network execution | Bounded concurrent Rust probes | Bounded concurrent Rust probes | | Management | Bun API/UI/RBAC and policy writes | Bun API/UI/RBAC and policy publication | | Durable state/results | PostgreSQL commits by Bun | Explicitly designed restricted DB access or native durable state plus bounded replay | | Incidents/notifications | Existing Bun state machine/queue | Explicit single authoritative owner; no duplicate policy logic | Deliver the design decision and experiments in this issue; do not initiate a full migration. ## Implementation Scope - Define policy source of truth, version/generation/acknowledgement, invalidation and initial/resync/reset protocol. - Compare restricted PostgreSQL access with controller-native durable state/outbox and internal APIs. Explain what remains available while Bun is absent; an API hosted only by Bun cannot alone provide that persistence independence. - Define claim/fencing or equivalent execution authority, per-host exclusion, deadlines, cancellation, stale-result rejection and revision changes across process/controller restart. - Specify observation/history durability, bounded backlog/replay, maximum supported outage and what happens at storage pressure. Do not promise unlimited lossless history through indefinite management outage. - Preserve one availability/incident state machine. Explain how host continuity proofs and global within-probe configuration fences survive the boundary. - Define edit/disable/delete/revocation behavior while Bun cannot publish changes, including user-visible pending acknowledgement and prevention of resurrection after reconnect. - Define notification integration and audit receipts. Monitoring execution continuity, durable incident persistence and outbound notification continuity are separate promises. - Preserve restore quiescence, state/key replacement, replay/store identity reset and explicit reactivation of restored external automation. - Compare total CPU/RSS/connections, checks/s, freshness, restart recovery, IPC/storage amplification and implementation/test burden. ## Security and Reliability Considerations Rust must not receive broad database credentials, arbitrary destinations, SMTP/webhook secrets or complete application secrets solely to simplify implementation. Any DB role/API must have the least necessary tables/actions and fresh policy scope. Preserve configured active host validation, credential-free HEAD checks, TLS/trusted-CA controls, bounded requests and no redirect following. Do not duplicate authorization or incident logic across languages. ## Acceptance Criteria - [x] A/B designs specify every scheduler/state/persistence/security/restore owner and all policy/result synchronization failure modes. - [x] Use #392's measured 1,000-policy/60-second capacity envelope, including slow/mixed probes; predeclare numeric resource/freshness/recovery success and no-go thresholds. - [x] Demonstrate whether B improves an explicit continuity or resource metric beyond measurement noise compared with optimized A, including synchronization/storage overhead. - [x] Claim Bun-crash continuity only after #403 provides safe supported component isolation and a fault test proves ongoing execution; current autonomy of unrelated Rust tasks is insufficient. - [x] Prove edit/disable/revocation, stale-result and restart fences; bounded replay cannot create duplicate observations/incidents or bypass restore. - [x] State what happens to notifications during Bun loss, how long results can be retained and how management discovers incomplete evidence. - [x] Recommend migration only if benefit justifies added ownership/persistence/maintenance complexity. A documented keep-hybrid decision is a valid outcome. - [x] Final recommendation and a scoped follow-up sequence are recorded here; no production migration is performed by the investigation. ## Testing Requirements Plan matched bounded A/B fixtures through #397 for Bun TERM/KILL/hang, controller restart, PostgreSQL outage, policy changes in flight, stale generation, lease expiry, replay gap/duplicate, full result storage and restore during checks. Assert external observable progress and durable post-recovery state, not only that a Rust process stayed alive. Preserve existing state-machine and diagnostics security regressions. Keep normal checks short. ## Dependencies / Related Issues Final recommendation requires #401 ownership findings, #392 capacity results and #403 isolation/maintenance foundation. Use #396/#397 measurements and #399 database findings. #398 is a separate comparison of a dedicated Bun role; do not use either investigation to preselect the other's conclusion. #393 retains responsibility for notification delivery scaling. ## Relevant Source Files - web/src/server/HostMonitoring/host-monitoring.worker.server.ts - web/src/server/HostMonitoring/host-monitoring.repository.ts - web/src/server/HostMonitoring/host-monitoring.probe.ts - web/src/server/RuntimeDiagnostics/domain-diagnostics-data.ts - web/src/server/Notifications/host-availability.repository.ts - web/src/server/Notifications/host-availability.ts - web/src/db/Schema/hostMonitoring.ts - web/src/lib/HostMonitoring/state.ts - core/src/runtime/domain_diagnostics.rs - core/src/runtime/lifecycle.rs - core/src/runtime/configuration.rs - core/src/runtime/engine/maintenance.rs - core/src/server/handlers/domain_diagnostics.rs - core/tests/private/domain_diagnostics.rs - web/src/tests/server/HostMonitoring/host-monitoring.repository.db.test.ts - web/src/tests/server/Notifications/host-availability.db.test.ts
Activity
RentnerKev commentedon Nov 12, 2026
Decision: keep hybrid production ownership
The complete source-pinned investigation in #418 is finished. The original runner completed all twelve safety cases and twelve full 120-second windows, with three alternating A/B2 pairs for each profile. Its original result is
completeness=complete,recommendation=keep-hybrid. Exit 1 records the numerical no-go; it does not mean missing observations or failed cleanup. No production migration is performed.B2 did not justify its additional ownership/persistence complexity. All six pairs exceeded both predeclared added-resource ceilings; two B2 slow-profile windows also exceeded the SSR latency ceiling. Retain the optimized hybrid scheduler and single Bun observation/incident/notification owner.
Complete designs and authority
Cached publication alone (the B1 alternative) cannot prove fresh admission after a committed revocation. An API hosted only in the failed management process also cannot establish that process's persistence independence. B2 therefore uses a separate restricted SQL role, private native state and surviving broker/publisher processes. UID/GID 20004 has no broad application-table or secret access; its SQL role is capped at two connections. The configured active-host, credential-free HEAD, TLS/trusted-CA, deadline and no-redirect controls remain authoritative.
Policy/grant changes invalidate old authority. Initial publication, reconnect/resync and reset require current store/controller identity, generation, policy/grant versions, active-host proof, revision and exact unexpired lease. A disabled, deleted, revoked or unpublished policy cannot gain fresh admission from a cached snapshot or resurrect after reconnect. Stale/conflicting/gapped results cannot bypass the authoritative Bun transaction. A matching terminal receipt and contiguous raw sequence prefix are required before ACK; duplicate replay cannot create duplicate observations/incidents.
Raw retention is 120s, observation leases 45s, replay batches bounded, and storage limited to 4,096 records / 16 MiB with a 4 KiB per-record bound. Expired/unacknowledged or capacity-pressure state visibly stops admission. Retained history does not acquire incident eligibility after lease expiry. Management must surface incomplete/expired evidence. Notification delivery remains dependent on its Bun owner; this is not a promise of continuing outbound alerts during management loss.
Matched measurement
Every window uses 1,000 policies / 60s, 64 scheduled plus 2 interactive slots and the same 2 CPU / 1 GiB / 512 PID / 100-connection envelope. Both collectors arm before one shared absolute wall/monotonic origin. All twelve declared durations are 120,000 ms; there are 1,452 resource samples. First samples are+16–19ms from origin, last samples+8–11ms from the declared end, final unfiltered reports+15–32ms after it.
Each window contains exactly 2,000 actual HEADs, starts, observations and covered slots: 24,000 of each overall. Duplicates, unexpected outcomes, traffic errors and OOMs are zero. Final active work, backlog and raw outbox are zero in every window. Native owners remain the qualified identities (A: 0, B2: 1); the controller remains the same across all windows. Peak SQL clients are 34 in both designs.
CPU 100% means one CPU core; the quota is two cores. RSS is the declared sum of
/proc/*/statusVmRSS, so shared pages can be counted more than once. It is not physical-memory attribution. Cgroup working set is reported separately (maximum 932.633 MiB), with no OOMs.The original limits were not changed: B2 overhead relative to A: CPU≤10%, peak summed RSS≤32MiB, extra SQL clients≤2; due-to-start p99≤55s; due-to-commit max≤60s; SSR/proxy p99≤250ms and zero traffic errors. An efficiency claim additionally requires ≥20% benefit beyond twice measured variation.
Actual pair deltas are CPU +20.19–65.53%, summed RSS +32.40–273.22MiB, additional SQL clients 0. All six pairs exceed both resource budgets. Maximum due-to-start p99 is 50.472s and maximum due-to-commit54.247s, so freshness passes. Proxy p99 stays below 1.264ms. The only per-window gate failures are SSR p99 311.010572ms and 258.854698ms in timeout B2 pairs 2/3. Original global failure codes are
added-resource-budget-exceededandwindow-gate-failure;efficiencyJustified=false. Measured relative variation is 18.09%, and no pair has a positive CPU/RSS efficiency benefit.Whole-database commit deltas also expose synchronization/storage cost: mean per 120s A/B2 commits are 2,659/14,680 for mixed and 2,023/22,919 for all-timeout. These counters include the identical observer and other appliance work; they are not SQL-call, fsync or disk-byte counts. Native journaling/replay and broker/publisher costs are included in the appliance measurement, not credited as free external work. These are bounded two-cadence reference windows, not a sustained production SLA or release soak.
Safety, continuity and recovery
All twelve original cases passed: replay, authority fences, lease expiry, pressure, sequence gaps, automatic publication, web TERM/KILL, PostgreSQL outage, controller restart, fresh-volume restore and Bun STOP.
Source, artifacts and reproducibility
Final experiment b6db98ca, tree
ab1f9ff1f7105af39594d6684e3c69007534984f, overlay SHA-25689d6f20f3bcbb67bbcfa90301ad40fc84f84e939b5f1c2503c5193aa860612dd.Named production baseline
01d0504010cb825333a56a92b18f20d36ff6b890, treeb22fed6050d2be78bd2630e7b7aad4d44f08ebf9, scope43154399125-1; verified producer and independent hash consumer. App IDsha256:d1bbcf40d24fa419bbc3e4b10519cd3595f10c4026823e2d020826f578b29aaf; fresh prototype IDsha256:b5030086bbc492ef7f2bd089ba411fe59abefe3b1cf7e257f9ace36589a4679a.Baseline and experiment deliberately keep separate source/metadata identities. Their exact four-file difference is confined to experimental cap/owner types/tests; production, Docker, harness, dependency and Rust source inputs are unchanged. The original CI image/receipt is not relabelled as a b6 build. A fresh final-source overlay preserves original production assets. Rust input SHA-256
9105d58122de3b29d4ad615a8091c36bfe0c7b5e033ffd80ce6ef56b51634113, ELF212b3478a6b30e6d5bd3a87c67f81297449859681ccf561a88890f4f487d4f99, manifestf19ede3b69b46dc33318eff05a211cf1cb0410b9c1045520e66411a0918ccd5f; rustc 1.99.1, frozen/offline inputs. No Git-origin field is invented for that manifest.Original report SHA-256
b2e60df1d039640224db1320c7e1e3bde40473a00df989bc1499391ec96db339; original log219f20a00612093a186c043e962432559a3ca8075230d3d7465da8caeffe4cfa; final binding1daec31808a155a5e0fd07231cb708b3b036cc84430870fcc30af049120d5593. Raw artifacts remain local and unchanged; no extra documentation/report file is committed, as requested. Earlier diagnostic/insufficient reports retain their original identities. Independent Docker queries confirmed no remaining owned containers, networks or volumes and no prototype image; the full report has no cleanup failure.Final b6 CI/security checks are green. CodeRabbit reviewed b6 with no actionable comments and explicitly cleared the five carried-over notes. The final PR/body-linked checks are refreshed before merge.
Scoped follow-up sequence