Skip to content

ConvertFrom mints identity-less resources across every provider #649

Closed

Description

@David-Noble-at-work

Every provider resource's ConvertFrom mints a resource with no identity and returns it as a slot value:

Provider Site Returns
appnet resource.go:293 &Resource{SourceURL: u}
git resource.go:381 &Resource{SourcePath: …}
pkg resource.go:328 &Resource{Name: str}
service resource.go:304 &Resource{Name: str}
file regular.go:233, directory.go:243, symbolic_link.go:246, resource_base.go:338 &Regular{resource: resource{SourcePath: …}} etc.

None calls op.NewResourceBase, so the embedded op.ResourceBase stays zero and URI() returns "". The value is unclaimed, uninterned, and identity-less — and every doc comment hands the problem downstream rather than solving it:

"Provider methods consuming the projected Resource are responsible for re-canonicalization via their own NewResource/DiscoverResource path when full identity is required."

That is the resource model depending on each consumer's good manners, which is the same thing #625 exists to stop depending on.

Why this is separate from #625

The seal governs construction from outside the package. ConvertFrom is a method on the resource, in its own package, so the seal permits it by design.

What #625 does change here

Convert step 7 reaches ConvertFrom by probing reflect.New(target) for TargetConverter (convert.go:364). After sealing, a resource slot's type is an interface, so the probe yields a pointer-to-interface with an empty method set, Implements returns false, and step 7 stops firing for resource slots entirely. Combined with tryHydrateStruct declining for the same reason, both identity-less routes into a resource slot close.

That leaves CanConvertFrom/ConvertFrom largely unreachable for resources — which is the decision this issue needs to make.

The decision

  1. Delete them — if step 7 can no longer reach them for resource slots, they are dead weight carrying a misleading contract.
  2. Make them honest — return an error instead of an identity-less value, so the failure is loud wherever they are still reached.

Option 1 has a consequence to size first: typesAreInterconvertible (convert.go:542 path 4) uses CanConvertFrom as its only bridge for string ↔ <provider>.Resource at plan time, since it deliberately does not probe registered-Resource construction (that needs a RuntimeEnvironment). Removing the probe makes a same-named-slot collision that is tolerated today become a hard collision in Subgraph.mergeBubbled.

