xai-org/x-algorithm · error · ValueError

Cannot lower a compiled jit function.

Error message

Cannot lower a compiled jit function.

What it means

A small wrapper around jitted functions forbids calling lower() on an object that is already a Compiled executable: lowering is only valid on an uncompiled jit function. This guards the AOT pipeline from double-processing an already-compiled artifact.

Source

Thrown at phoenix/xrex/utils/aot.py:672

        }

        return compiled

    metrics: Dict[str, Dict[str, float]] = {}
    all_compiled = {n: _compile_or_load(n, t, metrics) for n, t in all_traced.items()}
    return all_compiled, metrics


class JittedOrCompiled(Wrapped):
    __slots__: tuple[str, ...] = ("jitted", "fun_name")

    def __init__(self, jitted, name=None):
        self.fun_name = name
        self.jitted = jitted

    def lower(self, *args, **kwargs):
        if isinstance(self.jitted, Compiled):
            raise ValueError("Cannot lower a compiled jit function.")
        return self.jitted.lower(*args, **kwargs)

    def trace(self, *args, **kwargs) -> Traced:
        if isinstance(self.jitted, (Traced, Compiled)):
            raise TypeError(f"Unsupported type: {type(self.jitted)}.")
        return self.jitted.trace(*args, **kwargs)

    def name(self):
        if self.fun_name is not None:
            return self.fun_name
        if isinstance(self.jitted, Wrapped):
            return getattr(self.jitted._fun, "__name__", str(self.jitted._fun))
        raise TypeError(f"Unsupported type: {type(self.jitted)}.")

    def __call__(self, *args, **kwargs):
        return self.jitted(*args, **kwargs)

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Only call lower() when the wrapped object is still a jit function; check isinstance(wrapped.jitted, Compiled) first
  2. Restructure the pipeline so loaded Compiled objects go straight to execution, not back through compile

Example fix

# before
lowered = wrapped.lower(*args)  # wrapped.jitted is Compiled
# after
if isinstance(wrapped.jitted, Compiled):
    compiled = wrapped.jitted
else:
    lowered = wrapped.lower(*args)
Defensive patterns

Strategy: type-guard

Validate before calling

from phoenix.xrex.utils.aot import Compiled
if isinstance(wrapped.jitted, Compiled):
    use_directly = wrapped.jitted  # skip lower()

Type guard

def is_compiled(wrapped) -> bool:
    from phoenix.xrex.utils.aot import Compiled
    return isinstance(wrapped.jitted, Compiled)

Prevention

When it happens

Trigger: Wrapping a Compiled object in Wrapped and calling .lower() — e.g. after loading from the AOT cache, the loaded Compiled is wrapped and someone re-enters the compile stage.

Common situations: Caching the wrapped object across pipeline stages and accidentally re-running compile_or_load on it; control flow that assumes lower() is idempotent.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/a4afeb8c956927aa. Report an issue: GitHub.