Repository navigation
Description
Problem
Monitor.start() currently decides retries, recovery, maintenance, important heartbeats and notifications while also performing networking and persistence. Push monitoring has its own transition decisions. Extracting HTTP transport alone leaves the policy difficult to test and makes future cron, incident and delivery features risky.
The needed improvement is a deterministic decision boundary, not a different default monitoring policy.
Existing work and scope boundary
This is a concrete next behavior boundary within #58, not a replacement for its decomposition plan. PR #66 already extracts HTTP transport and must be reused if merged. Typing is handled by Stage F (FND-018 closes #59); do not refile general cleanup here. Coordinate persistence calls with #56 / PR #67 and handler wiring with #57 / PRs #65 and #68.
Implementation specification
- Characterize the current HTTP/keyword/JSON-query and push transition behavior first, including first observation, pending, retry counts, recovery, inverted checks, maintenance and resend eligibility. Include configuration edits, cancellation and first-check behavior.
- Introduce directly owned typed observation, prior-state, transition-context and effect types in focused modules. Implement a pure reducer with explicit observation time and configuration generation:
(prior, observation, context) -> { next, effects }. Effects describe persistence/notification/incident decisions; the reducer performs no I/O and imports no store or runtime. - Integrate one bounded family at a time using the existing composition and lifecycle owners. Network execution reports facts; the commit owner validates generation and applies effects. Preserve lazy providers and current numeric wire/persisted statuses.
- Move push decisions onto the same policy where semantics match, while keeping push-specific liveness explicit. Do not invent universal policy for every protocol or add a compatibility registry.
- Keep retry, maintenance and recovery defaults unchanged. The inherited retry settings (retry count and retry interval) are the confirmation step: carry them into the policy as-is. Add one optional recovery period to the same policy: after a Down monitor passes, it stays Down until it has passed for N seconds (default 0, which is today's behaviour), so a flapping target does not alternate Down/Up alerts. A new degraded state belongs in a separate feature change.
Acceptance criteria
- Fixture-based behavior tests cover the characterized transition matrix without a real clock, network or database.
- HTTP and push produce the same decisions for equivalent inputs; their intentional differences are explicit and tested.
- A stale result from an edited, paused, deleted or superseded run cannot persist a transition or send an effect.
- Existing external payloads and saved monitor behavior survive the extraction; the new contract is compiler-checked.
- Each implementation PR removes a specific mixed responsibility, rather than only moving methods between large files.
Verification and delivery
Run focused lifecycle, scheduler, timeout, heartbeat-data-plane and HTTP/push behavioral tests; then bun run lint, bun run build and the relevant backend/compiled checks. Capture before/after scheduling overhead, relevant import closure and compiled RSS for runtime changes. Preserve cold-import time inside the configured deadline.
Constraints
Keep Bun, Vue, one compiled executable and SQLite (kuma.db), with the supported Kuma importer. No required hosted service, extra database, worker deployment, Node/npm fallback or new distribution path. Backend code is written in Effect (north star D16, house style in docs/effect.md): dependencies are Effect services provided through layers, expected failures are tagged errors, and every input is decoded with Schema. Use direct @/ imports; no new barrel, ad-hoc registry, broad any facade or @ts-nocheck. Code passes the TS 7 strict typecheck and the @cloudflare/oxlint-config lint (D17). Make additive schema changes through the existing upgrade path; keep legacy rows meaningful.
Implement the idea independently. Staygreen is a design reference at the pinned revision, licensed FSL-1.1-MIT; do not transplant its source, CSS, illustrations or branding into this MIT project.
Source starting points
- iglo:
src/server/model/monitor.ts - iglo:
src/server/routers/api-router.ts - iglo:
src/server/heartbeat-data-plane.ts - Staygreen reference:
probe/state.ts - Staygreen reference:
src/checks/types.ts
Plan placement
Reconciled on 2026-11-21 with the project plan (docs/roadmap.md) and the fixed decisions (docs/north-star.md). If this issue and those documents still disagree, raise it instead of choosing.
- Stage: 1 — Platform track.
- Depends on: refactor: isolate core HTTP monitor behavior #66.
- Foundation first: starts after the Stage F exit gate (Stage F exit gate: foundation complete #120) closes, meaning types, guardrails, and the Effect rewrite are done. Build on the Effect services that own each responsibility after Stage F. File and module names in this issue describe the code as of 2026-10-28 and may have moved.
- Agent parity (P8): every capability this issue adds to the UI ships with its MCP tool in the same PR or stack, calling the same Effect service (D14). Writes follow the feat: command layer with idempotent, scoped, previewable writes #84 conventions (
request_id,dry_run, scopes). - GitHub dependencies: the blockers are also set as GitHub issue dependencies (see the issue sidebar).
- Referenced items: FND-018 = FND-018: Remaining backend sweep, strict mode on, ban @ts-nocheck #118
Activity