-
Notifications
You must be signed in to change notification settings - Fork 0
feat(runtime): separate liveness, readiness, and degraded health #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d89040d
feat(runtime): separate liveness, readiness, and degraded health
cursoragent fff74c5
fix: drop duplicate #[test] on pre-run health assertion
cursoragent 1c8ae36
fix: address DeepSource/Codacy health-surface findings
cursoragent fc314aa
fix: split health helpers to clear rustfmt and Codacy complexity
cursoragent a981786
fix: drop rejected control connections by returning from the helper
cursoragent 35774f7
fix: split remaining health and control helpers below Codacy CCN
cursoragent d23c38f
fix: split health module so Codacy file-length stays under 500
cursoragent 51c9057
fix: address CodeRabbit health-surface follow-ups
cursoragent 192119d
docs: qualify stub backend socket claim for control_bind
cursoragent 594ba75
fix: keep health docs table intact and tighten clock/tests
cursoragent e0e294b
fix: reject equal overload watermarks and ignore pre-start init
cursoragent 724e876
fix: clamp overload watermarks to [0, 1] and drop flaky timing
cursoragent 1a47c8e
test: split documented health snapshots under Codacy's 50-line limit
cursoragent ccb18f5
fix: ignore pre-start failures and reply 503 when control is saturated
cursoragent 9893bbb
fix: scope fatal docs to started states and use try_snapshot on control
cursoragent 0cafdea
fix: bound busy control replies and clarify monotonic clock
cursoragent f87ff32
docs: qualify /health and /metrics 200 with 503 busy
cursoragent f582e1d
docs: require Clock::now to be non-blocking
cursoragent 606f7aa
Merge origin/main into health states and wire live checkpoint/queues
cursoragent 4b10127
Merge origin/main to pick up the fault-injection harness
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| # Runtime health | ||
|
|
||
| Supervisors should treat **liveness** and **readiness** as independent. A live | ||
| `brainstem-daemon` process has a health reporter; it is ready only after | ||
| `StimulusSource::initialize` succeeds **and** a checkpoint is validated | ||
| (`restore_network` in live mode, or the explicit simulation blank network). | ||
| Live mode uses the Distill sidecar SHA-256 as `checkpoint.digest`. Simulation | ||
| mode reports `digest: null`. | ||
|
|
||
| This repository had no HTTP/metrics server before this surface. When | ||
| `control_bind` is set, `BrainstemDaemon::run` starts **one** listener: | ||
|
|
||
| | Path | Meaning | | ||
| |---|---| | ||
| | `GET /livez` | `200` if live, `503` otherwise | | ||
| | `GET /readyz` | `200` if ready, `503` otherwise | | ||
| | `GET /health` | `200` JSON [`HealthSnapshot`](../src/health/snapshot.rs) (inspect `phase`); bounded `503 busy` if the control plane cannot snapshot | | ||
| | `GET /metrics` | Prometheus text; labels are phase/reason codes only; same `503 busy` exception | | ||
|
|
||
| Leave `control_bind` unset to preserve the historical no-extra-socket default. | ||
| Do not add a second control server beside this one. | ||
|
|
||
| Library embedders can also clone [`HealthHandle`](../src/health/handle.rs) from | ||
| `BrainstemDaemon::health()` and call `snapshot()` / `try_snapshot()` without | ||
| waiting on the tick loop's backend or `SpikingNetwork::step`. Control probes | ||
| use `try_snapshot()` so they never wait on an in-flight `apply`. | ||
|
|
||
| ## Transition table | ||
|
|
||
| | From | Event | To | live | ready | Notes | | ||
| |---|---|---|---|---|---| | ||
| | (unstarted) | `ProcessStarted` | `starting` | true | false | Construction. Live does not imply ready. | | ||
| | (unstarted) | init/checkpoint success or failure | (unstarted) | false | false | Ignored until `ProcessStarted`; the fatal transition below applies only after `ProcessStarted`. | | ||
| | `starting` | `InitializationCompleted` | `loading_checkpoint` | true | false | `initialize()` succeeded. Checkpoint restore is a separate gate. | | ||
| | `starting` | `InitializationFailed` | `fatal` | true | false | Sticky. Detail is JSON-only, never a metric label. | | ||
| | `loading_checkpoint` | `CheckpointValidated` | `running` | true | true | Ready only after this gate. Live identity is sidecar `model_id` plus SHA-256. | | ||
| | `loading_checkpoint` | `CheckpointRejected` | `fatal` | true | false | Sticky. | | ||
| | `running` | clock ≥ `stale_after` without ingress | `degraded` | true | true | Reason `stale_input`. Ready stays true. | | ||
| | `degraded` (stale) | `IngressObserved` | `running` (if no other reasons) | true | true | Ticks without ingress do **not** clear stale. Empty stub packets do not count. | | ||
| | `running` | queue fill ≥ `overload_high` | `degraded` | true | true | Reason `overload`. Fill is the aggregate of the four bounded ingress classes. | | ||
| | `degraded` (overload) | fill ≤ `overload_low` | `running` (if no other reasons) | true | true | Hysteresis: mid-band does not recover. | | ||
| | `running` / `degraded` | `BeginDrain` | `draining` | true | false | SIGTERM/SIGINT. Does not return to ready. | | ||
| | any started non-fatal | `Fatal` / init or checkpoint failure | `fatal` | true | false | Subsequent validate/tick/drain cannot restore ready. Unstarted init/checkpoint failures stay ignored. | | ||
|
|
||
| After `BeginDrain`, `BrainstemDaemon::run` stops the control listener. External | ||
| `/readyz` probes may get connection refused rather than `503`. In-process | ||
| `HealthHandle::snapshot()` still reports `phase: draining`. There is no probe | ||
| grace period. If all 32 in-flight control slots are busy, up to 4 extra | ||
| connections get a short `503` (`busy`); further accepts are closed immediately. | ||
| The same `503` is used when a snapshot read would block on an in-flight `apply`. | ||
|
|
||
| Recoverable reasons (`stale_input`, `overload`) are independent: clearing one | ||
| leaves the other. `capacity == 0` means “no queue instrumented” and never | ||
| counts as overload. After LIM-1216 the tick loop reports the sum of the four | ||
| class depths and capacities. | ||
|
|
||
| Fatal and draining are sticky for **this process**. A new process starts in | ||
| `starting` again. | ||
|
|
||
| ## Checkpoint identity | ||
|
|
||
| Live mode copies [`ModelProvenance::model_id`](../src/checkpoint/mod.rs) and | ||
| the sidecar SHA-256 into `checkpoint`. Simulation mode uses | ||
| `id = "simulation/blank"` and `digest: null`. | ||
|
|
||
| ## Example snapshots | ||
|
|
||
| Healthy (ready to consume events) after a live sidecar restore: | ||
|
|
||
| ```json | ||
| { | ||
| "live": true, | ||
| "ready": true, | ||
| "phase": "running", | ||
| "reasons": [], | ||
| "last_successful_tick_ms": 0, | ||
| "tick_age_ms": 0, | ||
| "checkpoint": { "id": "spikenaut-snn:soma16", "digest": "abc123" }, | ||
| "input_freshness": { "age_ms": 0, "stale": false }, | ||
| "queue_pressure": { "depth": 0, "capacity": 216, "ratio": 0.0, "overloaded": false }, | ||
| "fatal": null, | ||
| "observed_at_ms": 0 | ||
| } | ||
| ``` | ||
|
|
||
| Degraded (still ready; supervisors should not bounce the process): | ||
|
|
||
| ```json | ||
| { | ||
| "live": true, | ||
| "ready": true, | ||
| "phase": "degraded", | ||
| "reasons": ["stale_input", "overload"], | ||
| "last_successful_tick_ms": 0, | ||
| "tick_age_ms": 0, | ||
| "checkpoint": { "id": "spikenaut-snn:soma16", "digest": "abc123" }, | ||
| "input_freshness": { "age_ms": 100, "stale": true }, | ||
| "queue_pressure": { "depth": 95, "capacity": 100, "ratio": 0.95, "overloaded": true }, | ||
| "fatal": null, | ||
| "observed_at_ms": 100 | ||
| } | ||
| ``` | ||
|
|
||
| Fatal (never returns to ready in this process): | ||
|
|
||
| ```json | ||
| { | ||
| "live": true, | ||
| "ready": false, | ||
| "phase": "fatal", | ||
| "reasons": ["fatal"], | ||
| "last_successful_tick_ms": null, | ||
| "tick_age_ms": null, | ||
| "checkpoint": null, | ||
| "input_freshness": { "age_ms": null, "stale": false }, | ||
| "queue_pressure": { "depth": 0, "capacity": 0, "ratio": null, "overloaded": false }, | ||
| "fatal": { "code": "checkpoint_invalid", "detail": "blank weights" }, | ||
| "observed_at_ms": 0 | ||
| } | ||
| ``` | ||
|
|
||
| `fatal.detail` belongs in JSON/logs. Prometheus `/metrics` exposes | ||
| `brainstem_fatal 1` and `brainstem_phase{phase="fatal"} 1` without the detail | ||
| string. Optional gauges (`last_successful_tick_ms`, `tick_age_ms`, | ||
| `input_age_ms`) emit `NaN` when the observation is missing so supervisors do | ||
| not treat startup as a tick at time zero. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.