You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Follow-up to #89 (PR #144). #89 added ctx context.Context as the first arg to Compiler.Compile, Loader.GetReader, and script.NewExecutableUnit, but stopped one layer short of the public consumer surface. The three FromXxxLoader constructors and the top-level polyscript.New[E] still don't accept a ctx, so they inject context.Background() inline when calling NewExecutableUnit:
Same pattern in engines/risor/new.go and engines/starlark/new.go. The ctx-threaded path through Loader.GetReader(ctx) and Compiler.Compile(ctx, reader) ends up exercising a never-cancellable Background() for every caller using the documented public API.
What this means in practice
The HTTP-loaded compile problem #89 set out to solve — "compile can hang indefinitely because nothing reaches for the cancellable variant" — is not actually fixed for the public consumer surface. We moved the context.Background() injection point from inside the loader to the caller side of NewExecutableUnit, but nobody using polyscript.New[E] or FromExtismLoader/FromRisorLoader/FromStarlarkLoader can supply a cancellable ctx today.
Fixes 1 and 2 from #89 (Extism's stored-ctx field, Risor's hard-coded Background() in the inner parser) are real and complete. Fix 3 (HTTP cancellation) is only reachable by callers who drive script.NewExecutableUnit directly — a building-block API that the docs steer people away from.
All consumer tests — pass t.Context() or equivalent
Acceptance
grep -rn 'context\.Background()' --include='*.go' . finds no production hits in the public construction path (the inline injections in engines/{extism,risor,starlark}/new.go are gone)
A user can supply ctx, cancel := context.WithTimeout(...) to any public constructor and have the cancel actually reach Loader.GetReader/Compiler.Compile
Spot-check: cancelling a ctx during an HTTP-loaded compile actually halts the fetch
Notes
This is a v1 breaking change to the four most-used public constructors.
Summary
Follow-up to #89 (PR #144). #89 added
ctx context.Contextas the first arg toCompiler.Compile,Loader.GetReader, andscript.NewExecutableUnit, but stopped one layer short of the public consumer surface. The threeFromXxxLoaderconstructors and the top-levelpolyscript.New[E]still don't accept actx, so they injectcontext.Background()inline when callingNewExecutableUnit:Same pattern in
engines/risor/new.goandengines/starlark/new.go. The ctx-threaded path throughLoader.GetReader(ctx)andCompiler.Compile(ctx, reader)ends up exercising a never-cancellableBackground()for every caller using the documented public API.What this means in practice
The HTTP-loaded compile problem #89 set out to solve — "compile can hang indefinitely because nothing reaches for the cancellable variant" — is not actually fixed for the public consumer surface. We moved the
context.Background()injection point from inside the loader to the caller side ofNewExecutableUnit, but nobody usingpolyscript.New[E]orFromExtismLoader/FromRisorLoader/FromStarlarkLoadercan supply a cancellable ctx today.Fixes 1 and 2 from #89 (Extism's stored-ctx field, Risor's hard-coded
Background()in the inner parser) are real and complete. Fix 3 (HTTP cancellation) is only reachable by callers who drivescript.NewExecutableUnitdirectly — a building-block API that the docs steer people away from.Proposal
Add
ctx context.Contextas the first arg to:polyscript.New[E](ctx, source, opts...)— top-level generic constructorextism.FromExtismLoader(ctx, ldr, opts...)risor.FromRisorLoader(ctx, ldr, opts...)starlark.FromStarlarkLoader(ctx, ldr, opts...)Each forwards its
ctxstraight intoscript.NewExecutableUnit. The threecontext.Background()injections in the enginenew.gofiles go away.Files
polyscript.go—New[E]signatureengines/{extism,risor,starlark}/new.go—FromXxxLoadersignatures + drop the inlinecontext.Background()deprecated.go— the legacyFromRisor*/FromStarlark*/FromExtism*constructors (decide: also take ctx, or leave on theBackground()shim until [v1][breaking] Remove deprecated top-level constructors (deprecated.go) #104 removes them)examples/— passctxt.Context()or equivalentAcceptance
grep -rn 'context\.Background()' --include='*.go' .finds no production hits in the public construction path (the inline injections inengines/{extism,risor,starlark}/new.goare gone)ctx, cancel := context.WithTimeout(...)to any public constructor and have the cancel actually reachLoader.GetReader/Compiler.CompileNotes