Skip to content

fix(loaderkit): terminate a cyclic namespace graph on the materialized wire - #350

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/materialized-wire-cycle
Oct 7, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
fix/materialized-wire-cycle

Conversation

@aitrawog

@aitrawog aitrawog commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Summary

MarshalMaterialized serialized a materialized spec.UnifiedFile as materializedEnvelope{UF: uf}, and spec.UnifiedFile.Namespaces is JSON-serialized (it carries only yaml:"-"). The graph it holds is cyclic by design: MaterializeLoadedProject reference-mounts the SAME *UnifiedFile pointer to break cycles and preserve diamonds ("the intentional main↔cachyos mutual import"), and this package's own capturePluginKindsSeen documents that cycle. encoding/json therefore rejects the marshal:

json: unsupported value: encountered a cycle via map[string]*spec.UnifiedFile

That made charly box validate / charly task <name> fail on any project whose import graph contains such a cycle — opencharly/opencharly#330.

The codec now carries the namespace tree flat: one materializedNamespace per PATH, each File a shallow copy with its own Namespaces cleared — exactly as the same envelope already carries PluginKinds by path. Every path a finite walk reaches survives (diamond and multi-alias mounts included); a genuine back-edge truncates, which is exactly the set UnifiedFile.collectBeds enumerates (it returns the instant it re-enters a namespace already on the current path). UnmarshalMaterialized rebuilds the tree from the flat levels.

The materialized-tree cache key already includes the sdk module version (loader_identity), so the wire-format change re-keys every entry and no stale payload is served.

Head 6b1e7cb8d69bb2b7b2a6c8e0a8b66bb5f32bc459, diff vs origin/main:

 loaderkit/materialize_wire.go            | 155 +++++++++++++++++++++++++------
 loaderkit/materialize_wire_cycle_test.go | 106 +++++++++++++++++++++
 2 files changed, 235 insertions(+), 26 deletions(-)

How tested

The new tests FAIL on the pre-fix code — the coverage is real, not vacuous. The same test file run against a clean origin/main worktree:

$ git worktree add /tmp/sdk-prefix --detach origin/main
$ cp loaderkit/materialize_wire_cycle_test.go /tmp/sdk-prefix/loaderkit/
$ (cd /tmp/sdk-prefix && GOWORK=off go test ./loaderkit/ -run 'TestMarshalMaterialized_(SelfCycle|MutualCycle|NestedLevels)' -v)
--- FAIL: TestMarshalMaterialized_SelfCycleRoundTrips
    materialize_wire_cycle_test.go:37: MarshalMaterialized(self-cycle): json: unsupported value: encountered a cycle via map[string]*spec.UnifiedFile
--- FAIL: TestMarshalMaterialized_MutualCycleRoundTrips
    materialize_wire_cycle_test.go:62: MarshalMaterialized(mutual-cycle): json: unsupported value: encountered a cycle via map[string]*spec.UnifiedFile
--- PASS: TestMarshalMaterialized_NestedLevelsPreserved

On this head the module gate (.github/workflows/ci.yml) is green:

$ gofmt -l .
$ go build ./...
build rc=0
$ go vet ./...
vet rc=0
$ go test ./...
test rc=0
$ golangci-lint run ./...
0 issues.
$ for arch in amd64 arm64 arm 386; do GOOS=linux GOARCH=$arch CGO_ENABLED=0 go build ./...; done
  amd64 ok
  arm64 ok
  arm ok
  386 ok

The pre-existing TestMarshalMaterialized_DiamondPreservesAllPaths and the PluginKinds tests still pass in that full run — the flat form preserves the diamond and every alias.

Live, on the acceptance case opencharly/opencharly#330 names — a charly binary built against THIS sdk worktree only (its linked spec is the ordinary pinned v0.2026279.2018, no replace), run from the umbrella root:

