{"record":{"id":"a4afeb8c956927aa","repo":"xai-org/x-algorithm","slug":"cannot-lower-a-compiled-jit-function","errorCode":null,"errorMessage":"Cannot lower a compiled jit function.","messagePattern":"Cannot lower a compiled jit function\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phoenix/xrex/utils/aot.py","lineNumber":672,"sourceCode":"        }\n\n        return compiled\n\n    metrics: Dict[str, Dict[str, float]] = {}\n    all_compiled = {n: _compile_or_load(n, t, metrics) for n, t in all_traced.items()}\n    return all_compiled, metrics\n\n\nclass JittedOrCompiled(Wrapped):\n    __slots__: tuple[str, ...] = (\"jitted\", \"fun_name\")\n\n    def __init__(self, jitted, name=None):\n        self.fun_name = name\n        self.jitted = jitted\n\n    def lower(self, *args, **kwargs):\n        if isinstance(self.jitted, Compiled):\n            raise ValueError(\"Cannot lower a compiled jit function.\")\n        return self.jitted.lower(*args, **kwargs)\n\n    def trace(self, *args, **kwargs) -> Traced:\n        if isinstance(self.jitted, (Traced, Compiled)):\n            raise TypeError(f\"Unsupported type: {type(self.jitted)}.\")\n        return self.jitted.trace(*args, **kwargs)\n\n    def name(self):\n        if self.fun_name is not None:\n            return self.fun_name\n        if isinstance(self.jitted, Wrapped):\n            return getattr(self.jitted._fun, \"__name__\", str(self.jitted._fun))\n        raise TypeError(f\"Unsupported type: {type(self.jitted)}.\")\n\n    def __call__(self, *args, **kwargs):\n        return self.jitted(*args, **kwargs)\n","sourceCodeStart":654,"sourceCodeEnd":689,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/phoenix/xrex/utils/aot.py#L654-L689","documentation":"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.","triggerScenarios":"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.","commonSituations":"Caching the wrapped object across pipeline stages and accidentally re-running compile_or_load on it; control flow that assumes lower() is idempotent.","solutions":["Only call lower() when the wrapped object is still a jit function; check isinstance(wrapped.jitted, Compiled) first","Restructure the pipeline so loaded Compiled objects go straight to execution, not back through compile"],"exampleFix":"# before\nlowered = wrapped.lower(*args)  # wrapped.jitted is Compiled\n# after\nif isinstance(wrapped.jitted, Compiled):\n    compiled = wrapped.jitted\nelse:\n    lowered = wrapped.lower(*args)","handlingStrategy":"type-guard","validationCode":"from phoenix.xrex.utils.aot import Compiled\nif isinstance(wrapped.jitted, Compiled):\n    use_directly = wrapped.jitted  # skip lower()","typeGuard":"def is_compiled(wrapped) -> bool:\n    from phoenix.xrex.utils.aot import Compiled\n    return isinstance(wrapped.jitted, Compiled)","tryCatchPattern":null,"preventionTips":["Check pipeline stage before calling lower(); don't re-enter compile on cache hits","Keep clear state: raw jit -> Traced -> Lowered -> Compiled, never backwards","Return loaded Compiled objects directly instead of re-wrapping into the compile path"],"tags":["jax","aot","state-machine"],"backgroundTag":"invalid-state-transition","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}