Skip to content

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

Closed

Description

@David-Noble-at-work

Part 1, phase 1 of sealed-provider-resources.md.

One framework change, then the whole shape proved on the cheapest provider.

The framework change

The receiver machinery is written for concrete types, and reflect treats an interface differently in three ways at once:

  1. The two PointerTo promotions (pkg/op/helpers.go:258, pkg/op/receiver_type.go:357) yield a pointer to interface, whose method set is empty. Providers announcing method metadata fail loudly at init; file.Any, which announces nil, fails silently with zero methods.
  2. NewMethod cannot consume an interface method at all (pkg/op/method.go:178). reflect gives an interface method a nil Func and a Type with no receiver, so do.Type.In(0) returns the first parameter for Equal(other any) and panics for a no-arg method like Etag().
  3. Unexported methods become visible — NumMethod counts them only for interface types.

Point 2 is why "stop promoting interfaces" is not the fix. Split the one field doing two jobs:

  • the concrete *resource serves method enumeration, promotion, dispatch, and the byType key (receiver_registry.go:960), which must match reflect.TypeOf(value);
  • a stored typeID string, computed once from the interface at announce time, serves the typeIDOf(ProviderType()) == typeID comparisons at receiver_registry.go:486 and :513, which match an id lifted from a URI.

Those consumers sit on adjacent lines and want opposite things. With the concrete type restored, points 1 and 3 evaporate and UnpackerByTypeID works again for function, json, mem, yaml.

The concrete type is unexported, so it cannot come from the gen file — it is registered from inside the provider package, where pkg/op/provider/file/planspace.go already sets the precedent by naming *resource. The generated announcements do not change at all.

The receipt retyping failure — fix it here

ReceiptBase.Commit records canonicalIDOf(result), the produced value's dynamic type (pkg/op/receipt.go:438). ProductTypeByID resolves it against an index built from every action method's declared result type (receiver_registry.go:542). The two need not agree, and today they agree only by coincidence:

file.Move, Remove, RemoveAll, and Backup already return the Resource interface, so they record a concrete dynamic id such as *…/file.Regular. That resolves because file.Copy independently declares *Regular and contributes the key; *Directory comes from Mkdir, *SymbolicLink from Link.

Sealing removes the coincidence. The dynamic type becomes *…/file.regular — an unexported struct no method declares — so the lookup misses. And the miss is silent, because retypeStampedResult (pkg/op/recovery_stack.go:647) reads:

productType, ok := ReceiverRegistry().ProductTypeByID(s.resultType)
if !ok {
	return
}

A resumed run leaves the result as its raw decoded value — the bare URI string — instead of a resource. No error, no log.

This is not a bug the change introduces; it is a latent fragility the change converts into a live silent failure across every provider. Fix by recording the announced identity on both sides. Pin it with a resume that asserts the retyped result — asserting that resume merely succeeds proves nothing, since the failure path is a bare return.

The template: service

Zero files outside its own package name the type (confirmed 2026-08-24). Sealed Resource interface, unexported resource struct, constructors unchanged in signature. Resource.Name is a field read 20x in pkg/op/provider/service/provider.go, so the interface gains Name() string. All in-package.

Acceptance

  • The resources section and URIs are byte-identical for the same intent.
  • result_type loses its leading * for resource-bearing receipts and is pinned to the new value. Receipts with no result, or a non-resource result (file.WalkTree returns any), are untouched.
  • The judgment scenario lands here, red first: a dict supplied where a resource slot is expected mints an identity-less resource today via tryHydrateStruct (pkg/op/convert.go:441); it must fail conversion after. Red before the seal, green after — otherwise the correctness claim is argued rather than demonstrated.

Activity

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

    @David-Noble-at-work
    ContributorAuthor

    Related: #649 — every provider's ConvertFrom mints an identity-less resource. The seal does not remove those methods (they are in-package), but this phase changes their reachability: after sealing, Convert step 7's reflect.New(target) probe yields a pointer-to-interface with an empty method set, so TargetConverter no longer applies to resource slots. Worth confirming that as an observed effect while doing this phase, since it is half the argument in #649.

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