$ charly -C <umbrella> task list
hooks                    Install the pre-commit gate for this clone ...
map                      List every submodule with its pin and sync state
org-map                  Verify the README "## The org map" tables against the repo and .gitmodules
pins                     The policy-B pin operation over the distro-* set (mode via param)
policy-b                 Assert policy B — every distro-* gitlink equals charly's own box/* gitlink
prune                    Reap merged-upstream session worktrees + branches (MODE=report is a dry run)
self-test                Self-test the committed CI body/pin-evidence builders + the dispatcher splice
skills                   Splice the generated R0 dispatcher from the pinned marketplace into AGENTS.md
sync                     Bump all submodule pins per policy B (preview; does not commit)
verify                   Run the full pinning gate on demand (every pin, incl. the remote branch audit)
rc=0

The umbrella root previously failed with the cycle error and could not list a single task.

Rulebook compliance

Rule Answer
R0 git-workflow, go, plugin, install-plan skills loaded before any edit.
R1 RCA'd from the live code: the loader reference-mounts the same pointer by design (cycle/diamond preservation); the codec plain-marshalled the nested struct. The package's own test already conceded "the marshal path itself rejects a literal pointer cycle at the json layer".
R2 The one surfaced defect is fixed here; the identity half of the same defect family is a named, in-flight PR (opencharly/spec#202), not a deferral.
R3 One codec, one flat representation — the namespace levels join PluginKinds in the SAME envelope; no second marshal path.
R4 No sleep, retry, or fallback added; the fix removes an unrepresentable serialization.
R5 No identifier deleted; MarshalMaterialized/UnmarshalMaterialized keep their names and contract, whose docs now state the cycle-safe rule.
R6 git status clean before and after the commit; PR-only branch; no force-push.
R7 The new tests fail on pre-fix code (pasted) and pass here; the changed path ran live (pasted).
R8 N/A — no OCI label or emitted config is touched; the wire codec itself is the artifact under test.
R9 N/A — a library module built from source; no deployed binary.
R10 The change-class gate for this module is its CI (build / vet / test / gofmt / golangci-lint / cross-compile), all green and pasted; plus the live umbrella run above.

Change classification

  • Change class: Go code (the loader's materialized-tree wire codec) plus tests — runtime.
  • Attribution tier: fully tested and validated — the CI-equivalent gate passed on the final tree and the changed path ran live on the real acceptance case.

Related: opencharly/opencharly#330 (this lands the wire-codec half; the identity half is opencharly/spec#202), opencharly/plugin-check#85.

Agent: plugin-check-85-takeover · session session-fe6a1287-a711-4e47-b913-70b78d262fd1
Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

…d wire

MarshalMaterialized serialized a materialized spec.UnifiedFile as
materializedEnvelope{UF: uf}, and spec.UnifiedFile.Namespaces is JSON-serialized
(it carries only `yaml:"-"`). The graph it holds is CYCLIC BY DESIGN:
MaterializeLoadedProject reference-mounts the SAME *UnifiedFile pointer to break
cycles and preserve diamonds ("the intentional main<->cachyos mutual import"),
and this package's own capturePluginKindsSeen documents that cycle. encoding/json
therefore rejects the marshal:

    json: unsupported value: encountered a cycle via map[string]*spec.UnifiedFile

which made `charly box validate` / `charly task <name>` fail on any project whose
import graph contains such a cycle (opencharly/opencharly#330).

The codec now carries the namespace tree FLAT — one materializedNamespace per
PATH, each File a shallow copy with its own Namespaces cleared — exactly as it
already carries PluginKinds by path. Every path a finite walk reaches survives
(the diamond and multi-alias mounts included); a genuine back-edge truncates,
which is exactly the set UnifiedFile.collectBeds enumerates (it returns the
instant it re-enters a namespace already on the current path).

The materialized-tree cache key already includes the sdk module version, so the
wire-format change re-keys every entry and no stale payload is served.

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
aitrawog added a commit to opencharly/spec that referenced this pull request Oct 7, 2026
…forms

The first revision qualified only a LOCAL ref's identity. A remote
`@host/org/repo[/sub]` ref still dropped its sub-path, so a subdirectory project
addressed remotely collapsed to its enclosing repo — the same false back-edge on
the other path. ParseRemoteRef already exposes SubPath; RepoIdentity now carries
it, mirroring the local branch's toplevel-relative qualification, so one rule
covers both forms.

The test header also now names WHICH of the two coupled fixes each consequence
belongs to: this identity fix (the project resolves as a definition mount, so
the namespace is delivered at all) versus the loaderkit wire codec's back-edge
truncation (opencharly/sdk#350), which with the identity collapse still present
silently dropped the namespace instead of crashing.

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Review — PASS

Head SHA: 6b1e7cb8d69bb2b7b2a6c8e0a8b66bb5f32bc459 (branch: fix/materialized-wire-cycle)

Security screen: PASS — no scope mismatch, secrets/exfiltration, weakened guardrail, or supply-chain change; only loaderkit/materialize_wire.go + one new test file. No embedded directives in the PR content.
Checklist: All applicable rules PASS or NA. Tool-limited cross-check (read-only, no shell): the pasted evidence is internally consistent — the pre-fix failure line numbers (37, 62) match the current test file exactly, the diff stat (+129/−26, +106; 235 insertions / 26 deletions / 2 files) reconciles with the hunk counts, and the RCA + doc-comment rewrite match the diff (the old "Namespaces + RootDir already round-trip … ONLY PluginKinds must be carried" claim is the swept falsehood). No comments to disposition.
placement: CORRECT — the change stays inside the pre-existing loaderkit materialize-leg wire codec (a kit mechanism consumed by plugin + host); no new charly/ import, no alias growth, no capability pulled into core.

Verdict: PASS


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

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) October 7, 2026 12:50
@github-actions
github-actions Bot merged commit 46861a7 into main Oct 7, 2026
6 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Oct 7, 2026
github-actions Bot pushed a commit to opencharly/spec that referenced this pull request Oct 7, 2026
…e enclosing repo (#202)

* fix(spec): resolve a local import ref to its PROJECT identity, not the enclosing repo

RepoIdentity() returned the git `origin` identity of the ref's directory, and
`git remote get-url origin` walks UP to the enclosing repository. A namespaced
import of a subdirectory project inside the same repo therefore inherited the
ROOT's identity, so walkNamespace's repo-identity cycle-break resolved it as a
REFERENCE mount to the root — a degenerate self-cycle. The materialized wire
marshaller then failed with `json: unsupported value: encountered a cycle via
map[string]*spec.UnifiedFile` (opencharly/opencharly#330's signature), and once
that marshaller was made cycle-safe the whole namespace was silently dropped.

ProjectRepoIdentity() now owns the rule uniformly (RootRepoIdentity is a thin
forward to it): an explicit `repo:` in the project's charly.yml is authoritative;
otherwise the git origin identity is QUALIFIED by the project's path relative to
the git toplevel whenever the project is not itself the repo root. A repo-root
project (a local submodule) keeps the bare identity, so the local<->remote
mutual-import short-circuit is unchanged.

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

* fix(spec): scope an import ref's identity to its PROJECT on BOTH ref forms

The first revision qualified only a LOCAL ref's identity. A remote
`@host/org/repo[/sub]` ref still dropped its sub-path, so a subdirectory project
addressed remotely collapsed to its enclosing repo — the same false back-edge on
the other path. ParseRemoteRef already exposes SubPath; RepoIdentity now carries
it, mirroring the local branch's toplevel-relative qualification, so one rule
covers both forms.

The test header also now names WHICH of the two coupled fixes each consequence
belongs to: this identity fix (the project resolves as a definition mount, so
the namespace is delivered at all) versus the loaderkit wire codec's back-edge
truncation (opencharly/sdk#350), which with the identity collapse still present
silently dropped the namespace instead of crashing.

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
aitrawog added a commit to opencharly/plugin-check that referenced this pull request Oct 7, 2026
The validator's prescribed remedy for the R10 finding: an in-repo
`disposable: true` bed that exercises the changed dotted-local dispatch. The repo
root IMPORTS its own testdata/dotted-local-fixture project as the namespace
`dottedfix`, so that project's kind:local bed is reachable ONLY as the
namespace-qualified `dottedfix.dottedfix-bed` — the dotted-key shape the local
arm must resolve. check-dotted-local-resolve drives it through a real
`charly check live` and asserts the fixture's step id, which the pre-fix code
never reaches (it exits non-zero with `local deployment ... not found`).

This shape requires the two producer fixes that make it possible at all:
opencharly/spec#202 (an import ref's identity names its PROJECT, so a
subdirectory project mounts as a definition rather than a self-reference) and
opencharly/sdk#350 (the materialized wire codec terminates the cyclic namespace
graph instead of rejecting it).

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
github-actions Bot pushed a commit to opencharly/plugin-check that referenced this pull request Oct 7, 2026
…#78) (#85)

* fix(check): resolve a dotted local bed with the dispatcher's resolver

The local live arm resolved a dotted name with an in-substrate-only member
walk, which cannot reach a NAMESPACE-QUALIFIED deploy key (charly.check-task —
its dots are namespace separators), so every dotted local bed reported
"local deployment … not found" before its plan ran. Use
resolveDeployNodeByPath (exact-key-first), the SAME resolver the dispatcher
checkLocalTarget already uses, and tighten checkLocalTarget to dispatch on a
RESOLVED leaf's venue instead of falling through to its root.

* test(check): host-root + non-host-leaf dispatch case (#78)

checkLocalTarget now dispatches on a RESOLVED leaf's venue; add the case
that distinguishes it (my-local.pod-child -> not local), which returns
true on the pre-fix code and so fails without the change.

* test(check): add the in-repo disposable dotted-local R10 bed (#78)

The validator's prescribed remedy for the R10 finding: an in-repo
`disposable: true` bed that exercises the changed dotted-local dispatch. The repo
root IMPORTS its own testdata/dotted-local-fixture project as the namespace
`dottedfix`, so that project's kind:local bed is reachable ONLY as the
namespace-qualified `dottedfix.dottedfix-bed` — the dotted-key shape the local
arm must resolve. check-dotted-local-resolve drives it through a real
`charly check live` and asserts the fixture's step id, which the pre-fix code
never reaches (it exits non-zero with `local deployment ... not found`).

This shape requires the two producer fixes that make it possible at all:
opencharly/spec#202 (an import ref's identity names its PROJECT, so a
subdirectory project mounts as a definition rather than a self-reference) and
opencharly/sdk#350 (the materialized wire codec terminates the cyclic namespace
graph instead of rejecting it).

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

* revert(check): drop the speculative leaf-venue dispatch change (#78)

The resolver fix (resolveLocalDeployNode + the local arm using it) is the whole of
#78's defect, and the in-repo R10 bed witnesses it: its
target dottedfix.dottedfix-bed resolves to a HOST leaf, so
`charly check run check-dotted-local-resolve` fails before the fix and passes after
it with NO change to checkLocalTarget.

The accompanying checkLocalTarget dispatch change (a RESOLVED non-host leaf under a
HOST root must not be local-routed via its root) alters a DIFFERENT behavior, and
its only witness is a unit case — the local-bed R10 cannot distinguish it. It is
therefore separable from this cutover and moves to its own named change
(#86), which must carry a runtime witness bed.

Also corrects charly.yml's stale header comment ("This file declares no entities of
its own - it only tells charly where to look"), which is false since this file now
declares the import and the R10-witness entities.

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
aitrawog added a commit to opencharly/opencharly that referenced this pull request Oct 7, 2026
…orktree-safe

Two changes in one commit: the pin advance this PR came for, and the fix for the defect that
stopped its OWN gate from running.

1. Policy-B pin advance (via `charly task pins MODE=bump`, scoped to the charly gitlink):

     charly  350435d789836d135304c2e49af40211cd5f10e9 -> 214692903edee807d9149f518fcd6896c7c294f6

   What the pin carries (the merged producer chain): opencharly/spec#202 (an import ref's
   identity names its PROJECT), opencharly/sdk#350 (the wire codec terminates the cyclic
   UnifiedFile.Namespaces graph), opencharly/plugin-check#85 (the local arm resolves a
   namespace-qualified bed with the dispatcher's resolver) and opencharly/plugin-check#87 (a
   resolved non-host leaf under a host root dispatches on its own venue). Together these
   close #330: `./charly/bin/charly task list` from the umbrella root
   loads and lists every maintenance task instead of aborting at project load with
   `json: unsupported value: encountered a cycle via map[string]*spec.UnifiedFile`.

   No distro-* move is required: charly's box/* gitlinks are identical at 350435d7 and
   21469290, so policy B already holds for the twins.

2. scripts/check-harness-config.mjs: the self-test no longer aborts on an unmaterialized
   submodule surface. `stage()` copied every surface unconditionally, so a checkout without
   the `marketplace` submodule -- the session-worktree layout Part II rule 2 REQUIRES --
   threw ENOENT out of the self-test and made `charly task verify` un-runnable there. It now
   SKIPS such a surface with a NOTICE, the same precondition the gate already guards at
   checks 8/12/13, and the four corpus-measured arms (check 12's two, check 13's coverage
   and collision) are skipped in the same voice; the report names how many arms were live.

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
github-actions Bot pushed a commit to opencharly/opencharly that referenced this pull request Oct 7, 2026
…+ loader-cycle fixes (#330) (#424)

* chore(pins): advance charly to v2026.280.1631 -- the dotted-local-bed + loader-cycle fixes

Policy-B pin advance via `charly task pins MODE=bump` (scoped to the charly gitlink):

  charly  350435d789836d135304c2e49af40211cd5f10e9 -> 945f9d7d35d3383bee4863f1aa00d10c6a48e3a9

What the pin carries (the merged producer chain):
- charly#821 adopts spec v0.2026280.1255 (opencharly/spec#202 -- an import ref's identity
  names its PROJECT), sdk v0.2026280.1251 (opencharly/sdk#350 -- the wire codec terminates
  the cyclic UnifiedFile.Namespaces graph) and plugin-check v0.2026280.1309
  (opencharly/plugin-check#85 -- the local arm resolves a namespace-qualified bed with the
  dispatcher's resolver).

Together these fix #330: `./charly/bin/charly task list` from the
umbrella root now loads and lists every maintenance task (rc=0) instead of aborting at
project load with
`json: unsupported value: encountered a cycle via map[string]*spec.UnifiedFile`.

No distro-* move is required: charly's box/* gitlinks are unchanged between the old and the
new pin, so policy B already holds for the twins (verified).

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

* chore(pins): advance charly to v2026.280.1725 and make the pin gate worktree-safe

Two changes in one commit: the pin advance this PR came for, and the fix for the defect that
stopped its OWN gate from running.

1. Policy-B pin advance (via `charly task pins MODE=bump`, scoped to the charly gitlink):

     charly  350435d789836d135304c2e49af40211cd5f10e9 -> 214692903edee807d9149f518fcd6896c7c294f6

   What the pin carries (the merged producer chain): opencharly/spec#202 (an import ref's
   identity names its PROJECT), opencharly/sdk#350 (the wire codec terminates the cyclic
   UnifiedFile.Namespaces graph), opencharly/plugin-check#85 (the local arm resolves a
   namespace-qualified bed with the dispatcher's resolver) and opencharly/plugin-check#87 (a
   resolved non-host leaf under a host root dispatches on its own venue). Together these
   close #330: `./charly/bin/charly task list` from the umbrella root
   loads and lists every maintenance task instead of aborting at project load with
   `json: unsupported value: encountered a cycle via map[string]*spec.UnifiedFile`.

   No distro-* move is required: charly's box/* gitlinks are identical at 350435d7 and
   21469290, so policy B already holds for the twins.

2. scripts/check-harness-config.mjs: the self-test no longer aborts on an unmaterialized
   submodule surface. `stage()` copied every surface unconditionally, so a checkout without
   the `marketplace` submodule -- the session-worktree layout Part II rule 2 REQUIRES --
   threw ENOENT out of the self-test and made `charly task verify` un-runnable there. It now
   SKIPS such a surface with a NOTICE, the same precondition the gate already guards at
   checks 8/12/13, and the four corpus-measured arms (check 12's two, check 13's coverage
   and collision) are skipped in the same voice; the report names how many arms were live.

Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
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