Skip to content

feat(controller): surface the quiesce reason on observed.json - #176

Merged
kyle-sexton merged 2 commits into
mainfrom
feat/170-quiesce-reason-observed
Jul 31, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
feat/170-quiesce-reason-observed

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Jul 30, 2026 •

Copy link
Copy Markdown
Member

The rollback-readability tradeoff this PR was deliberately parked on has been
resolved: option 2 of the recorded decision
(#176 (comment))
was chosen, and #185 landed observed-state forward tolerance on main first.
This branch now rides that guarantee, so marking it ready no longer accepts
any tradeoff.

Summary

Implements #170. A controller wedged in phase: draining recorded only
drainStartedAt — when the drain began, never why — so diagnosing the incident
behind #102 meant source-diving plan.go's quiesce path. observed.json now
carries quiesceReason beside drainStartedAt, and omits the key 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. 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: 0 converges through the same
downscale branch as an automatic downscale
(TestCapacityOverrideZeroIsDataOnlyPause pins 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.json was originally not add-only with
respect to rollback readability: the observed reader set
DisallowUnknownFields, so a controller rolled back to a release predating
this 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 schemaVersion 1, so an older controller reading an
observed.json that carries quiesceReason simply does not display it — the
drain clock and the CLI surfaces are unaffected, and the
rollback-readability guarantees in docs/observability.md stay true. This PR
is genuinely add-only on top of that. Its
TestObservedRejectsATopLevelKeyItDoesNotKnow — written so that flipping to
forward-tolerant decoding is what changes its expectation — was superseded by
main's TestObservedToleratesFieldsFromANewerRelease and removed in the merge
from main.

Provenance

The plan-side implementation originated on feat/170-quiesce-reason, pushed by
an earlier lane that wound down before review. This branch is that work rebased
onto current main, independently reviewed in a fresh context, with the
compatibility 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.go and
reconciler.go fails exactly three tests, so the wiring is pinned rather than
incidentally covered:

  • TestObservedStateRecordsWhyTheControllerDrainsAndClearsItOnRecovery
  • TestObservedStateSeparatesAnOperatorDrainFromAConvergenceQuiesce
  • TestPollCheckpointCarriesTheQuiesceReason

On the wire: TestObservedQuiesceReasonIsOnTheWireOnlyWhileDraining asserts
the key is present under exactly that name while draining and absent — not
empty, not "none" — when not, with a round trip proving the persisted key
matches the struct tag.

Compatibility: covered on main by
TestObservedToleratesFieldsFromANewerRelease and
TestObservedStillRejectsIncompatibleFiles (#185).

Not run locally: the race detector (-race requires cgo, unavailable on this
host). CI's go-quality lane covers it.

Related

Fixes #170.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RhS3T7ShwJgKTrvk2Mvd3C

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
@kyle-sexton

Copy link
Copy Markdown
Member Author

Re-verified this branch on current main (294652c, one commit ahead, zero behind). The code is finished; only the owner decision is outstanding — so this stays a draft.

Re-ran the full test plan on Windows rather than trusting the body:

Gate Result
go build ./... clean
go vet ./... clean
gofmt -l ./internal/ no output
golangci-lint run --config .golangci.yml 0 issues
go test ./... all packages ok, 0 failures

Also re-verified the three claims the decision rests on, in the code rather than relaying them:

  • internal/state/fs/store.go:198 — decoder.DisallowUnknownFields() is set, so an older binary cannot decode an observed.json carrying quiesceReason.
  • internal/state/fs/store.go:294-296 — validateObserved rejects anything but SchemaVersion == 1, so a schemaVersion bump is not an escape hatch; it fails the same way with a different message.
  • internal/app/app.go:293 — observed, _ := a.dependencies.Store.LoadObserved(ctx) discards the decode error and proceeds with a zero-valued state, so the blast radius reaches the CLI surfaces, not just the self-healing reconciler pass.

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 needs-human / status: needs-decision so the autonomous lane stops re-deriving the wall. Accepting a durable, first-of-its-kind giveaway of a property the repo explicitly guarantees elsewhere (docs/worker-image.md:219-220, docs/observability.md:142-144) is not a call an autonomous merge lane should make on the owner's behalf.

The decision, stated in full so it needs no back-reference:

  1. Accept the tradeoff — mark ready and merge as-is. observed.json gains quiesceReason while draining. Cost: a controller rolled back to a pre-this-field release quarantines the file, restarts the drain clock (the same clock Controller wedges in 'draining' with desired mode=enabled: advertised capacity 0, one idle worker, queue starved until restart #102's watchdog would time against), and the four app.go load sites degrade or silently read zero values until the controller rewrites the file. Exposure is real but bounded, and the documented rollback order drains before restoring the prior pair, so the key is present precisely then.
  2. Make observed-state decoding forward-tolerant first, in its own PR, then merge this one on top. Removes the rollback exposure; costs a change to the state-file safety model that deserves its own review. TestObservedRejectsATopLevelKeyItDoesNotKnow is written so flipping to forward-tolerant decoding is what changes its expectation.
  3. Surface the reason off observed.json entirely — keeps the persisted artifact untouched, but gives up the "one file-read instead of a source dive" outcome controller: surface the quiesce reason on observed.json (quiesceReason) #170 asked for.

No unresolved review threads and no failing checks are blocking; the branch is merge-ready the moment option 1 is chosen.

kyle-sexton added a commit that referenced this pull request Jul 31, 2026
## 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]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review July 31, 2026 13:10
@kyle-sexton
kyle-sexton merged commit 8788b75 into main Jul 31, 2026
1 check passed
@kyle-sexton
kyle-sexton deleted the feat/170-quiesce-reason-observed branch July 31, 2026 13:12

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

controller: surface the quiesce reason on observed.json (quiesceReason)

1 participant