{"record":{"id":"3682651e154a3594","repo":"langchain-ai/langchain","slug":"no-indexed-run-id-run-id","errorCode":null,"errorMessage":"No indexed run ID {run_id}.","messagePattern":"No indexed run ID (.+?)\\.","errorType":"exception","errorClass":"TracerException","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/tracers/core.py","lineNumber":156,"sourceCode":"                        \"Parent run %s not found for run %s. Treating as a root run.\",\n                        run.parent_run_id,\n                        run.id,\n                    )\n                run.parent_run_id = None\n                run.trace_id = run.id\n                run.dotted_order = current_dotted_order\n        else:\n            run.trace_id = run.id\n            run.dotted_order = current_dotted_order\n        self.order_map[run.id] = (run.trace_id, run.dotted_order)\n        self.run_map[str(run.id)] = run\n\n    def _get_run(self, run_id: UUID, run_type: str | set[str] | None = None) -> Run:\n        try:\n            run = self.run_map[str(run_id)]\n        except KeyError as exc:\n            msg = f\"No indexed run ID {run_id}.\"\n            raise TracerException(msg) from exc\n\n        if isinstance(run_type, str):\n            run_types: set[str] | None = {run_type}\n        else:\n            run_types = run_type\n        if run_types is not None and run.run_type not in run_types:\n            msg = (\n                f\"Found {run.run_type} run at ID {run_id}, \"\n                f\"but expected {run_types} run.\"\n            )\n            raise TracerException(msg)\n        return run\n\n    def _create_chat_model_run(\n        self,\n        serialized: dict[str, Any],\n        messages: list[list[BaseMessage]],\n        run_id: UUID,","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/tracers/core.py#L138-L174","documentation":"BaseTracer keeps an in-memory run_map of runs it started. _get_run looks up a run_id in that map; an unknown id means on_llm_end/on_chain_end/on_tool_end (or similar) was called for a run this tracer never saw begin — a lifecycle mismatch — and raises TracerException.","triggerScenarios":"Calling callback handler end events with a fabricated or foreign run_id; a tracer attached mid-run so it missed on_*_start; reusing a run_id after the tracer was reset; concurrent tracers receiving each other's events.","commonSituations":"Custom callback managers or manual tracer event forwarding; multiprocessing/streaming setups where start events bypass one handler; calling .end() twice with different handlers.","solutions":["Ensure the same tracer/handler receives both the start and end events for every run_id","Attach callbacks at the root invocation (e.g., invoke(..., config={'callbacks': [handler]})) rather than mid-stream","In custom handlers, guard: if str(run_id) not in tracer.run_map: return before calling _get_run"],"exampleFix":"# before\nclass MyTracer(BaseTracer):\n    def on_tool_end(self, output, *, run_id, **kw):\n        run = self._get_run(run_id, \"tool\")   # TracerException if start was missed\n\n# after\nclass MyTracer(BaseTracer):\n    def on_tool_end(self, output, *, run_id, **kw):\n        if str(run_id) not in self.run_map:    # skip runs we never started\n            return\n        run = self._get_run(run_id, \"tool\")","handlingStrategy":"try-catch","validationCode":"def tracer_has_run(tracer, run_id) -> bool:\n    return str(run_id) in tracer.run_map\n\nclass SafeTracer(BaseTracer):\n    def on_tool_end(self, output, *, run_id, **kw):\n        if not tracer_has_run(self, run_id):\n            return  # run started elsewhere; skip silently\n        run = self._get_run(run_id, \"tool\")","typeGuard":null,"tryCatchPattern":"from langchain_core.tracers import TracerException\n\ntry:\n    run = tracer._get_run(run_id, \"tool\")\nexcept TracerException:\n    return  # tolerate out-of-lifecycle events from foreign callbacks","preventionTips":["Attach callbacks at the root invoke/ainvoke call, never mid-run","Forward start and end events to the same handler instance","In custom tracers, ignore unknown run_ids rather than crashing the user's run"],"tags":["langchain","tracing","callbacks","lifecycle"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}