{"record":{"id":"88fd90288581e77c","repo":"jax-ml/jax","slug":"no-profile-started","errorCode":null,"errorMessage":"No profile started","messagePattern":"No profile started","errorType":"error_code","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"jax/_src/profiler.py","lineNumber":280,"sourceCode":"      print(f\"Open URL in browser: {url}\")\n\n      # Once ui.perfetto.dev acquires trace.json from this server we can close\n      # it down.\n      while httpd.__dict__.get('last_request') != '/' + filename:\n        httpd.handle_request()\n  finally:\n    os.chdir(orig_directory)\n\ndef stop_trace():\n  \"\"\"Stops the currently-running profiler trace.\n\n  The trace will be saved to the ``log_dir`` passed to the corresponding\n  :func:`start_trace` call. Raises a RuntimeError if a trace hasn't been started.\n  \"\"\"\n  with _profile_state.lock:\n    profile_session = _profile_state.profile_session\n    if profile_session is None:\n      raise RuntimeError(\"No profile started\")\n    profile_session.stop_and_export(str(_profile_state.log_dir))\n    if _profile_state.create_perfetto_trace:\n      abs_filename = _write_perfetto_trace_file(str(_profile_state.log_dir))\n      if _profile_state.create_perfetto_link:\n        _host_perfetto_trace_file(abs_filename)\n    _profile_state.reset()\n    clear_metadata()\n\n\ndef stop_and_get_fdo_profile() -> bytes | str:\n  \"\"\"Stops the currently-running profiler trace and export fdo_profile.\n\n  Currently, this is only supported for GPU.\n  Raises a RuntimeError if a trace hasn't been started.\n  \"\"\"\n  with _profile_state.lock:\n    profile_session = _profile_state.profile_session\n    if profile_session is None:","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/profiler.py#L262-L298","documentation":"jax.profiler.stop_trace raises RuntimeError when `_profile_state.profile_session` is None — i.e., no start_trace is active. This is the lifecycle guard matching start_trace's already-started check.","triggerScenarios":"Calling stop_trace before start_trace, after a previous stop_trace, or after an exception skipped start_trace while cleanup still ran.","commonSituations":"Cleanup/finally blocks calling stop_trace unconditionally; mispaired context managers; tests stopping traces started in a different process.","solutions":["Only call stop_trace after a successful start_trace; track state with a flag","Use the `jax.profiler.trace()` context manager which pairs start/stop automatically","Wrap stop_trace in try/except RuntimeError for idempotent cleanup"],"exampleFix":"# before\njax.profiler.stop_trace()  # nothing started\n# after\nwith jax.profiler.trace('/tmp/log'):\n  run_model()","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    jax.profiler.stop_trace()\nexcept RuntimeError as e:\n    if 'No profile started' in str(e):\n        pass\n    else:\n        raise","preventionTips":["Use the trace() context manager for automatic pairing","Guard cleanup with a session-started flag"],"tags":["jax","profiler","lifecycle"],"backgroundTag":"invalid-state-transition","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}