Summary
Declaring an extra global on the Risor compiler via WithGlobals([]string{"request"}) makes every Eval fail with missing required globals: [request], even for scripts that never reference the global. This contradicts the option's documentation ("declare additional global identifiers the script may reference at evaluation time").
Root cause
engines/risor/compiler/internal/compile/compile.go:39-55 puts custom globals into the compile-time env, so Risor v2 records them in Code.EnvKeys().
engines/risor/evaluator/evaluator.go:131 builds the runtime env as only Builtins() + ctx (internal.BuildRisorEnv), so the declared global is absent at run time.
- Risor v2's
Run → validateGlobals then rejects the run because a declared global key is missing from the runtime env.
Likely a Risor v1→v2 migration regression: v2 added strict global validation that v1 lacked. Starlark's equivalent degrades gracefully — it fails only if the script actually references the missing name.
Reproduction (confirmed)
Compiler built with WithCtxGlobal(), WithGlobals([]string{"request"}); script 1 + 2 (never references request):
exec error: risor execution error: missing required globals: [request] (...)
Impact
High — a public compiler API is unconditionally broken. Any use of WithGlobals with a name other than ctx makes evaluation impossible.
Fix
Plumb the declared globals list through the executable and have the evaluator inject nil/None placeholders for each into the runtime env, satisfying validateGlobals. Alternatively, reject non-ctx globals at compiler construction with a clear error. Add tests: declare a global and don't reference it (assert Eval succeeds); declare, reference, and supply it (assert the value is visible).
Summary
Declaring an extra global on the Risor compiler via
WithGlobals([]string{"request"})makes everyEvalfail withmissing required globals: [request], even for scripts that never reference the global. This contradicts the option's documentation ("declare additional global identifiers the script may reference at evaluation time").Root cause
engines/risor/compiler/internal/compile/compile.go:39-55puts custom globals into the compile-time env, so Risor v2 records them inCode.EnvKeys().engines/risor/evaluator/evaluator.go:131builds the runtime env as onlyBuiltins()+ctx(internal.BuildRisorEnv), so the declared global is absent at run time.Run→validateGlobalsthen rejects the run because a declared global key is missing from the runtime env.Likely a Risor v1→v2 migration regression: v2 added strict global validation that v1 lacked. Starlark's equivalent degrades gracefully — it fails only if the script actually references the missing name.
Reproduction (confirmed)
Compiler built with
WithCtxGlobal(), WithGlobals([]string{"request"}); script1 + 2(never referencesrequest):Impact
High — a public compiler API is unconditionally broken. Any use of
WithGlobalswith a name other thanctxmakes evaluation impossible.Fix
Plumb the declared globals list through the executable and have the evaluator inject
nil/Noneplaceholders for each into the runtime env, satisfyingvalidateGlobals. Alternatively, reject non-ctxglobals at compiler construction with a clear error. Add tests: declare a global and don't reference it (assertEvalsucceeds); declare, reference, and supply it (assert the value is visible).