Skip to content

feat(op): a resource announces an interface and reflects on the struct behind it - #657

Merged
David-Noble-at-work merged 1 commit into
developfrom
seal-service-resource
Aug 25, 2026
Merged

David-Noble-at-work merged 1 commit into
developfrom
seal-service-resource

Conversation

@David-Noble-at-work

Copy link
Copy Markdown
Contributor

Phase 1 of #625. Closes #641.

The judgment scenario, red first

The forging test went in before the seal, and its failure is the argument for the whole feature:

service.Resource{
  ResourceBase: op.ResourceBase{runtimeEnvironment:nil, id:"", producerID:"",
                                specific:"", typeID:"", uri:""},
  Name: "nginx",
}

Every identity field empty, Name filled from an author-supplied map. op.Convert's generic map-to-struct
hydration admits any target whose concrete kind is reflect.Struct, so a dict where a resource is expected
reflectively minted one — and it reaches sm.Disable(name.Name) against the host. Sealing removes the path
rather than policing it: the slot type becomes an interface, hydration declines, and conversion falls through
to the registered constructor. The test is green now.

The framework change

receiverType carried one type doing two jobs. Split:

  • the concrete type serves method enumeration, promotion, dispatch, and the byType key
  • a stored typeID serves the two typeIDOf(ProviderType()) == typeID comparisons that match an id
    lifted from a URI

NewMethod cannot consume an interface method at all — reflect gives one a nil Func and a Type with no
receiver, so do.Type.In(0) returns the first parameter and panics outright for a no-arg method. Routing
reflection back to the struct is what makes sealing possible; it is not an enumeration nicety.

No generated file changed. The announcement still names provider.Resource and provider.DiscoverResource,
both exported. The struct crosses the package boundary by registration instead — op.RegisterResourceImplementation,
called from the provider's own init. Ordering is guaranteed by the language: the generated package imports the
provider package, so Go initializes the provider first.

The receipt-retyping failure

Commit records what canonicalIDOf reports; restore resolves it through an index built from declared result
types. Two derivations of one identity, with nothing forcing agreement — they agreed only because the declared
return and the dynamic type were the same type. Sealing separates them.

The failure would have been silent: retypeStampedResult is if !ok { return }, so a resumed run keeps the
raw URI string instead of a resource. Fixed on both sides — canonicalIDOf asks a resource for its announced
identity, and the index is additionally keyed by that identity. Pinned in pkg/op/inventory, which is where the
registry is populated, and the pin asserts resolution rather than asserting that a resume succeeded.

Serialization did not move

service's URI fragment is still …/provider/service.Resource, pinned byte-for-byte. Ruling 4 works exactly
as designed: the interface took the name the struct gave up, so typeIDOf is unchanged.

#649's deferral trigger, observed

op.Convert step 7 no longer reaches ConvertFrom for a resource slot — reflect.New(interface) yields a
pointer-to-interface with an empty method set, so the TargetConverter probe fails. Recorded as a test that
fails if it ever regains the ability to mint an identity-less resource. #649 can now be decided.

Four things phase 1 found that the plan had not predicted

  1. A sealed provider must also designate its own mint. An interface asserts no kind, so an authored string
    bound to one is refused unless the interface names a claim type. Every later phase needs the same two lines.
  2. op.Resource does not expose everything ResourceBase provides — ReachabilityURI, Equal, Format,
    and the marshalers were reachable only because embedding leaked the base's surface. Every caller is
    in-package, so the tests reach the struct rather than widening the exported contract. A later phase with an
    out-of-package caller will have to decide differently.
  3. A provider's own package announces nothing — it imports neither its gen package nor the inventory, so a
    test needing a populated registry belongs in pkg/op/inventory. The first placement of the resolution pin
    was wrong for exactly this reason.
  4. The implementation registry is deliberately not RegisterResourceMint. That answers a different
    question — what a bare authored string claims as — and the two coincide only for a single-implementation
    interface. file designates *file.AnyKind while having four implementations.

All four are recorded in the plan, which now marks phase 1 complete.

Verification

make test 103 ok / 0 fail · make build · make vet darwin/linux/windows · make test-scenario ·
complexity · shell-lint · verify-ldflags · gofmt -l — all clean.

@David-Noble-at-work David-Noble-at-work self-assigned this Aug 25, 2026
@David-Noble-at-work
David-Noble-at-work merged commit f5e9c32 into develop Aug 25, 2026
8 checks passed
@David-Noble-at-work
David-Noble-at-work deleted the seal-service-resource branch August 25, 2026 01:58
@David-Noble-at-work

Copy link
Copy Markdown
Contributor Author

Correction to this PR's body. It says "No generated file changed." That is false — pkg/op/provider/service/gen/resource.gen.go did change, and the diff shows it:

-		map[string][]string{
-			"Equal":          {"other"},
-			"CanConvertFrom": {"source"},
-			"ConvertFrom":    {"value"},
-		},
+		nil,

What stayed true is the important half: the file still names provider.Resource and provider.DiscoverResource, both exported, so no new seam was needed to reach the unexported struct — which is what ruling 4 was for. What I missed is that the generator inspects the exported type to derive method metadata. Sealing moves Equal, CanConvertFrom, and ConvertFrom onto the unexported struct, where the generator cannot see them, so it emits none.

Harmless here, and load-bearing later. For service the three lost entries are framework-facing: CanConvertFrom/ConvertFrom are the TargetConverter probe, which this PR proves is now unreachable for an interface-typed slot anyway, and Equal is reached through the interface rather than through announced dispatch. Nothing in the suite or the .star judgment fixtures noticed.

The rule it establishes for phases 2-5: a method that must be dispatchable has to be declared on the sealed interface, because the generator only sees what the exported type exposes. service needed none. Any resource with author-facing methods will, and the failure mode is a silently smaller Starlark surface rather than a build error.

Worth noting the related status quo so the finding is not overstated: an announcement carrying nil metadata yields zero announced methods regardless of sealing — file.AnyKind is already in that state — so this is a sharper version of an existing edge, not a new class of problem.

Recorded on the plan and on #642.

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.

Seal service, and repair the two framework paths an interface-typed resource breaks

1 participant