Skip to content

fix: resolve container-qualified bindings for unchecked parsed eval - #196

Open
detail-app[bot] wants to merge 6 commits into
mainfrom
detail/bug-fix/fix-resolve-container-qualified-bindings-for-unche-0835f6
Open

detail-app[bot] wants to merge 6 commits into
mainfrom
detail/bug-fix/fix-resolve-container-qualified-bindings-for-unche-0835f6

Conversation

@detail-app

@detail-app detail-app Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Detail bug report: View on Detail

Change

Closes #173

For parsed (unchecked) EvalRequests — which carry no type_env, so free identifiers are not pre-resolved at plan time — EvalContext.rootBinding resolved root identifiers by a single exact-key lookup against the activation and ignored EvalRequest.container. As a result:

  • For Parse "y" then Eval(parsed_expr, container="x", bindings={"x.y": bool true, "y": string "false"}), the server returned string "false" (bare y shadowed x.y); the cel-spec corpus cases self_eval_container_lookup / self_eval_container_lookup_unchecked require bool true.
  • With only {"x.y": true} bound, evaluation errored with no value for variable: y because the container-qualified key was never tried.

The container-prefix walk existed only at plan time in Environment.resolve, and only over declared names — but a parsed EvalRequest has no declarations, so the walk never ran. This silenced the intent of EvalRequest.container and affected any dynamic caller that imports a canonical ParsedExpr AST (introduced in the genesis commit 9af3c5c). Per the CEL spec, the container scopes must be tried, innermost first, before the bare name.

Fix

In EvalContext, runtime root-identifier resolution now walks environment.container prefixes innermost-first (e.g. x.y, then y for container x) against the activation before falling back to the bare name, mirroring the existing plan-time Environment.resolve semantics:

  • getRoot/rootBinding(String, boolean) carry an absolute flag so absolute references (.y) skip the walk.
  • New @TruffleBoundary-annotated helpers resolveRoot (map-backed activation path) and matchesRoot (single-binding Scoped/Object[] fast paths) perform the walk.
  • The @TruffleBoundary annotation matches the existing slow-path idiom (absoluteName, getLocal, undeclared, lookup are already boundary-annotated) and keeps the walk's string concatenation out of JIT-compiled ASTs. Without it, Graal inlined the walk into the compiled MatchesNode and bailed out with PermanentBailoutException: Too deep inlining, regressing :noRe2jConsumer.

The checked-expr path is unchanged: the checker still rewrites identifiers to qualified names at plan time, and the runtime walk does not alter already-resolved names.

Validation

New regression tests (committed):

  • src/test/java/dev/trufflecel/ContainerResolutionTest.java (engine-level): container-qualified wins over bare; qualified-only resolves; bare-only still resolves; genuinely missing identifier still throws UNDECLARED (after walking the container); nested container a.b walks innermost-first; multiple roots each resolve through the container; absolute .y skips the walk; checked path unchanged; empty container falls back to the bare name; Activation.snapshot single-entry fast path resolves qualified keys.
  • tools/conformance/ConformanceServerTest.evalParsedExprResolvesContainerQualifiedBindings (gRPC end-to-end, in-process server): both-present, qualified-only, and bare-only cases against ConformanceServer.eval with a parsed_expr wire form and container="x".

Both new tests fail on the unpatched tree (bare "false" wins / spurious undeclared) and pass with the fix.

Routine checks: bazel build --config=local //:trufflecel //:trufflecel-protobuf //:trufflecel-json //:trufflecel-processor, bazel run --config=local //tools:format -- --check, and bazel run --config=local //bazel/gazelle:check all pass.

Suite verification: the full 2,771-case cel-spec conformance corpus (including the exact namespace/self_eval_container_lookup / _unchecked cases), the negative matrix, runtime, checker, canonical-ast, borrowed-bindings, partial-evaluation, policy (compiler + conformance), extensions, function-overload, lazy-binding, validation, CSE, ast-interchange, activation, environment-controls, pojo, pojo-processor, protobuf-integration, prepared-field, data-integration, interop, library-policy, late-function, map-snapshot, optional-value, nullable-typing, diagnostics, cost-estimator, custom-validator, boundary, foreign-ordinal-bug, polyglot-error-type-repro, ast-location, ast-macro, ast-validation, error-location, evaluation-controls, environment-yaml, parser-recovery, parser, encoder, re2-nested-pattern-repro, regex-acceleration, truffle-regex-only, and tools/fuzz:regression / evaluation_regression / smoke all pass.

