Skip to content

fix(kit): persist RemoveVmSshStanza removals while sibling stanzas exist - #371

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/ssh-stanza-prune
Oct 13, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
feat/ssh-stanza-prune

Conversation

@aitrawog

Copy link
Copy Markdown
Contributor

Summary

kit.RemoveVmSshStanza never persisted a removal while any sibling stanza remained, so
charly vm destroy (and a vm: deploy's teardown) reported Destroyed VM <name> yet left
the managed Host alias behind in ~/.config/charly/ssh_config.

Root cause. saveStanzas re-merged the caller's map into a fresh loadStanzas(path)
read. That merge is upsert-only, so the just-deleted alias was re-added from disk whenever
another stanza existed — only the single-stanza len==0 → os.Remove(frag) arm hid it.

Fix. WriteVmSshStanza and RemoveVmSshStanza now do their read-modify-write under
the fragment file lock (lockStanzas) and write the authoritative set (writeStanzasLocked,
no re-merge). The concurrency guarantee that motivated the merge (no lost alias under N
concurrent writers — the measured 16-lane check-run stalls) is preserved by loading under
the lock instead of re-merging without it.

Closes #370.

How tested

All commands run on the committed tree a7448c55cda48fc0902447ac58e150b1ac8c3c29
(git status --short empty), changed files kit/sshconfig.go + kit/sshconfig_test.go.

Reproduction before the fix (worktree at origin/main, test added, source unpatched):

$ go test ./kit/ -run TestRemoveVmSshStanzaKeepsOthers -v
--- FAIL: TestRemoveVmSshStanzaKeepsOthers (0.00s)
    sshconfig_test.go:76: removed alias charly-b still present: [charly-a charly-b charly-c]
FAIL

After the fix:

$ go test ./kit/ -run 'TestRemoveVmSshStanzaKeepsOthers|TestWriteVmSshStanzaConcurrent' -v
--- PASS: TestWriteVmSshStanzaConcurrent (1.17s)
--- PASS: TestRemoveVmSshStanzaKeepsOthers (0.00s)
PASS
ok  	github.com/opencharly/sdk/kit	1.202s

Full module gate on the committed tree:

$ go test ./...
ok  	github.com/opencharly/sdk	(cached)
ok  	github.com/opencharly/sdk/agentkit	(cached)
ok  	github.com/opencharly/sdk/buildkit	(cached)
ok  	github.com/opencharly/sdk/candywalk	(cached)
ok  	github.com/opencharly/sdk/charlylib	(cached)
ok  	github.com/opencharly/sdk/checkkit	(cached)
ok  	github.com/opencharly/sdk/deploykit	(cached)
ok  	github.com/opencharly/sdk/enginekit	(cached)
ok  	github.com/opencharly/sdk/kit	(cached)
ok  	github.com/opencharly/sdk/llmkit	(cached)
ok  	github.com/opencharly/sdk/loaderkit	(cached)
ok  	github.com/opencharly/sdk/packagekit	(cached)
ok  	github.com/opencharly/sdk/vmshared	(cached)
ok  	github.com/opencharly/sdk/workflowkit	(cached)

$ test -z "$(gofmt -l kit/)" && echo gofmt-clean
gofmt-clean
$ go vet ./kit/ ; echo vet-rc=$?
vet-rc=0
$ for arch in amd64 arm64 arm 386; do GOOS=linux GOARCH=$arch CGO_ENABLED=0 go build ./... && echo "build ok: $arch"; done
build ok: amd64
build ok: arm64
build ok: arm
build ok: 386

Live evidence that motivated the fix (host no, 2026-10-13): on a 20-stanza fragment,
charly vm destroy ubuntu-ci --disk printed Destroyed VM charly-ubuntu-ci and removed the
libvirt domain, the ~116 GiB disk and the vm:ubuntu-ci deploy entry — but
grep charly-ubuntu-ci ~/.config/charly/ssh_config still matched after the run; the fragment
mtime advanced (a rewrite happened) yet the alias survived, i.e. the removal was written and
then resurrected by the re-merge.

Rulebook compliance

  • R0 — loaded /charly-internals:git-workflow, /charly-internals:plugin, /charly-internals:go before any change.
  • R1 — root-caused the upsert-only re-merge in saveStanzas; reproduced with a failing test before touching the fix.
  • R3 — one canonical writer: writeStanzasLocked is the single authoritative fragment writer; the re-merging saveStanzas is deleted, not left beside it.
  • R4 — no workaround: fixed the mechanism in its owning repo (sdk/kit), not the caller.
  • R6 — no direct push to main; work done in the feat/ssh-stanza-prune worktree.
  • R10 — all evidence captured from the committed tree a7448c5; the changed path executes live in the regression test.
  • Landing order — sdk is the producer; consumers (plugin-vm, plugin-deploy-vm, plugin-kubevirt) adopt through a normal github.com/opencharly/sdk pin bump after this merges and tags.

Change classification

  • Change class: library bug fix — reusable mechanism (sdk/kit), no schema or wire-type change.
  • Verification gate: go build ./... + go test ./... + gofmt + go vet + the Linux cross-compile matrix (amd64/arm64/arm/386), all on the committed tree.
  • Attribution tier: fully tested and validated.

Assisted-by: OpenCode DeepSeek V4.1 Flash (fully tested and validated)

saveStanzas re-merged the caller's map into a fresh `loadStanzas` read,
so RemoveVmSshStanza's delete was re-added from disk whenever any sibling
stanza remained — only the single-stanza `len==0 → os.Remove` arm hid it.
`charly vm destroy` therefore reported success yet left the alias behind.

Do the read-modify-write UNDER the fragment file lock and write the
authoritative set (no fresh-load re-merge); the concurrency guarantee is
preserved by loading under the lock, not by re-merging without it. Adds a
removal regression test and points the concurrency test at the real API.

Refs #370
@aitrawog

Copy link
Copy Markdown
Contributor Author

Live confirmation of the fix on the real fragment this bug was found on.

Host no, the operator's ~/.config/charly/ssh_config: 20 stanzas, including the stale
charly-ubuntu-ci stanza a buggy charly vm destroy left behind. Running the fixed
kit.RemoveVmSshStanza against it (built from this branch's worktree):

before: 20 aliases
remaining=19
after: 19 aliases; charly-ubuntu-ci absent

The # opencharly:begin/# opencharly:end fence and all 19 sibling stanzas are intact —
the only diff versus the pre-run snapshot is the dropped Host charly-ubuntu-ci block.
The buggy path instead rewrote the fragment and resurrected the alias on every run (see the
body's live evidence).

Assisted-by: OpenCode DeepSeek V4.1 Flash (fully tested and validated)

@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: a7448c55cda48fc0902447ac58e150b1ac8c3c29 (branch: feat/ssh-stanza-prune)

Security screen: PASS — no secrets/egress, no guardrail or validator-spec change, no new deps; diff touches only kit/sshconfig.go + its test, matching the stated scope.
Checklist: All applicable rules PASS or NA. The fix correctly moves the read-modify-write under lockStanzas and writes the authoritative set via writeStanzasLocked (re-merge removed, no transitional path); both new behaviors ship tests that fail without the change; evidence is pasted and internally coherent; footer is the required *Assisted-by: …* line; placement in sdk/kit (multi-consumer reusable mechanism) is correct.

Verdict: PASS


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

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) October 13, 2026 08:48
@github-actions
github-actions Bot merged commit b5e1e6b into main Oct 13, 2026
6 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Oct 13, 2026
github-actions Bot pushed a commit to opencharly/plugin-vm that referenced this pull request Oct 13, 2026
* chore(deps): adopt sdk v0.2026286.849 (ssh stanza removal fix)

Bumps github.com/opencharly/sdk to the tag carrying the
RemoveVmSshStanza persistence fix (opencharly/sdk#371): with sibling
stanzas present, `charly vm destroy` now prunes the managed ssh_config
Host stanza instead of resurrecting it. spec cascades to v0.2026280.2244.

Refs opencharly/sdk#370, opencharly/sdk#371

* docs: re-freeze gate on the corrected PR body (no code change)

---------

Co-authored-by: Andreas Trawoeger <[email protected]>
github-actions Bot pushed a commit to opencharly/plugin-deploy-vm that referenced this pull request Oct 13, 2026
* chore(deps): adopt sdk v0.2026286.849 (ssh stanza removal fix)

Bumps github.com/opencharly/sdk to the tag carrying the
RemoveVmSshStanza persistence fix (opencharly/sdk#371), so the vm deploy
teardown prunes the managed ssh_config Host stanza instead of
resurrecting it while sibling stanzas remain. spec cascades to
v0.2026280.2244.

Refs opencharly/sdk#370, opencharly/sdk#371

* docs: re-freeze gate on the corrected PR body (no code change)

* docs: re-freeze gate after round RCA + filed R10 gap (no code change)

* docs: add the check-local-vm bed evidence for the R10 finding (no code change)

* docs: add the isolated deploy-del teardown proof for the R10 finding (no code change)

---------

Co-authored-by: Andreas Trawoeger <[email protected]>
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.

fix(kit): RemoveVmSshStanza never persists a removal while sibling stanzas exist

1 participant