Skip to content

fix(pluginsgen): split the drift gate by determinism and guard the build's rewrite - #795

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/refs-drift-guard
Oct 5, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
feat/refs-drift-guard

Conversation

@aitrawog

@aitrawog aitrawog commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Summary

charly's main went RED at 2026-10-04T21:25:33Z and was turned green again at 02:16:40Z by #794, which regenerated charly/plugins_refs_generated.go and committed it. This PR fixes the cause that makes that manual regeneration necessary.

$ gh run list --repo opencharly/charly --workflow ci --branch main --limit 3
37254763088  success  4e095391  2026-10-05T02:16:40Z     <-- green again (#794 regenerated the file)
37236037806  failure  9cd960ea  2026-10-04T21:25:33Z     <-- the red
37221537381  success  ae1b7977  2026-10-04T17:42:31Z
$ gh run view 37236037806 --log-failed
--- FAIL: TestPluginsGenReproducible (130.51s)
    main_test.go:41: charly/plugins_refs_generated.go is stale — re-run `scripts/bootstrap-charly.sh` (pluginsgen) and commit it.
FAIL	github.com/opencharly/charly/charly/internal/pluginsgen	130.528s

opencharly/charly#794 did exactly what the failure message prescribed — re-ran the generator and committed the result (+7/-0, the seven verb: providers from plugin-pipeline). It says so itself: "This PR regenerates it — one file, no source logic changed." It closes opencharly/charly#793, the symptom issue. This PR is the complementary one, and it is opencharly/charly#792, the cause: the gate that demanded that regeneration asserts a contract that cannot hold, so the red returns on the next corpus provider addition.

Why the red returns

TestPluginsGenReproducible byte-compared all three generated files against a live regeneration. Two of them — charly/plugins_generated.go and go.work — are derived from tracked inputs (charly.yml's compiled_plugins: + the go.mod pins read at their immutable tags; the go.mod go directive), so byte-equality is a sound gate there, and it is unchanged by this PR.

The third is not. charly/plugins_refs_generated.go is a projection of the corpus's default branches: collectWordRefs calls refs.DownloadRepo(repo, "HEAD") (charly/internal/pluginsgen/main.go:163) over the 112-repo corpus. Byte-equality between a committed projection and a live re-fetch of a moving branch cannot hold for more than a moment.

One factual correction to #794's write-up, since the fix depends on it: #794 says the generator "derives the word→provider map from every plugin repo's own plugin: block at its newest tag". That is true of the compiled-in wiring — refs.DownloadRepo(repoPath, "candy/"+name+"/"+version), line 246 — but not of the word→ref index, which reads HEAD (line 163). The distinction is the whole point: a tag can be pinned and byte-compared; a default branch cannot. Measured: plugin-pipeline#32 merged 2026-10-04T21:04:52Z; the red landed 21 minutes later; the committed index named zero of its seven new words.

The change

1. Split the gate by determinism — charly/internal/pluginsgen/main_test.go

  • the two deterministic files keep byte-equality, strength unchanged;
  • the upstream-derived index moves to a new TestPluginsRefsIndexSound, on the invariant that is true of a moving projection: every word the committed index names must still be served by that same ref.
    • a word the corpus no longer serves, or serves from a different ref ⇒ the index is FALSE — it sends a reader to a plugin that does not provide the word ⇒ t.Errorf;
    • a word the corpus serves that the index does not name ⇒ an upstream ADDITION: incomplete, not wrong, and nothing in this repository can complete it except regenerating ⇒ t.Logf advisory, never red.

The committed side is parsed as source (an AST walk for pluginProviderRefs) rather than re-derived — re-deriving it would compare a value to itself.

The limit, stated rather than papered over: a hand-edit that deletes a row is indistinguishable from an upstream addition when all you have is the committed file — both leave the word absent from the committed index and present in the live one — so a deletion lands on the advisory path too. Telling them apart needs the corpus commit recorded beside each entry; that is the pinned-corpus option, a separate decision, not taken here. What this gate catches reliably is a false index: a repointed provider, and a provider the corpus has dropped. Both were verified to fail by tampering the committed file (below).

The corpus set is built in one place — the new corpusRepoList in main.go — so the generator and the soundness gate cannot disagree about what "the corpus" means (extracted on its second use, R3).

2. Guard the build's rewrite of tracked files — scripts/check-generated-clean.sh + scripts/bootstrap-charly.sh

pluginsgen and workspace-mode Go both rewrite tracked files. #794 is what that looks like from the human side: a build-run left a tracked file modified, and the remedy was a review-and-commit by hand. That remedy is forbidden in a detached umbrella submodule checkout (rule 1 / rule 5), which is where every session's charly/ build actually happens. So the guard classifies by what each file is derived from:

class files disposition
inconsistent go.work, go.work.sum, charly/plugins_generated.go derived from tracked inputs ⇒ a diff is this checkout's own inconsistency ⇒ fail, for review and commit
upstream charly/plugins_refs_generated.go derived from a source this checkout does not pin ⇒ nothing here is wrong; named and restored, so the tree stays clean at its gitlink

bootstrap-charly.sh calls it before promoting bin/.charly.next, so a guard failure can never leave a half-written binary in place. Exit 2 (no git lineage — a source export) is reported and not treated as a build failure.

The class list lives in one place — the script, readable with --list — and charly/generated_clean_script_test.go reads it back rather than restating it, so a dropped entry fails a test.

Closes #792.

How tested

Everything below was re-run from the final committed tree (90ea4779, rebased onto origin/main = 4e095391, worktree clean), not from an edited state and not from the pre-rebase head (R10).

The core Go gate — gofmt, go vet, and the full go test ./charly/...:

$ gofmt -l charly tools
GOFMT_CLEAN_EXIT=0

$ go vet ./charly/...
VET_EXIT=0

$ go test ./charly/...
ok  	github.com/opencharly/charly/charly	147.375s
ok  	github.com/opencharly/charly/charly/internal/pluginsgen	108.176s
TEST_EXIT=0

The two pluginsgen gates, live against the corpus. After #794 refreshed the committed index, the advisory is now empty — the gate reports the index sound, which is the positive case, not merely the absence of a failure:

$ go test ./charly/internal/pluginsgen/ -run 'TestPluginsGenReproducible|TestPluginsRefsIndexSound' -v
=== RUN   TestPluginsGenReproducible
--- PASS: TestPluginsGenReproducible (65.84s)
=== RUN   TestPluginsRefsIndexSound
--- PASS: TestPluginsRefsIndexSound (41.00s)
PASS
ok  	github.com/opencharly/charly/charly/internal/pluginsgen	106.854s

TestPluginsRefsIndexSound emits no advisory here: #794's regeneration brought the committed index level with the corpus, so there is nothing to report. The advisory path is therefore exercised too — the same gate printed the seven verb: words on the pre-#794 tree, which is the evidence that the advisory reports real upstream additions rather than sitting inert.

The guard's own tests — hermetic, no network, -count=1 so the result is executed rather than replayed from cache:

$ go test ./charly/ -run TestGeneratedCleanScript -v -count=1
--- PASS: TestGeneratedCleanScriptClassifiesEveryRewrittenFile (0.02s)
--- PASS: TestGeneratedCleanScriptFailsOnInconsistentDrift (0.06s)
--- PASS: TestGeneratedCleanScriptRestoresUpstreamDriftAndSucceeds (0.03s)
--- PASS: TestGeneratedCleanScriptHandlesBothClassesInOneRun (0.03s)
--- PASS: TestGeneratedCleanScriptReportsNoLineageOutsideGit (0.00s)
PASS
ok  	github.com/opencharly/charly/charly	2.458s

The changed build path, run live. This is #794's symptom reproduced on the fixed tree and resolved by the guard: the same build, the same rewritten tracked file, and now a named NOTICE plus a restore instead of a dirty tree:

$ bash scripts/bootstrap-charly.sh
bootstrap-charly: regenerating compiled-in plugin wiring
bootstrap-charly: building bin/charly
check-generated-clean: NOTICE — charly/plugins_refs_generated.go differs because it was indexed from a source this checkout does not pin
check-generated-clean:   (a corpus plugin's default branch, or a --dev-plugin local checkout); restoring the tracked file.
bootstrap-charly: built ./bin/charly (2026.278.0202)
BOOTSTRAP_EXIT=0

$ git status --porcelain
                                    # empty — the guard restored the tracked file
$ git diff --quiet -- charly/plugins_refs_generated.go && echo "no diff — clean at its gitlink"
no diff — clean at its gitlink
$ ./bin/charly version
2026.278.0202

R7 — the new gate is shown to FAIL, not merely to pass. -count=1 on every run so no cache can mask a result; each tamper was applied to the committed charly/plugins_refs_generated.go and reverted afterwards.

Repoint one committed word at the wrong provider — the index is false:

$ go test ./charly/internal/pluginsgen/ -run TestPluginsRefsIndexSound -count=1
--- FAIL: TestPluginsRefsIndexSound (42.33s)
    main_test.go:129: the committed index points 1 word(s) at the wrong provider:
FAIL	github.com/opencharly/charly/charly/internal/pluginsgen	42.340s

Name a word no corpus plugin serves (what a corpus-side provider removal produces):

$ go test ./charly/internal/pluginsgen/ -run TestPluginsRefsIndexSound -count=1
--- FAIL: TestPluginsRefsIndexSound (42.77s)
    main_test.go:125: the committed index names 1 word(s) no corpus plugin serves any more — the index is FALSE; regenerate and commit it:
FAIL	github.com/opencharly/charly/charly/internal/pluginsgen	42.779s

And the delete-a-row case, run for the record, to document the limit above rather than assert a capability that is not there — it passes on the advisory path:

$ go test ./charly/internal/pluginsgen/ -run TestPluginsRefsIndexSound -count=1
ok  	github.com/opencharly/charly/charly/internal/pluginsgen	42.629s

R7 — the guard's tests cannot pass vacuously. With scripts/check-generated-clean.sh moved away, every one of them fails naming the missing guard (they deliberately t.Fatalf rather than t.Skip, which would make them unfalsifiable):

$ mv scripts/check-generated-clean.sh /tmp/pt/guard-away.sh
$ go test ./charly/ -run TestGeneratedCleanScript -count=1
--- FAIL: TestGeneratedCleanScriptClassifiesEveryRewrittenFile (0.02s)
    generated_clean_script_test.go:120: scripts/check-generated-clean.sh is missing (… no such file or directory) — it is the guard that keeps a build from leaving the tracked generated files dirty, and this test cannot pass without it
--- FAIL: TestGeneratedCleanScriptFailsOnInconsistentDrift (0.01s)
--- FAIL: TestGeneratedCleanScriptRestoresUpstreamDriftAndSucceeds (0.01s)

Nothing generated changed. The generator refactor is behaviour-preserving, and this is the proof rather than a claim — this commit touches no generated artifact at all, so the binary's provider resolution is byte-for-byte what main ships today:

$ git diff --stat origin/main...HEAD -- charly/plugins_generated.go charly/plugins_refs_generated.go go.work go.work.sum
                                    # empty: all three generated artifacts are byte-identical

CI. charly/.github/workflows/ci.yml runs go test ./charly/..., which is where the red appeared; this PR is what makes that run hold green instead of going red again on the next corpus provider addition. release-binary.yml builds with a plain go build and no bootstrap, which is why the committed plugins_refs_generated.go must stay in the tree — another reason the guard restores rather than deletes.

Rulebook compliance

  • R1 (RCA): the ci failure was root-caused to TestPluginsGenReproducible asserting byte-equality over a moving upstream — measured, with the merge→red interval, the exact source line, and the seven words named. No "pre-existing" or "out of scope" classification is used for it.
  • R2 (whole cutover): the symptom (#794, another session's) and the cause (this PR) are both addressed; the superseded assertion is removed here rather than left beside the new one.
  • R3 (no duplication): corpusRepoList is the one definition of the corpus set, shared by the generator and the soundness gate; the guard's class list is the one definition of what the build rewrites, read back by its test with --list.
  • R4 (no workaround): the gate is fixed at its cause, not silenced; the guard acts on the build path rather than telling a human to commit inside a detached submodule. No sleeps, retries, or hook bypass.
  • R5 (delete legacy completely): the superseded byte-equality assertion on plugins_refs_generated.go is removed in this same commit.
  • R6 (git safety): PR-only, no force-push (the rebase was onto a newer main before anything was published, so no published ref moved), no hook bypass, no direct push to main.
  • R7 (prove behaviour; a test that cannot fail is invalid): both failure branches of the new gate shown failing on tampered input with -count=1; the guard's tests shown failing without the guard; both changed paths executed live.
  • R9 (binary equals source): the binary was produced by scripts/bootstrap-charly.sh from this tree, and ./bin/charly version reports 2026.278.0202 — the HEAD commit's CalVer.
  • R10 (fresh proof from the final tree): all evidence above is from 90ea4779 with a clean worktree. R10 target set: ∅ — R10 scopes the fresh-rebuild obligation to runtime changes, and this is build tooling plus tests: no runtime path changes, and the generated artifacts (hence the compiled-in wiring the binary resolves providers through) are byte-identical, so no explicit disposable: true target is affected. No bed was run, and none is claimed.
  • Umbrella rule 10 (body before push): this body was written before the push, with the Assisted-by trailer last.

Change classification

  • Change class: charly Go build tooling — the compiled-in plugin generator (charly/internal/pluginsgen) and the build entrypoint (scripts/bootstrap-charly.sh) — plus their tests. Not a runtime change: the generated artifacts are byte-identical, so the shipped binary's plugin resolution is unchanged.
  • Verification gate: the core Go gate (gofmt + go vet + go test ./charly/...) and a live scripts/bootstrap-charly.sh run on the final committed tree 90ea4779, plus tamper-failure proofs for the new gate.
  • R10 target set: ∅ (see above).
  • Attribution tier: analysed on a live system — both changed paths ran live with retained output, but no disposable: true bed was run. No runtime path is touched, so no bed is affected; I am not claiming fully tested and validated for a bed I did not run.

Agent: polymorphism-truth · session 9c898e99-b5d7-4f3e-a472-62c4ecbcd18f
Assisted-by: Claude Code DeepSeek V4.1 (flash) (analysed on a live system)

…ild's rewrite

TestPluginsGenReproducible byte-compared all three generated files against a
live regeneration. Two of them are derived from TRACKED inputs and byte-equality
is sound there. The third, charly/plugins_refs_generated.go, is a projection of
the corpus's DEFAULT branches (collectWordRefs -> refs.DownloadRepo(repo, "HEAD")),
so byte-equality with a live re-fetch is a contract that cannot hold: any plugin
repo merging a provider addition reddens main with no charly-side change.

It did. plugin-pipeline#32 merged 2026-10-04T21:04:52Z adding seven verb providers;
ci run 37236037806 @ 9cd960e failed at 21:25:33Z on exactly that file.

Split the gate by determinism:

  - plugins_generated.go + go.work keep byte-equality, unchanged in strength;
  - the upstream-derived index moves to TestPluginsRefsIndexSound, gated on the
    invariant that IS true of a moving projection: every word the committed index
    names must still be served by that same ref. A word the corpus no longer
    serves, or serves from a different ref, means the index is FALSE -> FAIL (this
    is also the shape a hand-edit takes). An upstream ADDITION means the index is
    incomplete, not wrong -> advisory, never red.

With it, scripts/check-generated-clean.sh classifies the tracked files the build
rewrites by the same cause, and bootstrap-charly.sh calls it before promoting the
binary: an inconsistent file (tracked inputs) fails for review and commit; the
upstream-derived one is named and restored, so a sanctioned build leaves the tree
clean at its gitlink and the detached umbrella submodule is never dirtied.

The corpus set is built in one place (corpusRepoList) so the generator and the
soundness gate cannot disagree about what "the corpus" means.

Closes #792
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Review — PASS

Head SHA: 90ea4779dade79e4a32a8ed9cc899be52f63dc10 (branch: feat/refs-drift-guard)

Security screen: PASS — no injection directives, no secrets/egress, no supply-chain edits; scripts/bootstrap-charly.sh + check-generated-clean.sh and the drift test are build-integrity, not the T3/T4 enumerated access-control machinery, so no maintainer sign-off is triggered (and none is present in the empty thread).

Change class: charly Go build tooling + build script (non-runtime; generated artifacts byte-identical).

Checklist: All applicable rules PASS or NA.

  • A1/A3: body accounts for all 5 files; ends with the italicized *Assisted-by:* trailer after the Agent: line; tier analysed on a live system is honest (bootstrap + gates ran live, no bed claimed) — not inflated.
  • A2/B12/R10: build tooling, no runtime path changed, so no disposable: true bed is owed; fresh-rebuild evidence (bootstrap run, go test ./charly/..., per-gate tamper-failure proofs, guard-absent failure) is internally consistent — test names/--list/exit codes all match the diff; corpusRepoList refactor is byte-equivalent to the inlined code.
  • B5/B6/B7/B8/B9/B10: real RCA (measured merge→red interval + failing gate), superseded byte-equality assertion removed in the same commit, corpus set and class list each defined once, no sleeps/workarounds, no docs-routing, no leftover legacy path.
  • B13: no candy/schema/proto/compiled_plugins change; ADE/SDD N/A.
  • B16: placement CORRECT — pluginsgen generator, its tests, and the build guard all stay in the build/tooling layer; no alias file, no sdk-into-core import, no *Legacy* name.
  • B18: diff is gofmt-clean, no dead code/unused imports, lowercase-hyphenated paths.
  • Comment intake: thread is empty (0 comments) — nothing to disposition.

Verdict: PASS


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

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) October 5, 2026 02:44
@github-actions
github-actions Bot merged commit 7484c74 into main Oct 5, 2026
1 of 2 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Oct 5, 2026
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.

bootstrap-charly.sh leaves a tracked file dirty: pluginsgen re-indexes the corpus at upstream HEAD, with no drift guard

1 participant