JIT gate: :noRe2jConsumer (forces engine.CompilationFailureAction=Throw + compiler.TreatPerformanceWarningsAsErrors=all and hot-loops a regex match) initially regressed with the naive fix — Graal bailed out Too deep inlining on the inlined container walk. Adding @TruffleBoundary to the new helpers restored it; confirmed passing 3× with --runs_per_test=3 --flaky_test_attempts=3, and the baseline also passes identically. :traceAsync and :instrumentation pass as well.

Limitations / env notes:

  • The GraalVM JIT tests (:traceAsync, :instrumentation, :noRe2jConsumer) require a writable polyglot cache inside the Bazel sandbox; locally they need --test_env=POLYGLOT_USER_CACHE=<dir> --sandbox_writable_path=<dir> with the directory pre-created and chmod 777. Without it they fail with the resource cache folder /root/.cache/org.graalvm.polyglot is not a readable and writable directory. This is an environment requirement, not affected by the change.
  • Linux native guest-JIT/blocklist CI gates (bazel test //benchmarks:jit_smoke) were not exercised in this sandbox; per CONTRIBUTING.md the JVM pass alone does not establish Native Image compatibility.

Automatic Fixes PRs can be configured here.

import org.junit.Test;

/** Runtime container-qualified binding resolution for unchecked/parsed evaluation. */
public final class ContainerResolutionTest {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in edc1165: dropped the added @TruffleBoundary from rootBinding so the compiled root-resolution fast path matches the pre-PR allocation profile (restores the benchmarks:compiled budget); the new container-walk helpers stay @TruffleBoundary. Also added NullMarked to ContainerResolutionTest (+ @maven//:org_jspecify_jspecify dep) to satisfy RequireExplicitNullMarking.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up in 0a257a0: reverted the NullMarked addition. It can't land cleanly here — strict deps requires a direct @maven//:org_jspecify_jspecify dep, but Gazelle auto-removes that dep as transitively-satisfied, so the two checks conflict. The RequireExplicitNullMarking finding is WARN-level (code-scanning), not a CI failure (trufflecheck passed without the annotation), so a human can decide later whether to adopt NullMarked package-wide.

@codspeed

codspeed Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 21 untouched benchmarks


Comparing detail/bug-fix/fix-resolve-container-qualified-bindings-for-unche-0835f6 (d3955b4) with main (a31f1c5)

Open in CodSpeed

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@datadog-official

datadog-official Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Pipelines

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: d3955b4 | Docs | Give us feedback!

detail-app Bot added 5 commits November 17, 2026 12:22
Drop @TruffleBoundary from rootBinding so the compiled fast path for
container-less root resolution matches the pre-PR allocation profile
(benchmarks:compiled budget). The new container-walk helpers stay
behind @TruffleBoundary.

Add @NullMarked to ContainerResolutionTest to satisfy
RequireExplicitNullMarking.
Gazelle resolves org.jspecify.annotations transitively via //:trufflecel
(-> truffledata-core -> jspecify), so the explicit @maven dep on
containerResolution is unused and fails the gazelle check. @NullMarked
remains on the test class to satisfy RequireExplicitNullMarking.
The @NullMarked annotation conflicts with the repo's Gazelle config
(strict deps require a direct @maven//:org_jspecify_jspecify dep, but
Gazelle auto-removes it as redundant). The RequireExplicitNullMarking
finding is WARN-level code-scanning, not a CI failure, and trufflecheck
passed without it.
The boundary-annotated container walk in rootBinding was invoked on
every root resolution, including programs with the default empty
container. That added per-evaluation allocation and pushed the compiled
benchmark x * 2 + 1 > 100 from 64 to 80 bytes/evaluation, exceeding its
budget.

Gate the walk behind environment.container.isEmpty() so compiled code
takes the original inline single.equals / lookup fast path when no
container prefixes exist. The boundary helpers run only when a
container is actually present, preserving the container-qualified
resolution semantics for unchecked parsed eval.
The container-qualified root-resolution fast paths added to
EvalContext.rootBinding (String-single Object[] path and Scoped
single-name path) only exercised the matching case in
singleEntryActivationResolvesContainerQualifiedKey. The no-match
branch (matchesRoot returns false -> null -> UNDECLARED) was
uncovered, which dropped production branch coverage to 99.78%,
under the 99.8% gate.

Add singleEntryActivationMissingIdentifierErrorsAfterContainerWalk
which evaluates a parsed 'y' with container 'x' against a single
Activation.snapshot binding 'z' that matches neither 'x.y' nor
'y', exercising both the Object[] fast path (no-options evaluate)
and the Scoped single-name path (options-driven evaluate), each
expected to raise UNDECLARED after walking the container.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Detail Bug] Conformance gRPC: parsed (unchecked) eval ignores container-qualified bindings

2 participants