Note file already lives in that state — its kind-indifferent methods take the Resource interface today — so this is a known condition being extended, not a new one. Authored strings are unaffected either way: they bind through op.RegisterResourceMint (#619), not through this path.

Activity

  1. David-Noble-at-work commented on Aug 24, 2026

    @David-Noble-at-work
    ContributorAuthor

    Deferred (USER, 2026-08-24): too early to decide. The fork rests on a claim that has been read off the code but never observed, and on a contract question that cannot be answered until it is.

    What has to be observed first

    After #625 part 1, a resource slot's type is an interface, so tryTargetConverter's probe (pkg/op/convert.go:364) does reflect.New(target) and gets a pointer-to-interface with an empty method set — Implements(targetConverterType) returns false and step 7 should stop firing for resource slots entirely. That is inference from reading reflect's contract, not a measurement.

    #641 should observe it directly and record the result here.

    Why the decision waits on that

    The candidate answer is to split the pair — keep CanConvertFrom, make ConvertFrom return an error — because they do different jobs: CanConvertFrom mints nothing and is the only bridge making string ↔ <provider>.Resource plan-time-compatible (typesAreInterconvertible deliberately cannot probe registered construction, which needs a RuntimeEnvironment), while ConvertFrom is the half that produces the identity-less value.

    But that leaves a type advertising convertibility and then refusing to convert, which is an incoherent contract on its face. Whether that incoherence is acceptable depends on whether CanConvertFrom still has a live consumer after part 1 — which is exactly what has not been observed. If nothing reaches either method, deleting both is clean and the incoherence never arises.

    Open sub-questions to settle at the same time

    1. Does file's unexported base ConvertFrom (resource_base.go:338) follow the same rule? It returns &resource{…} — a bare base that deliberately lacks sealedResource(), so it cannot satisfy file.Resource. Where that value is meant to land is itself unclear.
    2. Does any env-less library caller or test legitimately depend on step 7 producing a resource today? Making it error surfaces those loudly — intended, but it is work to absorb.
  2. David-Noble-at-work commented on Aug 25, 2026

    @David-Noble-at-work
    ContributorAuthor

    The deferral trigger has fired — this is decidable now

    Phase 1 (#641, merged) made the observation this issue was waiting on, and pinned it:

    pkg/op/provider/service/forgery_test.go → TestConvert_EnvlessStringNoLongerReachesConvertFrom

    op.Convert step 7 reaches a resource's TargetConverter by probing reflect.New(target). While the resource was a struct that probe produced a *Resource, which implements the interface, so ConvertFrom ran and returned a value with no URI. Now that the slot type is an interface, the probe produces a pointer-to-interface whose method set is empty — the probe fails and the step declines. The test fails if that ever regains the ability to mint an identity-less resource.

    So the premise this issue rested on is confirmed rather than assumed, and the fork can be resolved.

    Scheduled as step 3 of the current run

    1. function.Provider end-to-end coverage — PR open
    2. Seal json and yaml #643 — seal json, yaml, mem
    3. this issue

    It may need no code

    If nothing reaches CanConvertFrom or ConvertFrom for a resource slot any more, the answer is delete both rather than the "keep the probe, error the conversion" split floated earlier — and the incoherent-contract objection to that split never arises.

    Two things to size before deciding, both from the earlier analysis:

    • typesAreInterconvertible uses CanConvertFrom as its only plan-time bridge for string ↔ <provider>.Resource; it deliberately cannot probe registered construction, which needs a RuntimeEnvironment. Removing the probe turns a tolerated same-named-slot collision into a hard one in Subgraph.mergeBubbled. file already lives in that state, so this is a known condition extending rather than a new one — but it should be confirmed, not assumed.
    • Does any env-less library caller or test depend on step 7 producing a resource today? Making it error surfaces those loudly, which is intended, but it is work to absorb.

    Also unresolved and worth folding in: three of the eight providers are sealed and five are not, so step 7 still reaches ConvertFrom for the unsealed five. Whether this lands now or as part of the last sealing phase depends on whether the answer is "delete" — which is cheap to do eight times — or "change behavior", which is not.

    Not yet started. Sizing happens at step 3 rather than being assumed to be a code change.

  3. David-Noble-at-work commented on Aug 25, 2026

    @David-Noble-at-work
    ContributorAuthor

    Ruled: delete both, and sweep after the migration completes (USER, 2026-08-25)

    Delete ConvertFrom and CanConvertFrom — not the "keep the probe, error the conversion" split floated earlier. That split existed to preserve CanConvertFrom for typesAreInterconvertible, and the preservation turns out to be unnecessary. Its residual objection — a type advertising convertibility and then refusing to convert — never arises.

    Scheduled as phase 8, after every provider is sealed, rather than per-phase. Sealing is what makes a pair unreachable, so once the migration completes all sixteen die at once and the sweep is pure dead-code removal instead of a behaviour change threaded through five PRs.

    The toss list — sixteen methods, eight pairs, five providers

    File Symbols
    pkg/op/provider/appnet/resource.go:323,342 (*resource).CanConvertFrom, (*resource).ConvertFrom
    pkg/op/provider/git/resource.go:444,463 (*resource).CanConvertFrom, (*resource).ConvertFrom
    pkg/op/provider/service/resource.go:350,369 (*resource).CanConvertFrom, (*resource).ConvertFrom
    pkg/op/provider/pkg/resource.go:308,328 (*Resource).CanConvertFrom, (*Resource).ConvertFrom
    pkg/op/provider/file/regular.go:217,233 (*Regular).CanConvertFrom, (*Regular).ConvertFrom
    pkg/op/provider/file/directory.go:227,243 (*Directory).CanConvertFrom, (*Directory).ConvertFrom
    pkg/op/provider/file/symbolic_link.go:230,246 (*SymbolicLink).CanConvertFrom, (*SymbolicLink).ConvertFrom
    pkg/op/provider/file/resource_base.go:319,338 (*resource).CanConvertFrom, (*resource).ConvertFrom

    Their doc comments go with them. Nothing else.

    The framework seam stays

    op.TargetConverter (pkg/op/interfaces.go:67), tryTargetConverter (convert.go:364, step 7), targetSideAdvertises (convert.go:632, path 4 of typesAreInterconvertible), and the cached targetConverterType are all live for non-resource targets:

    • pkg/op/ordering_edge.go:30 — (*OrderingEdge).CanConvertFrom, a real production implementor unrelated to resources
    • pkg/op/convert_test.go:61 — the test double, exercised by TestConvert_TargetConverter

    op.SourceConverter is a different interface in the other direction and is untouched — five implementors including op.ResourceBase.CanConvertTo, function, and mem. Easy to conflate by name; deleting the wrong half would break content-addressed conversion.

    Why this is safe — evidence, not argument

    1. The contract declares itself optional for resources. pkg/op/interfaces.go:65: implementers "commonly omit TargetConverter when their natural source is content bytes or a parsed structure — not a CLI string." Four resources — json, yaml, mem, function — have never implemented it. The remaining five stop opting in, joining four that already decline.
    2. The plan-time worry that deferred this issue is answered. CanConvertFrom is typesAreInterconvertible's only bridge for string ↔ Resource, and removing it was expected to turn a tolerated same-named-slot collision into a hard one in mergeBubbled. Sealing already removed it for five providers — the probe returns false against an interface target — and the full suite, the scenarios, and all three platforms stayed green. Nothing depended on it.
    3. The deferral trigger fired. Phase 1 pinned the reachability claim as TestConvert_EnvlessStringNoLongerReachesConvertFrom.

    Distinct from #661

    Opposite shape. There, op.ResourceBase.MarshalJSON's doc invites concrete resources to override it and zero implementors do — a contract nobody honours. Here the seam is live, used by a non-resource type, tested, and explicitly optional for resources.

    Also settled

    The second sub-question — does any env-less library caller or test depend on step 7 producing a resource? — is answered by the same evidence: five providers stopped producing one when sealed, and nothing failed.

    The remaining sub-question about file's unexported-base ConvertFrom (resource_base.go:338, returning a bare resource that lacks the seal marker) dissolves — it is on the toss list.

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