Repository navigation
Description
Analysis baseline: main @ 3ec3455 — 9 November 2026.
Priority: P1
Context / Current Behavior
The 1,000-policy limit is a configuration admission cap, not demonstrated execution capacity. The Bun worker runs one claim at a time and waits another 1,000 ms after completion before its next pass. PostgreSQL admits at most two active monitoring leases globally; claims already use an oldest-due ordering and FOR UPDATE SKIP LOCKED, but select only one policy. Rust performs the actual upstream-only DNS/HTTP/TLS probe, with a shared two-permit domain-diagnostics semaphore also used by interactive checks.
Existing 45-second leases, token/version/expiry fences, configuration checks before and after execution, incident transitions and cancellation cleanup are correctness foundations to retain. Network execution already occurs outside the database transaction. nextCheckAt is currently calculated from completion/release, not a fixed periodic schedule.
Problem Statement
Even ignoring network and database cost, one process's completion-relative one-second delay limits it to fewer than 60 checks/minute. A requested 1,000 checks every 60 seconds requires 16.67 checks/second. At three seconds of occupied probe time, the arithmetic lower bound is approximately 50 concurrently occupied execution slots before overhead or interactive reserves; this is a sizing calculation, not a benchmark result. Raising the TypeScript concurrency constant alone leaves database admission and Rust capacity unchanged.
Proposed Architecture / Solution
Build a bounded hybrid pipeline: short PostgreSQL coordination transactions claim a limited batch; Bun dispatches admitted work; Tokio executes concurrent network probes; Bun commits fenced state transitions and notification inputs. Select batch sizes, pipeline limits and result-commit grouping from measured cost. Preserve one authoritative availability state machine and avoid a second scheduler in Rust in this implementation.
Define the scheduling contract explicitly: completion-relative interval, fixed cadence, maximum observation freshness, allowed jitter and overload behavior. Preserve user-requested intervals; a capacity failure must be visible rather than silently increasing intervals or dropping policies.
Implementation Scope
- Measure claim/context/probe/commit/retention costs separately at 100, 500 and 1,000 policies.
- Replace one-at-a-time admission where beneficial with bounded batch claims; maintain oldest-due fairness, stable tie-breaking and per-host exclusion.
- Coordinate lease duration, queued-versus-running time, cancellation and any renewal so a waiting batch cannot outlive its authority. Bound both admitted and in-flight work.
- Tune Rust scheduled-probe admission with explicit interactive diagnostic capacity, global and per-host limits, end-to-end deadlines and backpressure to Bun.
- Reduce repeated context hydration and evaluate bulk persistence without combining unrelated hosts into an all-or-nothing failure. Retain per-result atomic observations, incident transitions and final fencing.
- Separate real upstream failure from busy, unavailable, stale or cancelled execution. Bound retry/backoff without catch-up storms.
- Set numeric due-to-start and due-to-completion p95/p99/max targets and a reproducible latency distribution/resource envelope before acceptance measurements.
Security and Reliability Considerations
Retain configured-active-host checks, HEAD-only credential-free probes, no followed redirects, TLS/SNI/trusted-CA validation, policy authorization and all revision/availability-proof semantics. A policy/host/domain/CA edit, expired lease, controller replacement or old batch result must not commit stale history. Shutdown and restore must stop admission and fence late writes. Protect Caddy traffic and SSR; do not solve throughput by removing limits or routing proxy traffic through Bun.
Acceptance Criteria
- A measured capacity model identifies the first bottleneck and reports checks/s, policy freshness and resource cost independently.
- The supported reference case includes 1,000 enabled policies requesting 60-second checks, realistic mixed latency, explicit scheduling semantics and numeric lag bounds. Every policy progresses and the due backlog does not grow across repeated steady-state periods.
- Include an all-slow/all-timeout case: either meet the declared 60-second contract within an explicitly supported budget or report the unmet capacity requirement and bounded degradation. The 1,000-at-60-second target cannot be declared complete by changing requested intervals.
- Claims, dispatch queues, active host probes and persistence batches remain within declared bounds; interactive diagnostics retain their reserved admission/fairness contract.
- Stale tokens, versions and revisions cannot create observations or incidents; cancellation and expiry recover without duplicate active host execution.
- Existing state transitions, incident history, configuration-change behavior, audit/notification inputs and transaction atomicity remain correct.
- Compare CPU, RSS, PostgreSQL connections/lock time, checks/s and SSR latency separately against the same baseline. Publish only the capacity actually demonstrated.
Testing Requirements
Extend the monitoring worker and PostgreSQL repository tests plus Rust diagnostics tests for concurrent claimers, batch partial failure, lease expiry while queued/running, process crash, slow network, busy admission, starvation, cancellation and edits during probes. Use the background fixture from #397 for mixed healthy/timeout targets, continuous management reads and exact policy-ID coverage. Retain fast regressions for normal PRs; larger capacity runs are explicit performance/release preparation. Do not start a 30-minute soak automatically.
Dependencies / Related Issues
The existing implementation in #287/#288/#289 is the baseline, not work to reopen. Use #401 to confirm the hybrid ownership boundary, #397 for baseline fixtures and the monitoring-specific findings of #399 before changing database coordination. Coordinate resource definitions with #400 without requiring a global framework. #402 separately investigates autonomous Rust scheduling after this capacity work and #403 establish evidence; it does not block targeted hybrid improvements.
Relevant Source Files
- web/src/config/host-monitoring.config.ts
- web/src/server/HostMonitoring/host-monitoring.worker.ts
- 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/db/Schema/hostMonitoring.ts
- core/src/runtime/mod.rs
- core/src/runtime/domain_diagnostics.rs
- core/tests/private/domain_diagnostics.rs
- web/src/tests/server/HostMonitoring/host-monitoring.repository.db.test.ts
- web/src/tests/server/HostMonitoring/host-monitoring.worker.test.ts
Activity