Skip to content

feat(state): tolerate unknown observed-state fields on rollback - #185

Merged
kyle-sexton merged 1 commit into
mainfrom
feat/observed-forward-tolerant-decode
Jul 31, 2026
Merged

kyle-sexton merged 1 commit into
mainfrom
feat/observed-forward-tolerant-decode

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

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.

🤖 Generated with Claude Code

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 carries whatever
the newer release added. With DisallowUnknownFields on that path, every
additive field was a rollback break: quarantine, a forced capacity-zero
recovery pass, and a restarted drain clock.

The observed-state reader now ignores unknown keys, top-level and nested,
within schemaVersion 1. schemaVersion stays the deliberate compatibility
gate for shapes an older release must not trust, the single-JSON-value
trailer check still rejects concatenated writes, and operator-authored
desired.json keeps strict decoding so a typo fails loudly.

Co-Authored-By: Claude Fable 5 <[email protected]>
@kyle-sexton
kyle-sexton merged commit 85d7787 into main Jul 31, 2026
1 check passed
@kyle-sexton
kyle-sexton deleted the feat/observed-forward-tolerant-decode branch July 31, 2026 13:06
kyle-sexton added a commit that referenced this pull request Jul 31, 2026
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 added a commit that referenced this pull request Jul 31, 2026
> 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.

- #185 — the forward-tolerance change this PR merges on top of; it
retired the
  rollback exposure this PR was parked on.
- #102 — the parent incident. Its drain-stall watchdog and every policy
  question inside it stay out of scope; the drain-clock interaction that
coupled this field's rollback behavior to that watchdog is defused by
#185
  for additive fields.
- `feat/170-quiesce-reason` — the earlier lane's unreviewed snapshot
this
  supersedes; safe to delete once this merges.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<https://claude.ai/code/session_01RhS3T7ShwJgKTrvk2Mvd3C>

Co-authored-by: Claude Fable 5 <[email protected]>
kyle-sexton added a commit that referenced this pull request Sep 25, 2026
Repo-wide /code-tidying:dissolve-comments pass (strict posture, 2-line
budget for kept comments). Every edited file is proven comment-only:
Go files by a go/scanner token-stream comparison, shell and PowerShell
by the skill's change-shape proof. No code, no renames, directive counts
unchanged. Exported GoDoc, build tags, nolint and spellchecker markers
untouched. Net -1265 comment lines (~-20k tokens).

Rationale removed from comments (recoverable from the cited PRs):
- Step watchdog is a coarse backstop behind HTTP/2 pings and TCP
  keepalive; an abandoned Step forces exit because Go cannot kill a
  goroutine, and the Scheduled Task restart policy reclaims stepMu.
- Retirement and registration-check budgets hold because reconciler.go
  caps those loops at MaximumConcurrentWorkers; each call spends a full
  RetryValue budget; rotation stops head-of-line starvation.
- Budget basis exists because host AvailablePhysical falls as workers
  run (vmmem); advertised capacity follows ARC.
- Strict observed.json reads turned added fields into quarantine after
  rollback; schemaVersion is the compatibility gate (#185).
- jobs.json loads accept 4x the save cap so over-cap files self-heal
  (#70); completed records fill the cap before retention (#107).
- CreateMutexW ERROR_ALREADY_EXISTS is success; the opened mutex keeps
  its creator's DACL.
- Worker hook writes to /proc/1/fd/1 so the marker lands as one atomic
  write in Docker's log pipe (#134); worker scripts avoid forks (#345).
- A held repository pin needs a reviewed drift-review entry (#223).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KAK3bULeJAvdzAb4mL5j7k
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.

1 participant