Skip to content

Commit ff33a2f

Browse files
author
David Noble
committed
wip(op): the type wrapper, wired at the graph slot seam (#712)
PRESERVES WORK IN PROGRESS. The tree is RED: three executor tests fail with "encodeTypeWrapper: $resource ... has no catalog to name it". Landed and green on its own: - pkg/op/type_wrapper.go — the wrapper codec. MongoDB Extended JSON's shape with Go-native names ($bool, $bytes, $float64, $int64, $list, $map, $nil, $resource, $string), string payloads for numerics. - pkg/op/type_wrapper_test.go — round trips over json and yaml, the 2^53+1 integer, +Inf/-Inf/NaN, bytes, a map keyed like a wrapper, and refusal of bare values and unknown type names. Wired, and six of the nine Phase 1 tests now pass: - marshalBindings wraps a slot value whose parameter is `any` or absent, and any non-finite float regardless of declared type. - assembleBindings unwraps structurally: a single $-prefixed key is a wrapper, everything else is a bare literal read against its field. Known wrong, to fix first next session: encodeResource reads the catalog from resource.RuntimeEnvironment(), which is the planning environment's, not the graph's. Graph.resourceCatalog's own doc says a serializer must read from the graph. The obstacle is that Node.MarshalYAML takes no context and the canonical form marshals nodes through it, so reaching graph.resourceCatalog needs a structural decision that has not been made. The plan document carries the full work-in-progress state: the uncommitted inventory, the devlore-test findings, and the open questions.
1 parent b17067b commit ff33a2f

6 files changed

Lines changed: 918 additions & 28 deletions

File tree

‎docs/plans/any-slot-types.md‎

Lines changed: 104 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,20 @@ therefore does not name a resource -- it names whichever generation is current a
6969
graph reloaded after a resource has been re-produced binds to a generation it never saw, while the generation
7070
it actually used is still in the ledger under its original id.
7171

72-
This is not confined to dispatch. `resolveDispatchResource` (`method.go:807`) has the same flaw for declared
73-
targets, but the codec path reaches it first: `discoverResource` is called from the resource's
74-
`UnmarshalJSON`, `UnmarshalText`, and `UnmarshalYAML` (`file/resource_base.go:389,420,446`, and the same shape
75-
in eight other providers). Retiring the dispatch path alone would not fix it.
72+
This is not confined to dispatch. Three paths re-identify by URI, and the codec one is reached first:
73+
74+
| Path | Location | Reached from |
75+
| --- | --- | --- |
76+
| `discoverResource` | nine providers' `UnmarshalJSON`/`UnmarshalText`/`UnmarshalYAML` | deserialization |
77+
| `resolveDispatchResource` | `method.go:807` | dispatch; one production caller, `method.go:725` |
78+
| `resolveRecordedResource` | `recovery_stack.go:678` | receipt rehydration on resume |
79+
80+
The third is the sharpest: it resolves a **recorded result** -- what a node actually produced on the original
81+
run -- so a resumed run can bind a generation that did not exist when the node ran. A produced resource is a
82+
historical fact with exactly one right entry.
83+
84+
The second and third are both gated on the target or product type implementing [Resource], so neither fires
85+
for an `any` slot at all, which is the gap finding 3's first row describes.
7686

7787
**Ruled: both are fixed at once** (filed as #735). Fixing the `any` case alone would leave one slot
7888
resolving correctly by id while the declared slot beside it drifts to the current generation -- one
@@ -155,6 +165,73 @@ Receipts and the recovery stack feed compensation and resume. A float that reloa
155165
changes a *compensating* call, which is worse than changing a forward one. One shared treatment at every
156166
`any` seam, not a local patch at `bindingData`.
157167

168+
## Work in progress — state as of 2026-08-28
169+
170+
**Branch:** `any-slot-types`. **Committed:** `b17067b` (Phase 1: the plan and nine failing tests).
171+
**Everything below this line is UNCOMMITTED and will be lost if the tree is discarded.**
172+
173+
### The tree is red, deliberately and not
174+
175+
Three executor tests fail: `TestRun_AKindMismatchStopsEvenUnderIgnore`,
176+
`TestRun_ScopedPreflightFailsOnConsumedMissingClaim`, `TestRun_ScopedPreflightVerifiesConsumedClaims`. All
177+
three fail with `op.encodeTypeWrapper: $resource ... has no catalog to name it` — the write side reaches for
178+
`resource.RuntimeEnvironment().ResourceCatalog`, which is the WRONG catalog (see below).
179+
180+
Six of the nine Phase 1 tests now pass. Still red: the truthiness guard (task 15), the Resource case, and the
181+
recovery-stack seam.
182+
183+
### Uncommitted files
184+
185+
| File | State |
186+
| --- | --- |
187+
| `pkg/op/type_wrapper.go` | New. The wrapper codec. Its own tests pass. |
188+
| `pkg/op/type_wrapper_test.go` | New. Round trips over both codecs, all green. |
189+
| `pkg/op/node.go` | Modified. `marshalBindings`/`assembleBindings` wrap and unwrap; signatures changed. |
190+
| `pkg/op/graph.go` | Modified. `assembleUnits` takes the environment. |
191+
| `pkg/op/binding_test.go` | Modified. Call sites updated for the new signatures. |
192+
| `pkg/op/provider/file/graph_shape_demo_test.go` | Scratch. Fails on purpose to print a doc. DELETE. |
193+
| `pkg/op/provider/file/resource_lifecycle_order_test.go` | Scratch. Does NOT compile; see below. |
194+
| `test_path_*` artifacts (repo root) | devlore-test litter. DELETE. |
195+
| `*/inventory.gen.go` (op and star) | Touched by `make` regeneration; verify before committing. |
196+
197+
### The correction the next session must apply first
198+
199+
`encodeResource` currently reads `resource.RuntimeEnvironment().ResourceCatalog`. That is wrong. The graph
200+
carries its own catalog and `Graph.resourceCatalog`'s doc comment says so explicitly: "every later
201+
session-owner (a Go-side `GraphExecutor.Run`, **a serializer**, an inspector) reads from `resourceCatalog`
202+
rather than from the long-gone planning environment."
203+
204+
The obstacle: `Node.MarshalYAML() (any, error)` takes no context, and the canonical form marshals nodes
205+
through exactly that path, so a node marshaling standalone cannot reach `graph.resourceCatalog`. Three
206+
options, none chosen: give `Node` a catalog reference at construction; resolve slot ids once at `NewGraph`;
207+
or route the canonical form through a graph-aware marshal instead of the node's own marshaler. **This is an
208+
open structural decision and belongs to the user.**
209+
210+
The read side threads `env.ResourceCatalog` through `assembleUnits`/`assembleNode`/`assembleBindings`, which
211+
is likewise probably the wrong catalog — the graph's own unpacked catalog is the right one.
212+
213+
### What the devlore-test investigation established
214+
215+
Run against real documents rather than reasoned about, and all of it now backed by artifacts:
216+
217+
- **A graph's immediate slots hold literals.** A resource produced by a node travels as a `promise` carrying a
218+
unit id. Confirmed against a two-node write-then-remove plan.
219+
- **A resource DOES reach an immediate slot** when the author passes a path to a `Resource`-typed parameter:
220+
plan-time coercion mints the entry, `resources:` gains `id: res-1`, and the slot records the **URI**. That
221+
document is #735 in one screen — the id the slot should use is eleven lines below it.
222+
- **Passing a path instead of a promise drops the dependency edge.** No `edges:` key is emitted, nothing
223+
orders the consumer after the producer, and scoped pre-flight then fails the consumer's claim. Not filed;
224+
see Open Questions.
225+
- **`mode: 420`** appears in a planner-produced document — #711 in the wild.
226+
227+
### Blocked on
228+
229+
- **#738** — `devlore-test` is broken (High/P1). Its `graph.yaml` is empty for any plan whose units return
230+
nil, the graph document is written to the stream named `receipt`, and no execution trace is persisted. That
231+
last point blocks observing a resource's `Pending` to `Active` transition, which is a test this plan needs.
232+
- **A missing accessor.** `GraphExecutor` exposes no `RuntimeEnvironment()`, so a test cannot reach the run's
233+
catalog to assert resource state. Whether that is a gap or an intended restriction is unanswered.
234+
158235
## Requirements
159236

160237
### Requirement 1: Every value in an `any` slot is enveloped
@@ -470,6 +547,27 @@ the executor's pre-flight resolve pass through `VerifyExistence`, and by nothing
470547
When a consumer does find a resource missing at run time, [MissingResourcePolicy] governs: `Stop` or `Ignore`,
471548
`Stop` winning aggregation across the consumers of one entry, with a warning emitted under every policy.
472549

550+
### 9. The wrapper is in the canonical form, and that is what makes reload stable
551+
552+
Measured rather than assumed. `Graph.canonicalForm` marshals the live `*Node` values
553+
(`graph.go:830-851`), `Node.MarshalYAML` returns `n.marshalData()` (`node.go:203`), and `marshalData` fills
554+
its slots through [marshalBindings]. Wrapping in [marshalBindings] therefore puts the wrapper into the
555+
canonical form as well as the document.
556+
557+
Three consequences, all wanted:
558+
559+
- **The checksum changes** for every graph holding an immediate slot value. Greenfield, so no document needs
560+
to keep validating; the Migration section already states this.
561+
- **The canonical form becomes codec-independent.** It now carries explicit types, so a graph written as json
562+
and the same graph written as yaml canonicalize identically even for values the two codecs disagree about.
563+
That is what the "JSON and YAML agree" goal has been asking for.
564+
- **It fixes #734 at the root.** A reloaded `{"$float64": "42"}` resolves to `float64(42)`, which re-wraps to
565+
the identical bytes, so the recomputed checksum matches the stored one. The regression exists precisely
566+
because a `json.Number` re-canonicalized differently from the `float64` that was written.
567+
568+
The last point is the load-bearing one: the wrapper is not merely tolerated by the checksum, it is what makes
569+
save and reload agree at all.
570+
473571
### Out of scope, and why
474572

475573
`converter.go:446` collapses `*starlark.List`, `starlark.Tuple`, and `*starlark.Set` into a single
@@ -597,6 +695,7 @@ change already read back wrong; Phase 4 makes them fail loudly instead of quietl
597695

598696
| File | Action | Purpose |
599697
| --- | --- | --- |
698+
| `pkg/op/type_wrapper.go` | Create | The wrapper codec (**landed**, green) |
600699
| `pkg/op/convert.go` | Modify | Resolve an enveloped value at the `any` seam |
601700
| `pkg/op/truthiness.go` | Modify | `json.Number` case in `scalarTruthy` as a guard rail |
602701
| `pkg/op/node.go` | Modify | Envelope `bindingData.Value` |
@@ -608,6 +707,7 @@ change already read back wrong; Phase 4 makes them fail loudly instead of quietl
608707
| `pkg/op/method.go` | Modify | Retire `resolveDispatchResource`'s URI lookup for slots |
609708
| `pkg/op/provider/*/resource*.go` | Modify | Retire `Discover(uri)` on unmarshal for slot values |
610709
| `pkg/op/any_slot_types_test.go` | Create | Phase 1: one failing test per finding (**landed**) |
710+
| `pkg/op/type_wrapper_test.go` | Create | Wrapper round trips, both codecs (**landed**, green) |
611711
| _every float position_ | Modify | Non-finite floats envelope regardless of declaration (Requirement 2) |
612712

613713
## Related Documents
@@ -623,6 +723,3 @@ change already read back wrong; Phase 4 makes them fail loudly instead of quietl
623723
- Issue #443 -- Epic: Serialization and the single codec
624724

625725
## Open Questions
626-
627-
- [ ] Does Phase 3 change the *canonical* form used for checksums, or only the serialized bytes? #711 is
628-
already answering an adjacent version of this and the answers should match.

‎pkg/op/binding_test.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,15 @@ func TestBindings_DocumentRoundTrip_PreservesField(t *testing.T) {
5656

5757
// nil action: these are variable bindings, which name a variable rather than carrying a value, so
5858
// no declared parameter type is consulted.
59-
reloaded := assembleBindings(marshalBindings(bindings), nil)
59+
marshaled, err := marshalBindings(bindings, nil)
60+
if err != nil {
61+
t.Fatalf("marshalBindings: %v", err)
62+
}
63+
64+
reloaded, err := assembleBindings(marshaled, nil, nil)
65+
if err != nil {
66+
t.Fatalf("assembleBindings: %v", err)
67+
}
6068

6169
projected, ok := reloaded["projected"].(VariableBinding)
6270
if !ok {

‎pkg/op/graph.go‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,18 +368,24 @@ func SerializeGraphs(w io.Writer, graphs []*Graph) (err error) {
368368
// existence with its action already bound — NewNode / NewSubgraph's assert.NonZero invariant holds.
369369
//
370370
// Parameters:
371+
// - `env`: the run environment whose catalog a `$resource` id resolves against.
371372
// - `p`: the decoded graph payload.
372373
//
373374
// Returns:
374375
// - `map[string]ExecutableUnit`: the unit table, keyed by ID.
375376
// - `error`: the joined per-unit assembly failures, or nil.
376-
func assembleUnits(p *graphData) (map[string]ExecutableUnit, error) {
377+
func assembleUnits(env *RuntimeEnvironment, p *graphData) (map[string]ExecutableUnit, error) {
378+
379+
var catalog *ResourceCatalog
380+
if env != nil {
381+
catalog = env.ResourceCatalog
382+
}
377383

378384
var violations []error
379385
unitsByID := make(map[string]ExecutableUnit, len(p.Nodes)+len(p.Subgraphs))
380386

381387
for i := range p.Nodes {
382-
node, err := assembleNode(&p.Nodes[i])
388+
node, err := assembleNode(&p.Nodes[i], catalog)
383389
if err != nil {
384390
violations = append(violations, err)
385391
continue
@@ -433,7 +439,7 @@ func assembleGraph(env *RuntimeEnvironment, p *graphData) (*Graph, error) {
433439
// recomputed checksum matches the document's; re-deriving here would drop hand-authored, non-slot-producer edges.
434440
root.edges = p.Edges
435441

436-
unitsByID, err := assembleUnits(p)
442+
unitsByID, err := assembleUnits(env, p)
437443
if err != nil {
438444
return nil, err
439445
}
@@ -986,7 +992,11 @@ func (g *Graph) marshalData() (graphData, error) {
986992

987993
nodePayloads := make([]nodeData, 0, len(descendantNodes))
988994
for _, n := range descendantNodes {
989-
nodePayloads = append(nodePayloads, n.marshalData())
995+
nodePayload, err := n.marshalData()
996+
if err != nil {
997+
return graphData{}, err
998+
}
999+
nodePayloads = append(nodePayloads, nodePayload)
9901000
}
9911001

9921002
content, err := g.packContent()

0 commit comments

Comments
 (0)