Repository navigation
Description
Problem
WalkTree's Reducer signature is designed for Go-side compensable operation chains:
type Reducer func(initial any, resource Resource, relativePath string, stack *op.RecoveryStack) (result any, err error)This is unusable from Starlark for two reasons:
resourcemarshals as a full struct — Starlark callers just need a file path, not afile.Resourcewith SourcePath, Checksum, Size, Mode, etc.- The accumulator pattern is too complex — Starlark scripts want a simple callback, not a fold/reduce with
initialandstack.
Proposed Redesign
Unify resource and relativePath into a single source file.Resource parameter. The Resource already contains the path — relativePath is redundant. The new signature:
type Reducer func(initial any, source file.Resource, stack *op.RecoveryStack) (result any, err error)For Starlark consumption:
sourceshould marshal as a path string (the absolute path), not the full structstackshould not be visible to Starlark callers — the framework should suppress it or pass nil- The accumulator pattern may need a simpler alternative for scripts that just want per-entry callbacks
Context
file.Findwas added as a non-callback alternative for recursive file discovery (**patterns)- The callable bridge (
buildCallableFunc) can marshal Starlark functions to Go functions, so WalkTree could work from Starlark — but the Reducer signature makes it impractical - See plan:
docs/plans/star-provider-migration.md
Design Analysis (2026-03-26)
Callable contract
Every Starlark callable returns (starlark.Value, error) — one result or an error (via fail()). There is no multi-return. This means:
- The Go
Reducersignature(any, Resource, string, *RecoveryStack) → (any, error)cannot be directly bridged unmarshalReturnin the callable adapter currently handles multi-return Go signatures that Starlark can never produce — the middle-return zero-filling is dead code- The honest callable adapter is: call → if error, return it → unmarshal the single value
Two worlds, one action
WalkTree serves two use cases with different constraints:
| Go (graph action) | Starlark | |
|---|---|---|
| Reducer signature | func(acc any, resource Resource) (any, error) |
def reducer(acc, resource) -> acc |
| Error signaling | Return error |
fail("message") → becomes Go error |
| Resource access | Full Resource struct |
StructValue with path attrs |
| Compensation | Not applicable | Not applicable |
WalkTree is a FallibleAction, not a CompensableAction
WalkTree is a query — it walks the tree and accumulates a result. It does not mutate. The RecoveryStack and relativePath parameters should be removed from both WalkTree and Reducer:
RecoveryStack: mutations belong in downstream graph steps, not inside the walkrelativePath: redundant —Resource.SourcePathcarries both.Abs()and.Rel()afterResolve
New signatures:
type Reducer func(acc any, resource Resource) (any, error)
func (p *Provider) WalkTree(root Resource, fn Reducer, honorGitignore bool) (any, error)Mutating operations (writes, copies, moves) should occur downstream from WalkTree as separate graph steps driven by its result value. Those downstream actions are individually compensable through the normal action bridge.
Conclusion
The compensability of a walk is determined by the mutations that follow it, not by the walk itself. The walk accumulates; the graph acts on what was accumulated.
- Go:
Reducerreceives(acc, resource)and returns(any, error). Pure accumulation. - Starlark:
def reducer(acc, resource) -> acc. Same contract, simpler surface.
The adapter wraps the Starlark function into a Go Reducer, marshaling Resource to a StructValue.
Related refactoring
buildCallableFunc, unmarshalReturn, and makeErrorReturn have been moved from marshal.go to callable.go — they are callable-specific, not general marshal utilities. The doc comments and implementation need further tightening to reflect that a callable always returns (starlark.Value, error).
Activity
feat(file): Add Find method for recursive file discovery with ** patt…
feat(file): Add Find method for recursive file discovery with ** patt…
David-Noble-at-work commentedon Oct 1, 2026
The signature may not be the problem. Measured 2026-10-01.
This issue's analysis predates the
function.Resourcework, and that work already built the bridge it proposes.Starlark-to-Go func conversion exists and is reachable. What is missing is one step earlier than the
Reducerredesign described above.What happens today
Calling
file.walk_treefrom a linter extension -- the ambient surface, not the plan surface:Why, precisely
op.Converthas ten steps, and step 5 is the bridge:function.Resourceimplements exactly that --CanConvertToandConvertTo, the latter documented as"Converts to any Go func type by building a bridge that converts arguments, calls the underlying starlark
function, and converts the result." It validates parameter counts, rejects varargs and kwargs, and accepts
Go returns of
(),(T),(error)or(T, error).So the conversion works when the value IS a
function.Resource. What arrives from an ambient call is abare
*starlark.Function, which implements noSourceConverter, so it falls through all ten steps toexplainRefusal.On the plan surface a lambda is desugared into a content-addressed
function.Resourcefirst, which is whycmd/devlore-test/devloretest/data/test_function_call_walk_tree.starworks:Its own comment says so: "a lambda desugars to the new
function.callaction and rides the graph as acontent-addressed
function.Resource." Nothing does that wrapping on the ambient path.The missing piece is the desugaring, not the signature
Either
op.Convertgains a step that wraps a*starlark.Functionin afunction.Resourcewhen the target isa func type, or the ambient receiver path does that wrapping before calling
Convert. Thenfile.walk_treeworks from a linter with its signature unchanged.That is worth settling before the
Reducerredesign this issue proposes, because the redesign is justifiedhere by "the accumulator pattern is too complex" and "
resourcemarshals as a full struct" -- and if the onlyreal blocker is a missing wrap, those are ergonomics arguments rather than blockers. They may still be worth
doing; they are a different change from making it work.
Also stale above:
buildCallableFuncno longer exists by that name. Its capability moved intofunction.Resource.ConvertToandbridgeable, so the sentence "the callable bridge (buildCallableFunc) canmarshal Starlark functions to Go functions" is still TRUE in substance and wrong in the identifier.
How this surfaced
devlore-cli#994 Phase 5 needed one tree traversal instead of 39
file.findcalls -- 39 patterns of which 34match no file in this repository, measured at 4.3 s warm against 1.1 s with four.
file.walk_treewas theobvious instrument and refused. The work landed on a single
file.find(path + "/**/*")instead, which thisissue itself names as the sanctioned alternative: "
file.Findwas added as a non-callback alternative forrecursive file discovery." Measured equivalent -- 1,016 files both ways, 4.3 s to 0.91 s warm -- so #994 is
not blocked. But a linter that wants to fold over a tree still cannot.
Related: #945 (the traversal surface has no link predicate) and #170 (closed; the same problem seen from the
binding generator's side, and its closing note already said "the reflection bridge needs to support
starlark.Callableas a parameter type").David-Noble-at-work commentedon Oct 1, 2026
Researched exhaustively 2026-10-01. The marshaling question is settled, and the fix proposed in March does not work
Fourteen agents, every claim below traced to source rather than inferred. Two conclusions, and the second
kills the approach this issue has been carrying.
1.
*op.RecoveryStackmarshals into Starlark.file.Reducerdoes NOT need a new signatureThe doubt that blocked this -- "a script has no business seeing a RecoveryStack, so the signature must
change" -- does not fire. The chain, read end to end:
function.resource.ConvertTobuildsreflect.MakeFunc(target, ...)and unwraps each argument witharg.Interface()(pkg/op/provider/function/resource.go:695-701) ->invoker.CallStarlarkconverts eachargument via
converter.toStarlark(pkg/op/starlarkbridge/invoker.go:79-89) ->toStarlarkfalls throughto
toStarlarkReflect(go_receiver.go:342-353) ->elem()dereferences the non-nil pointer to anaddressable struct (
go_receiver.go:413) ->structToStarlarktakesrv.Addr()and resolves a receiver type(
go_receiver.go:739-770).The derive cannot fail:
TypeByReflectionOrDerivefalls back toNewReceiverType(t, nil)on error(
receiver_registry.go:679-690), which routes toderivedMethods, which skips an unclassifiable methodrather than aborting -- and its own doc comment names
RecoveryStack.ResultByUnitIDas the case(
receiver_type.go:535-578).structToStarlark's comment at:726-731names "a framework type like*op.RecoveryStackhanded to a reducer" as its motivating example. Pointer identity survives viarv.Addr(),so the reducer sees the live stack.
Shape also passes:
file.Reduceris 4-in/2-out with error last (provider.go:2565), so bothresource.go:637(NumParams == NumIn) andresource.go:675-684(hasError,numValues <= 1) accept it.Keeping the 4-parameter shape also keeps all five existing
.starfixtures valid. Changing arity breaksevery one with no escape hatch, because
resource.go:637-645refuses a count mismatch and refuses*argsand**kwargsoutright.2. Wrapping the callable in a
function.Resourcecannot workThis was the plan. It fails for two independent reasons.
It is a snapshot, not a bridge.
synthesizeemits onlyfn.NumFreeVars()bindings plus the def text(
synthesize.go:41-82), andcompileSourceresolves withisPredeclaredhard-wired tofunc(string) bool { return false }(resource.go:952-958). Checked against starlark-go's resolver ratherthan assumed: a reference reaching the file block returns Global/Predeclared/Universal, and a FreeVar is
created only for a Local/Free/Cell binding of an enclosing function (
resolve/resolve.go:954-996,useToplevelat:415-454). So a top-leveldefreading a module-level variable hasNumFreeVars() == 0,nothing is emitted, and the synthesized program fails with
undefined: <name>.Not hypothetical.
cmd/devlore-test/devloretest/data/test_walk_tree_closure.star:17-24setsext = ".py"atmodule level and reads it inside
def filter_by_ext(...). That fixture cannot work through the archivalpath in either immediate or plan mode. A real linter reducer is worse:
com.noblefactor.star.LintCopyright/commands/lint-copyright.starreads module globals, calls sibling modulefunctions, and calls provider predeclareds (
file.read_text,regex.match) -- every one undefined in thesynthesized module. The archival wrap would deliver a feature that works only for a reducer using nothing but
its own parameters and Universe builtins.
It imports side effects into a read-only surface.
buildCandidateruns before the catalog is consulted(
resource.go:178-189), andnewFromSourceunconditionally doesMkdirAll(0700)+WriteFile(0600)of apack into
<root>/.devlore/function/resource/sha256/<xx>/<hex>on every call -- per call, not per distinctfunction, because the catalog dedupes only the entry (
resource_catalog.go:304-312). It callsruntimeEnvironment.Root()with noHasRootguard, andRoot()panics viaassert.Failffor aroot-less session (
runtime_environment.go:341-346). It re-reads and re-parses the user's.starfileunsandboxed on every call (
synthesize.go:174-180). Understarthe root isos.Getwd()(
cmd/star/extension/application.go:71-89), so a lint pass would litter the working tree.3. The answer is a live bridge, and the layering permits it
starlarkbridge.NewInvoker()is explicitly environment-free (invoker.go:39-50): no root, no disk, nocatalog, and the callable keeps its own module, so globals, sibling functions and predeclareds all resolve.
Layering verified by grep, not assumed:
starlarkbridgeimportspkg/op(go_receiver.go:16) and imports noprovider;
pkg/opnever importsstarlarkbridge(only doc-comment mentions atgraph_executor.go:360andruntime_environment.go:45). So aninit()instarlarkbridgeregistering intoopis cycle-free, in theshape
op.RegisterPlanPathNormalizeralready uses (pkg/op/plan_path.go:18-74).Placement:
op.Convert, immediately beforereturn nil, explainRefusal(value, target)(convert.go:137),gated on
target.Kind() == reflect.Func. It must sit afterconvertDirect(convert.go:84) so ananytarget short-circuits at
convert.go:209-- that is what keeps the two lambda desugar sites that type-assertthe raw
*starlark.Functionworking (plan/provider.go:683-690,flow/planners.go:737-745). It must readvalue, not theelemderef atconvert.go:88-91(a*starlark.Functionderefs to a struct). It must sitafter step 5 so a real
function.Resourcestill routes through its ownConvertTo.Nothing changes in plan mode:
bindAuthoredValuewraps to afunction.ResourcebeforeConvertever runs(
planner.go:436-447), so the new step never sees a bare*starlark.Functionthere.4. Two things that must land in the same commit
A pre-existing panic becomes reachable.
funcReturndoesout[0] = reflect.ValueOf(result).Convert(target.Out(0))with no nil guard (resource.go:1018-1031), andconverter.go:424-425mapsstarlark.NoneTypeto Go nil. So a reducer that returnsNone-- or simply fallsoff the end, which Starlark allows -- panics inside reflect rather than erroring. Today
Convertrefusesbefore the bridge exists, so author code cannot reach it. This change makes it reachable on every call.
A recorded ruling must be amended, not contradicted silently.
docs/plans/extract-starlark-from-op/phase-8/steps/25-function-values-bridge.md:20reads: "(b) dispatch-timelanded as a
SourceConverteropt-in, not areflect.Funcbranch insideConvert." That rejection was aimedat a step with environment-dependent side effects; a pure live bridge has none. The ruling still has to be
amended in the same commit that reopens it.
Honest caveat on this research
It was framed as "is the wrap sufficient" -- a minimality framing that was ruled against mid-flight. Its
substance rejected the cheap fix anyway, on correctness, and chose the more invasive bridge. So the conclusion
survives the framing, but this is a mechanism answer, not a comparison of designs. A four-design judge panel
is scripted and cached if the design space is worth opening.
David-Noble-at-work commentedon Nov 9, 2026
star github triage sweep added this issue to Triage: devlore, for the rule it breaks:
no-evidence: no Evidence of completion section