Skip to content

schemacompose: a dangling reference inside a served definition survives the compose, so "plugin schema does not compile" covers imports only #301

Open

Description

@aitrawog

What

schemacompose composes a plugin's served schema as ONE offline CUE module instance, and the SDK
reports plugin schema does not compile when that fails. It catches an unresolvable import and it
does not catch a dangling reference inside a served definition — because a CUE definition body
is not forced until something instantiates the field that carries it. So a plugin whose schema says
schema.#NoSuchDef starts, serves, and passes the load gate, and fails only at the first authored step
that sets that field.

Measured on the second converted consumer, opencharly/plugin-vision (branch
feat/spec-schema-import, head 752c41f), with a charly built at 8cc5a79b carrying spec
v0.2026313.1428 / sdk v0.2026313.513, in a scratch project whose only job is to reference the
vision: word so the loader host-builds the plugin and loads its schema:

# the IMPORT arm: loud, and it names the file
$ python3 - <<'EOF'
p='candy/plugin-vision/schema/vision.cue'
s=open(p).read().replace('import "github.com/opencharly/spec/schema"','import "example.com/does/not/exist"')
open(p,'w').write(s)
EOF
$ grep -n '^import' candy/plugin-vision/schema/vision.cue
33:import "example.com/does/not/exist"
$ charly box generate; echo "rc=$?"
charly: error: command "generate": buildengine-connect-plugins: build-time plugin load failed: plugin plugin-vision (describe phase, source github.com/opencharly/plugin-vision/candy/plugin-vision): plugin describe: rpc error: code = Unknown desc = plugin schema does not compile: import failed: /opencharly/plugin-schema/schema/plugin.cue:35:8: cannot find package "example.com/does/not/exist": cannot find module providing package example.com/does/not/exist
rc=1

# the DANGLING arm: silent
$ python3 - <<'EOF'
p='candy/plugin-vision/schema/vision.cue'
s=open(p).read().replace('llm?: schema.#LLMSpec @go(Llm)','llm?: schema.#NoSuchDef @go(Llm)')
open(p,'w').write(s)
EOF
$ grep -n 'llm?:' candy/plugin-vision/schema/vision.cue
59:	llm?: schema.#NoSuchDef @go(Llm)
$ charly box generate; echo "rc=$?"
plugin plugin-vision: served from /home/atrawog/.cache/charly/plugin-build/views/plugin-vision-c3ed8a58fdd50092 (build sha256:0a7389a0021c271294a4c58183ecf80b07ea0d10cab2ac60206642eb18e2dd14); source /tmp/vision-init/candy/plugin-vision
rc=0

Nor does any non-forcing read of the composed value see it — on the same dangling schema,
ServedSchema returns no error and every top-level definition validates clean:

$ go run . /tmp/schema-baddef.cue      # compose, then per-definition Validate
compose err: <nil>
#VisionInput           Validate(Concrete=false)=<nil>  Validate()=<nil>
#VisionExpect          Validate(Concrete=false)=<nil>  Validate()=<nil>

The mechanism

CUE defers errors inside an uninstantiated definition. #VisionInput.llm is an OPTIONAL field, so
unifying a document that omits llm never evaluates schema.#NoSuchDef; the selector resolves only
when a value lands on that field. CompileString, the module compose, and Value.Validate() all read
the definition without instantiating it, which is why the three of them agree that a dangling schema is
fine.

For contrast, the committed test in that repo does catch it, because its fixture holds a document that
SETS llm:

$ go test -run 'TestServedSchemaLoadsAndCarriesTheImport|TestVisionInputFixtureJudgedIdenticallyByBothHalves' .
    schema_test.go:278: empty llm block   accept=true verdict=#VisionInput.llm: undefined field: #NoSuchDef
--- FAIL

The missed control

The gate's message is the claim: plugin schema does not compile. It is true of an import and false of
a dangling reference, and nothing in schemacompose's or the SDK's stated contract says the second case
is out of reach. A reader of that message reasonably infers both are covered.

Blast radius

Every plugin's served schema. A dangling reference — a renamed contract def, a typo, a def deleted in
the contract repo — is a delayed, confusing failure: start-up is green, the plugin is advertised, and
the first authored step that touches the field fails with an error pointing at the STEP rather than at
the schema.

charly box validate is not a second gate: it stays green on BOTH arms (measured on the same head),
and the org candy-validate projection step cannot read an importing schema at all
(opencharly/.github#288).

Root fix (needs a decision, not a guess)

The compose should force what it advertises. Two candidate shapes, neither proven yet:

  1. Force each served definition at the compose boundary — instantiate every field of the def with a
    maximal value (or unify it against a generated "all optional fields present" instance) and report
    the resulting error. Catches the case where a field's reference is dangling; needs care not to
    reject a legitimately incomplete def.
  2. Resolve selectors statically — walk the loaded instance's syntax for selectors into imported
    packages and assert each label resolves. Cheaper, and independent of instantiation.

Either way the regression test belongs beside schemacompose's existing arms: a schema whose def
references a missing label must FAIL the compose, and an import of a missing package must keep failing
as it does today.

Agent: vision-schema-import

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:runtimetype:fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions