Skip to content

git.Resource decodes a document form it can never be written to #661

Open

Description

@David-Noble-at-work

Found while sealing git (#642). git.Resource can be read from a document form it can never be written to.

The asymmetry

UnmarshalJSON and UnmarshalYAML decode {uri, ref, head} and carefully carry ref and HEAD across the rebuild:

ref, head := aux.Ref, aux.HEAD
built, err := discoverResource(r.RuntimeEnvironment(), aux.URI)
built.ref, built.head = ref, head

UnmarshalText's doc comment states the intended split outright: "Scalar form: only identity (URI) round-trips. Ref, HEAD, and Remotes remain at zero values; richer round trip uses [Resource.UnmarshalJSON] or [Resource.UnmarshalYAML]."

That richer round trip does not exist. git has no MarshalJSON and no MarshalYAML, so the promoted op.ResourceBase marshalers write the URI alone. Nothing in the tree ever produces the ref/head keys the decoders read.

The contract nobody honors

op.ResourceBase.MarshalJSON's own doc comment anticipates this: "additional fields (cached metadata, domain-specific state) override [ResourceBase.MarshalJSON] with their own representation."

Zero resources override it — verified across all nine providers. Every resource marshals as a bare URI string. So the base documents an extension contract that no implementation uses, and git is the one whose decoder was written as though it did.

Why it is more than adding two methods

git returns receipts (Provider.Clone → NewReceipt(destination)), and a receipt's result is marshaled through the resource. Today that is a URI string, and resolveRecordedResource depends on exactly that:

uri, isString := result.(string)
if !isString {
    return nil, false
}

Give git an object-form marshaler and its receipts stop satisfying that assertion. The miss is silent — retypeStampedResult swallows it with a bare return, and a resumed run keeps a decoded map instead of a resource. That is the same failure mode #641 fixed on the id side, arriving on the shape side.

So the work is:

  1. MarshalJSON / MarshalYAML on git's resource, emitting the {uri, ref, head} shape its decoders already accept, with omitempty so a resource carrying neither stays {"uri": "..."}.
  2. resolveRecordedResource accepts the object form as well as the bare string, keyed on uri.
  3. A round-trip pin: a git resource with ref and head set survives marshal → unmarshal with both intact. Nothing tests that today, which is why the gap survived.

The wider question this raises

git is the only provider whose decoder assumes a richer form, but it may not be the only one that wants one. pkg and mem carry domain state too. Worth deciding whether the base's documented override contract is real — and if not, deleting the sentence rather than leaving an invitation nobody accepts.

Not folded into #642 (USER, 2026-08-24): that phase seals git and appnet and preserves the existing behavior exactly. This changes a document format and belongs on its own.

Activity

  1. David-Noble-at-work commented on Nov 9, 2026

    @David-Noble-at-work
    ContributorAuthor

    star github triage sweep added this issue to Triage: devlore, for the rule it breaks:

    • no-evidence: no Evidence of completion section
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions