Keep operator monitoring in bounded live snapshots and provide scoped replica retirement. Update the board dashboard and retirement regressions.
99 lines
5.9 KiB
Markdown
99 lines
5.9 KiB
Markdown
# Operator monitoring: bounded live snapshots
|
|
|
|
Implemented 2026-10-16, following the operator storage rule in `AGENTS.md`.
|
|
The operator's job is to see current onboard computer health. The existing Fleet
|
|
board monitoring page retains its placement and canonical Design Guideline
|
|
components. It no longer offers historical windows or claims to own an archive.
|
|
Keeping the old chart/window controls would promise data this operator service
|
|
must not retain; moving this view to a new workspace would add navigation without
|
|
changing that job. No new product root or visual component is introduced.
|
|
|
|
## Producer, transport and storage contract
|
|
|
|
`src/k1link/fleet/monitor.py` admits one validated latest observation per node.
|
|
It never creates, opens or migrates a SQLite database. The existing FleetRegistry
|
|
constructor remains compatible; its storage path is ignored by MonitorReceiver.
|
|
|
|
- At most 32 active node snapshots. When full, a new node is refused until an
|
|
existing entry expires; established nodes can still replace their own snapshot.
|
|
- At most 384 metric definitions/values and 64 classified events per observation.
|
|
Each serialized sample is limited to 32 KiB; the projected snapshot to 192 KiB.
|
|
The retained serialized payload and duplicate-comparison sample together are
|
|
bounded by 7 MiB for 32 nodes, plus bounded Python metadata/string overhead.
|
|
This is not a process RSS ceiling.
|
|
- Only `schema`, `source_id`, `definitions` and `latest` are projected. Incoming
|
|
historical batches and archive metadata are not copied into retained memory
|
|
or disk. Existing HTTP transport still receives the v1 envelope.
|
|
- Expiry is 30 seconds from receipt or observation time, whichever expires first.
|
|
Receipt expiry uses a monotonic clock; stale and more-than-5-second-future
|
|
observations cannot populate the view. A one-second idle sweeper also runs
|
|
without API consumers. UTC date changes clear the store; process restart starts
|
|
empty. No age-based cleanup of simulation data is involved.
|
|
- Replayed or duplicate sequences never extend freshness or expiry; conflicting
|
|
duplicates are rejected. A delayed observation cannot replace a newer one.
|
|
- Fresh means observation age below 10 seconds and receipt age below 15 seconds.
|
|
Older retained values are explicitly stale until expiry, then unavailable.
|
|
|
|
The existing v1 transport acknowledgement now includes `mode: "live"` and
|
|
advances `after` to the consumed latest sequence. This is transport consumption,
|
|
not a durable replication receipt. The current Node transport accepts this
|
|
cursor and ignores the additive field. Board archive retention is independent
|
|
of the cursor: the archive batch is a SELECT, not acknowledgement-driven deletion.
|
|
No onboard installation, archive retention policy or board data is changed by
|
|
this operator migration. Future transport versions may omit historical batches
|
|
at the sender; that is not claimed by this change.
|
|
|
|
## API and UI
|
|
|
|
`GET /api/v1/fleet/{vehicle}/monitor` returns `mode: "live"`,
|
|
`history_available: false`, freshness/age and remaining lifetime; its response
|
|
has `Cache-Control: no-store`. Legacy `metric`, `window` or `end` query parameters
|
|
return HTTP 400 instead of silently pretending to provide history.
|
|
|
|
The existing page shows current metric groups and events belonging to the latest
|
|
observation. Missing measurements remain missing, never numeric zero. Polling is
|
|
sequential every five seconds with a 12-second request timeout. A separate local
|
|
expiry tick removes values even during request failure, a hung request or a
|
|
suspended tab. Expiry includes request duration and uses the greater of wall and
|
|
monotonic elapsed time. Initial errors end the loader; stale/error states cannot
|
|
claim fresh data. Historical chart controls, aggregates and window selection are
|
|
removed from this live-only surface.
|
|
|
|
## Retiring an existing Mac replica
|
|
|
|
Install and accept the live producer/consumer first. Then generate a fresh plan:
|
|
|
|
```sh
|
|
.venv/bin/python scripts/retire_monitor_replica.py plan > .runtime/monitor-retirement-plan.json
|
|
.venv/bin/python scripts/retire_monitor_replica.py apply --plan .runtime/monitor-retirement-plan.json
|
|
```
|
|
|
|
The tool permits only `monitor.sqlite3`, `monitor.sqlite3-wal` and
|
|
`monitor.sqlite3-shm` directly under `.runtime/mission-core/fleet`. It checks the
|
|
known four-table schema with an immutable read-only connection, canonical paths,
|
|
regular-file identities and SHA-256. Unexplained orphan sidecars, links, changed
|
|
plans or unknown tables block removal. Apply independently verifies canonical
|
|
Core health and every existing Fleet monitor's live-only contract. `lsof` must
|
|
show no process holding any target; identities are checked again before unlink.
|
|
Sidecars are removed first and the main database last, allowing interrupted
|
|
operations to be replanned against the remaining known schema. There is no
|
|
recursive cleanup, vacuum, board command or raw-sample export.
|
|
|
|
Intent, removed identities and filesystem free-space observations are journaled
|
|
under `.runtime/storage-maintenance/monitor-retirement`. These small maintenance
|
|
receipts are evidence, not persistent monitoring samples. Logical file bytes are
|
|
an upper bound on space reclaimed; concurrent filesystem activity affects the
|
|
observed free-space delta. Repeating plan after completion returns no candidates.
|
|
|
|
## Verification
|
|
|
|
`tests/test_board_monitor.py` covers bounds, sequence/source ordering, duplicate
|
|
freshness, stale/future samples, idle expiry, UTC reset, restart, JSON validation,
|
|
copy isolation, current events and the API. `tests/test_monitor_retirement.py`
|
|
covers exact scope, schema/path/hash rejection, open-file refusal (including a
|
|
real open SQLite reader), interruption and independent live-mode acceptance.
|
|
The existing Node package tests keep collector/packaging coverage. Frontend tests
|
|
cover unavailable/stale/error states, client expiry and absence of history controls.
|
|
Live endpoint, UI and deletion acceptance are recorded separately in the dated
|
|
operator report; unit tests alone are not proof of deployment or reclaimed space.
|