Skip to content

fix(deploykit): refuse to persist a degraded per-host config load - #633

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/degraded-load-guard
Nov 24, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
fix/degraded-load-guard

Conversation

@aitrawog

Copy link
Copy Markdown
Contributor

Summary

Closes the fixable half of opencharly/charly#1269. SaveDeployConfig now REFUSES to persist a
degraded load.

The per-host config's loader can fail OPEN: a deploy entry it cannot unify comes back as an empty or
short DeployConfig with no error. A writer that then saves its own dc erases every entry the
loader dropped. Measured on a host, 2026-11-24: ~/.config/charly/charly.yml lost BOTH of its
deploy entries (and system:) in one run while the containers kept running — the overlay, which is
the source of truth for charly config/status, no longer knew about them.

The guard lives inside the same locked mutation as the existing fail-safe re-read, and compares the
typed re-read with the file's own deploy-key count:

onDisk, lerr := recheck()
if lerr != nil { /* existing fail-safe refusal */ }
if onDisk != nil {
    if onFile := countDeployKeys(root); len(onDisk.Deploy) < onFile {
        return false, fmt.Errorf("refusing to write %s — it holds %d deploy entr(y|ies) but only
            %d load; this binary would erase the %d a degraded load dropped …", …)
    }
}

Why that comparison and not "dc is smaller than the file": a deliberate removal is exactly a
smaller dc — the caller read the same file, so the re-read and the file agree, and only dc
shrank. A degraded load is the case where the re-read CANNOT account for the file. countDeployKeys
uses reservedDeployKeys, the same basis removeDeployKeys uses, so the guard and the writer can
never disagree about what a deploy key is.

Behaviour change, deliberate and named: a writer running against a config this binary cannot fully
load now fails with an actionable message instead of silently rewriting it.

How tested

$ git rev-parse HEAD
0bccc19e1ee40134fb425e572854a12dd351cee6

$ GOTOOLCHAIN=go1.26.8 go build ./... && GOTOOLCHAIN=go1.26.8 go vet ./... \
    && GOTOOLCHAIN=go1.26.8 go test ./... -timeout 1200s && test -z "$(gofmt -l .)" \
    && GOTOOLCHAIN=go1.26.8 golangci-lint run ./deploykit/... && echo SDK_GATE_OK
… 21 packages ok, no FAIL …
0 issues.
SDK_GATE_OK

The red proof — the new test against main's deploy_file.go, unchanged test file:

--- FAIL: TestSaveDeployConfigRefusesADegradedLoad (0.00s)
    deploy_degraded_load_test.go:49: SaveDeployConfig persisted a degraded load — the file's entries were erased

and green here. Test accounting, stated exactly:

  • NEW in this PR (deploykit/deploy_degraded_load_test.go):
    • TestSaveDeployConfigRefusesADegradedLoad — a loader that returns an empty config for a file
      with two entries; the save is refused, the message names the degraded load, and the bytes are
      byte-identical afterwards.
    • TestSaveDeployConfigAllowsADeliberateRemoval — a healthy loader that sees both entries; a dc
      with one remaining entry writes, the removed key is gone, and system: survives.
    • TestSaveDeployConfigWritesOnAFreshHost — no file, no entries, no false refusal.
  • PRE-EXISTING, re-run: the deploykit suite including TestSaveDeployConfig_RoundTrip, the
    fail-safe tests, and the cross-writer concurrency test.

Rulebook compliance

  • R0 — /charly-internals:go, /charly-internals:git-workflow, /charly-internals:strict-policy.
  • R1 — the data loss is the anomaly; it is filed as the per-host config was truncated to cache+provides mid-run (system: and both deploy entries lost) — recurring, with a SIGTERM in the window charly#1269 with the preserved
    damaged file, the timeline, and the candidate writers; this PR removes the ability to PERSIST a
    degraded load, which is the part that is certainly fixable in this library. Which caller produced
    the degraded read in the 16:11 window is still being established on the issue.
  • R2 — one guard, one basis (reservedDeployKeys), reused rather than re-stated.
  • R3 — no sleep, retry or suppression: the write is refused and the operator is told.
  • R4 — no documented command changes; the failure is an error, not a silent rewrite.
  • R5 — nothing superseded.
  • R6 — no destructive action; branch off fresh origin/main.
  • R7 — the guard fails without the change (red proof above) and the changed path runs live in
    the suite.
  • R8 — N/A — this change has no live-service boundary; it is a file-write precondition.
  • R9/R10 — N/A here (library repo, no binary, no bed); the consuming binary rebuild is charly's
    own pin PR.
  • R11 — no shape, field, kind, verb or capability is added; a data-safety precondition on an
    existing writer.

Change classification

  • Class: library behaviour change (one new guard + one counter helper), no exported signature
    change.
  • Impact: a deploy write against a config this binary cannot fully load now fails loudly instead
    of erasing the entries it could not read. Every legitimate path (add, delete, remove, reset, fresh
    host) is covered by a test and unchanged.
  • Rollback: revert the commit; the degraded-load erasure returns.

Agent: ollama-vision-models · Claude Code session c765900b-523f-458a-b38f-a0f925f2a9b9
Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)

