Skip to content

skills: no rule probes a reference chain as a spelling of its own #2372

Done

Description

@OmarAlJarrah

Problem

A schema that writes only a $ref keeps that reference as its own, in the statement's Schema.Ref (compilers/openapi/internal/statement/statement.go, reached as Statement.Ref), not as one of its Entries. A reader that walks a schema's conjuncts through Entries therefore stops at R: {$ref: T} and never reaches T. The one-hop spelling, which names T directly, does reach it. So the two-hop spelling of one schema can lower differently, and no skill says to write that spelling beside the one-hop twin.

  • morphic-openapi-compiler/references/lossless-and-diagnostics.md#every-spelling-of-one-concept lists the spellings to write one case each for: "nullability as a keyword or a null branch, schema or content, ASCII and non-ASCII twins, case-insensitive tokens in another case, both orders of an adjacency". A reference chain is not among them.
  • morphic-openapi-compiler/references/openapi-lessons.md#resolve-to-true-target asks for a two-hop chain, but only of a reader that knows it reads through a reference, for "every annotation read through it". A walk over conjuncts does not think of itself as such a reader: it reads Entries, where the chain does not appear.
  • morphic-verifying-changes/references/differentials.md#generator-width names "positions past a $ref" among the read paths a generator writes, but no chain of them.
$ git grep -n -i -E 'reference chain|chain of references|only a \$ref' origin/main -- .claude/skills/morphic-openapi-compiler .claude/skills/morphic-verifying-changes
origin/main:.claude/skills/morphic-openapi-compiler/references/openapi-lessons.md:342:## Read a reference chain to its end, and test every hop

A defect this let through, in the work on #2354. A rule there keeps an unevaluated keyword whose reach meets an if, but the reach walked Entries alone:

openapi: 3.1.0
info: {title: t, version: "1"}
paths: {}
components:
  schemas:
    T: {type: object, properties: {a: {type: integer}}, if: {required: [a]}, then: {properties: {k: {type: integer}}}}
    R: {$ref: '#/components/schemas/T'}
    OneHop: {allOf: [{$ref: '#/components/schemas/T'}], unevaluatedProperties: false}
    TwoHop: {allOf: [{$ref: '#/components/schemas/R'}], unevaluatedProperties: false}

At 2fba1eb, a commit of that work which #2354's branch does not hold yet:

$ morphic compile --verify --diagnostics-per-code-limit 0 chain.yaml > ir.json; echo "exit $?"
info openapi/validation-only-keyword chain.yaml#/components/schemas/T: validation-only keyword "if/then/else" kept verbatim under Unmodeled
info openapi/validation-only-keyword chain.yaml#/components/schemas/OneHop: validation-only keyword "unevaluated" kept verbatim under Unmodeled
exit 0
$ jq -c '.types | to_entries[] | select(.key|test("schemas/(OneHop|TwoHop)$")) | {id: (.key|split("/")|last), additional: .value.additional, kept: (.value.unmodeled // {} | map_values(.reason))}' ir.json
{"id":"OneHop","additional":null,"kept":{"openapi:unevaluated":"validation_only"}}
{"id":"TwoHop","additional":"closed_after_composition","kept":{}}

TwoHop is closed after composition, so the IR refuses {"a": 1, "k": 1}, which the source accepts through T's then. Its child, 80c048d, made the reach follow a schema's own reference and gives both the OneHop result. A review found it by reading the walk.

Direction

A draft:

  • In every-spelling-of-one-concept, add a reference chain to the list: a conjunct, branch or $ref target written through a schema that is only a $ref (and, in 3.1, only a $dynamicRef) beside the twin that names the target directly.
  • In resolve-to-true-target, say that a walk over a schema's conjuncts is a reader through a reference too, because a schema that is only a $ref keeps it outside its Entries.
  • In generator-width, name a reference chain among the read paths a generator writes.

Out of scope

The unevaluated reach itself, which 80c048d fixes.

Related: #2354

Priority: P4, rule 1 (housekeeping): a skills change that alters no lowering, validation, IR or emit-contract behaviour. The git grep above → one hit, the rule for a reader through a reference (morphic @4a7a384c9). The compile above → TwoHop closed and OneHop kept (morphic @2fba1eb98).

Activity

  1. added
    type:feature
    priority:P4
    on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:P4type:feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions