Repository navigation
feat(controller): surface the quiesce reason on observed.json - #176
Conversation
A controller wedged in `phase: draining` recorded only when the drain started, never why, so diagnosing #102's incident meant source-diving `plan.go`'s quiesce path. Observed state now carries `quiesceReason` alongside `drainStartedAt`, omitted entirely when the controller is not draining. The reason replaces the plan's internal quiescing boolean rather than sitting beside it, so phase selection reads the same value operators do and the reported reason cannot disagree with the decision that produced it. Values name the branch the plan took, not the intent behind it: an operator setting `temporaryCapacityOverride` to zero converges through the same downscale branch as an automatic downscale, so a value implying operator-versus-convergence would misreport that case. This does add a top-level observed-state key, and the observed reader sets DisallowUnknownFields, so a controller rolled back to a release predating the field cannot decode a file carrying it — the reconciler quarantines it for one forced capacity-zero pass, the CLI status and doctor surfaces that share the loader degrade until it is rewritten, and quarantine discards `drainStartedAt`, restarting the drain clock. The documented rollback order drains before restoring, which is exactly when the key is present. That cost is documented and pinned by a test rather than left to review. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RhS3T7ShwJgKTrvk2Mvd3C
|
Re-verified this branch on current Re-ran the full test plan on Windows rather than trusting the body:
Also re-verified the three claims the decision rests on, in the code rather than relaying them:
Not marking this ready for review. The body states that marking it ready is the act of accepting the rollback-readability tradeoff, and #170's own addendum asks for this to be re-gated to The decision, stated in full so it needs no back-reference:
No unresolved review threads and no failing checks are blocking; the branch is merge-ready the moment option 1 is chosen. |
## Summary Makes observed-state decoding forward-tolerant, engineering away the rollback-compatibility hazard #176 was deliberately parked on (recorded as option 2 of the decision in <#176 (comment)>). `observed.json` is controller-authored and, after a rollback, is read by an *older* release than the one that wrote it — the documented rollback order drains before restoring the prior pair, so the file on disk at that moment carries whatever the newer release added. With `DisallowUnknownFields` on that path, every additive observed-state field was a rollback break: the reconciler quarantined the file, took a forced capacity-zero recovery pass, and — because quarantine zeroes `previous` — restarted the drain clock #102's watchdog would time against. The four CLI load sites in `internal/app/app.go` that share the loader failed or read zero values until the controller rewrote the file. The observed-state reader now ignores JSON keys it does not know, top-level and nested, within `schemaVersion` 1. Scope and what deliberately does *not* change: - **`desired.json` stays strict.** It is operator-intent, the one state file a human may hand-edit during an incident; a typo there should fail loudly, not silently drop a field. `TestStoreRejectsUnknownFieldsAndMultipleValues` continues to pin that. - **`schemaVersion` stays the compatibility gate.** Additive fields keep version 1 and are tolerated; a shape an older release genuinely cannot be trusted to read bumps the version, and an unsupported version is still rejected — there, quarantine is the intended outcome. - **The trailer check stays.** A file carrying more than one JSON value is still rejected, so tolerance does not weaken corruption detection for concatenated writes. - **`restart-completed.json` stays strict.** It is controller-authored too, but it is a short-lived receipt consumed across a single restart, has never gained a field, and widening its decode posture deserves its own analysis if it ever does. `docs/observability.md` gains an "Observed-state rollback readability" section stating the guarantee, which holds for rollbacks to any release carrying this change. The existing "rollback-readable observed-state shape" language in that document stays true. ## Test plan Full suite green on Windows: `go build ./...`, `go vet ./...`, `gofmt -l ./internal/` (clean), `golangci-lint run --config .golangci.yml` (0 issues), `go test ./...` (all packages ok). markdownlint clean on the touched doc. Not run locally: the race detector (`-race` requires cgo, unavailable on this host); CI's go-quality lane covers it. New pins: - `TestObservedToleratesFieldsFromANewerRelease` — saves a draining observed state, injects an unknown top-level key and an unknown nested pool key, and asserts the load succeeds with phase, `drainStartedAt`, and the pool entry intact — the drain clock surviving unknown keys is the point. - `TestObservedStillRejectsIncompatibleFiles` — asserts a `schemaVersion` bump and a trailing JSON value are still rejected, naming the failure. ## Related No linked issue — this implements option 2 of the decision recorded on #176; per repo process this lane does not file issues. - #176 — the quiesce-reason PR parked on this hazard; it merges on top of this change, and its `TestObservedRejectsATopLevelKeyItDoesNotKnow` is the strict pin this PR's tolerance pin supersedes. - #170 — the issue #176 implements. - #102 — the parent incident whose drain-stall watchdog makes the restarted drain clock consequential. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Fable 5 <[email protected]>
Beyond the textual conflicts, #185 (merged on main) made observed-state decoding forward-tolerant, which retires the rollback cost this branch documented and pinned. Resolution: TestObservedRejectsATopLevelKeyItDoesNotKnow is removed as superseded by main's TestObservedToleratesFieldsFromANewerRelease; the "Rollback cost of this field" doc subsection now points at the guarantee instead of stating a cost; and the wire test's comment no longer claims the observed reader rejects unknown fields. Co-Authored-By: Claude Fable 5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fb7e57f143
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| observed := model.ObservedState{ | ||
| SchemaVersion: 1, Phase: phase, HeartbeatAt: time.Now().UTC(), DrainStartedAt: drainStartedAt, Version: r.version, | ||
| SchemaVersion: 1, Phase: phase, HeartbeatAt: time.Now().UTC(), DrainStartedAt: drainStartedAt, | ||
| QuiesceReason: postPlan.QuiesceReason, Version: r.version, |
There was a problem hiding this comment.
Preserve the drain clock for degraded quiesces
When a plan is simultaneously quiescing and degraded—for example, excess idle workers while a scale-set listener is unavailable—BuildPlan deliberately retains a nonempty QuiesceReason under PhaseDegraded, but the drain clock above is populated only for PhaseDraining. This writes quiesceReason without drainStartedAt; repeated degraded reconciles therefore lose the original drain start, and once the problem clears the clock restarts, delaying drain-warning. The checkpoint writer repeats the same phase-based condition, so both paths should preserve the clock whenever the plan has a quiesce reason.
Useful? React with 👍 / 👎.
Summary
Implements #170. A controller wedged in
phase: drainingrecorded onlydrainStartedAt— when the drain began, never why — so diagnosing the incidentbehind #102 meant source-diving
plan.go's quiesce path.observed.jsonnowcarries
quiesceReasonbesidedrainStartedAt, and omits the key entirelywhen the controller is not draining.
The reason replaces the plan's internal
quiescingboolean rather thansitting beside it, so phase selection reads the same value operators do. That
is what keeps the reported reason from ever disagreeing with the decision that
produced it. A degraded plan still reports the reason it computed — a
controller that is both wedged and degraded is exactly when the reason is
wanted.
Values name the branch the plan took, not the intent behind it:
operator-disabled, gaming-mode with active work, gaming-mode host teardown,
excess workers that cannot be advertised as burst capacity, and an exhausted
advertisement budget. This resolves an objection raised on the issue: an
operator setting
temporaryCapacityOverride: 0converges through the samedownscale branch as an automatic downscale
(
TestCapacityOverrideZeroIsDataOnlyPausepins that), so a value implying"operator versus convergence" would misreport it. Naming the mechanism keeps
that test true while still letting a reader separate an operator drain from a
convergence quiesce, which is what the issue asked for.
The rollback decision, resolved
Adding a top-level key to
observed.jsonwas originally not add-only withrespect to rollback readability: the observed reader set
DisallowUnknownFields, so a controller rolled back to a release predatingthis field would have quarantined the file, taken a forced capacity-zero
recovery pass, and restarted the drain clock #102's watchdog would time
against. That was an owner decision, recorded on this PR and kept out of the
autonomous merge lane by the draft state.
#185 resolved it the durable way: observed-state decoding is now
forward-tolerant within
schemaVersion1, so an older controller reading anobserved.jsonthat carriesquiesceReasonsimply does not display it — thedrain clock and the CLI surfaces are unaffected, and the
rollback-readability guarantees in
docs/observability.mdstay true. This PRis genuinely add-only on top of that. Its
TestObservedRejectsATopLevelKeyItDoesNotKnow— written so that flipping toforward-tolerant decoding is what changes its expectation — was superseded by
main's
TestObservedToleratesFieldsFromANewerReleaseand removed in the mergefrom main.
Provenance
The plan-side implementation originated on
feat/170-quiesce-reason, pushed byan earlier lane that wound down before review. This branch is that work rebased
onto current
main, independently reviewed in a fresh context, with thecompatibility analysis and the documentation of the (since-resolved) tradeoff
added here.
Test plan
Full suite green on Windows after merging current
main(post-#185):go build ./...,go vet ./...,gofmt -l ./internal/(clean),golangci-lint run --config .golangci.yml(0 issues),go test ./...(all packages ok, 0 failures), markdownlint clean on the touched doc.
Reverting the observed-state carry-through in
poll_cadence.goandreconciler.gofails exactly three tests, so the wiring is pinned rather thanincidentally covered:
TestObservedStateRecordsWhyTheControllerDrainsAndClearsItOnRecoveryTestObservedStateSeparatesAnOperatorDrainFromAConvergenceQuiesceTestPollCheckpointCarriesTheQuiesceReasonOn the wire:
TestObservedQuiesceReasonIsOnTheWireOnlyWhileDrainingassertsthe key is present under exactly that name while draining and absent — not
empty, not
"none"— when not, with a round trip proving the persisted keymatches the struct tag.
Compatibility: covered on
mainbyTestObservedToleratesFieldsFromANewerReleaseandTestObservedStillRejectsIncompatibleFiles(#185).Not run locally: the race detector (
-racerequires cgo, unavailable on thishost). CI's
go-qualitylane covers it.Related
Fixes #170.
rollback exposure this PR was parked on.
question inside it stay out of scope; the drain-clock interaction that
coupled this field's rollback behavior to that watchdog is defused by feat(state): tolerate unknown observed-state fields on rollback #185
for additive fields.
feat/170-quiesce-reason— the earlier lane's unreviewed snapshot thissupersedes; safe to delete once this merges.
🤖 Generated with Claude Code
https://claude.ai/code/session_01RhS3T7ShwJgKTrvk2Mvd3C