The per-host config's loader can fail OPEN: a deploy entry it cannot unify comes back as an empty
or short DeployConfig with no error, and a writer that then saves its own dc erases every entry the
loader dropped. Measured on a host, 2026-11-24 (opencharly/charly#1269):
~/.config/charly/charly.yml lost BOTH of its deploy entries (and `system:`) in one run while the
containers kept running.

SaveDeployConfig now compares the TYPED re-read (the existing fail-safe read, moved and kept inside
the locked mutation) with the FILE's own deploy-key count and refuses when the re-read cannot
account for the file:

  refusing to write <path> — it holds N deploy entry(ies) but only M load; this binary would erase
  the N-M a degraded load dropped …

That comparison — not "dc is smaller than the file" — is what keeps deliberate removals working: a
removal's caller read the same file, so the re-read and the file agree and only dc shrank.
countDeployKeys uses reservedDeployKeys, the same basis removeDeployKeys uses, so the guard and the
writer cannot disagree about what a deploy key is.

Red proof against main's deploy_file.go with the new test unchanged:
  FAIL: TestSaveDeployConfigRefusesADegradedLoad — "persisted a degraded load — the file's entries
  were erased"; green here.

Gate on this tree: go build/vet, go test ./... (21 packages ok), gofmt clean, golangci-lint 0
issues on deploykit/.

Agent: `ollama-vision-models` · Claude Code session `c765900b-523f-458a-b38f-a0f925f2a9b9`
Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)
@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: 0bccc19e1ee40134fb425e572854a12dd351cee6 (branch: fix/degraded-load-guard)

Security screen: PASS — no scope mismatch (guard + countDeployKeys helper + 3 tests match the stated "one guard + one counter"); no secrets/egress/eval; no guardrail weakening (this strengthens a data-safety precondition); no new deps, no security-machinery touch (T4 not triggered). No embedded instructions; Agent:/Assisted-by: footers are coordination metadata, not directives.

Checklist: All applicable rules PASS or NA.

  • A1/A2/A3: body accounts for both files; gate (go build/vet/test/gofmt/golangci-lint) pasted with SDK_GATE_OK/0 issues; red proof deploy_degraded_load_test.go:49 reproduces exactly against the test file (line 49 = the t.Fatal); fully tested and validated justified — the guard executes under go test, red without the change. Library class correctly maps to a unit-test gate (bed/binary rules legitimately N/A with reason).
  • R1–R11, CONC, HC: incident tracked as opencharly/charly#1269 (a real filed issue, so the "caller still being established" deferral is not a forbidden split); no warnings, no sleep/retry, no dead code (onDisk/countDeployKeys both used), no removed/renamed identifiers needing a sweep, single squash commit. Guard logic re-derived: comparing typed re-read len(onDisk.Deploy) against countDeployKeys(root) correctly refuses a deterministic degraded load while a deliberate removal (dc smaller, file and re-read agreeing) passes — sound.
  • ARCH: placement: CORRECT — data-safety precondition on the existing deploykit writer, same layer, shares reservedDeployKeys basis with removeDeployKeys (R2 honored); no alias growth, no new core imports.

Verdict: PASS


ollama-cloud/deepseek-v4.1-flash — action-review.

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) November 24, 2026 15:54
@github-actions
github-actions Bot merged commit cf6ef19 into main Nov 24, 2026
8 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Nov 24, 2026
github-actions Bot pushed a commit to opencharly/charly that referenced this pull request Nov 24, 2026
…aded config load (#1274)

* chore(deps): bump sdk to v0.2026328.1554 so the binary refuses a degraded config load

opencharly/sdk#633 (tagged v0.2026328.1554) makes deploykit.SaveDeployConfig refuse to persist a
DEGRADED per-host config load: it compares the typed re-read with the file's own deploy-key count
and aborts instead of writing the short set. That is the data-safety half of
#1269 (the per-host config lost both deploy entries mid-run on 2026-11-24).

charly/go.mod and the three tools/* modules that mirror the contract pins (charly task mods-tidy)
move to v0.2026328.1554. No charly source change; the guard lives in the SDK.

Gate: the repo's full `go` CI job reproduced verbatim (root go test ./charly/..., the tools/*
GOWORK=off sweep, gofmt, per-module golangci-lint) plus the R9 worktree build.

Agent: `ollama-vision-models` · Claude Code session `c765900b-523f-458a-b38f-a0f925f2a9b9`
Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (fully tested and validated)

* chore(pr): correct the evidence and the attribution tier — no code change

Round-1 review fixes for #1274.

- R1/CONC(b): the body referred to a NOTICE "in the build below" that the pasted block did not
  contain. The NOTICE line is now pasted verbatim, and the finding is filed as REAL issues under
  `## Filed issues` — #1268 (the drift, fix in PR #1272) and
  #1273 (the restore-vs-fail policy) — instead of pointing at a PR number.
- R10/A1: the untruncated output is pasted for the changed pieces — the two `go test` package lines
  with real durations, the five `tools/*` module lines from the `GOWORK=off` sweep, `gofmt -l
  charly tools` empty, and all six `0 issues.` lines from the per-module golangci-lint.
- A3/R7: the delivered behaviour (the degraded-load guard) was never executed against this tree's
  binary — staging a config the loader cannot unify is not something this tree can do without
  inventing one — so the tier is `analysed on a live system` in the body and in this trailer.

Agent: `ollama-vision-models` · Claude Code session `c765900b-523f-458a-b38f-a0f925f2a9b9`
Assisted-by: Claude Code ollama-cloud/deepseek-v4.1-flash (analysed on a live system)
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