{"record":{"id":"df3f29a7c813d4d1","repo":"jax-ml/jax","slug":"next-fetch-is-none","errorCode":null,"errorMessage":"next_fetch is None","messagePattern":"next_fetch is None","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic/pipeline.py","lineNumber":986,"sourceCode":"  def wait_out(self, dst_ref, grid_indices):\n    \"\"\"Waits for output copy to finish.\"\"\"\n    assert self.is_output\n    if not self.is_buffered: return\n    assert self.sem_sends is not None\n    wait_slot = self.current_wait_out_slot\n    dst_slice = self.get_dma_slice(_ref_to_value_aval(dst_ref), grid_indices)\n    src_slice = self._to_window_slice(dst_slice)\n    # Single-buffered outputs are synchronously copied.\n    if self.buffer_count > 1:\n      tpu_primitives.make_async_copy(\n          self._window_ref_at(wait_slot, src_slice),  # nb: doesn't matter\n          dst_ref.at[dst_slice],  # only dst shape is important\n          self.sem_sends.at[wait_slot],\n      ).wait()\n\n  def advance_next_fetch(self, grid):\n    if self.next_fetch is None:\n      raise ValueError(\"next_fetch is None\")\n    return self.with_next_fetch(_next_index(tuple(self.next_fetch), grid))\n\n\ndef fetch_with_lookahead(buffered_ref, src_ref,\n                         grid,\n                         grid_offsets,\n                         predicate: jax.Array | bool = True,\n                         max_num_fetches: int | None = None,\n                         update_slots: bool = True):\n  \"\"\"Fetch future blocks using unbounded lookahead.\n\n  Args:\n    buffered_ref: the BufferedRef to fetch for.\n    src_ref: the source Ref.\n    grid: the grid bounds.\n    grid_offsets: the grid offsets (used for megacore).\n    predicate: a boolean predicate for whether to perform the fetch.\n    max_num_fetches: the maximum number of fetches to perform. If None,","sourceCodeStart":968,"sourceCodeEnd":1004,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic/pipeline.py#L968-L1004","documentation":"advance_next_fetch advances the prefetch pointer by one grid step. It is a programming invariant that next_fetch was set before the call; if it is None, the internal state is uninitialized or misused and the guard raises immediately with 'next_fetch is None'.","triggerScenarios":"Calling advance_next_fetch on a BufferedRef whose next_fetch state was never initialized (e.g. constructing a fetch sequence manually or a state-replacement path dropping next_fetch) — normally reached via initialize_step on prefetched inputs.","commonSituations":"Almost exclusively a JAX-internal invariant violation or library misuse via lower-level APIs; end users rarely trigger it directly.","solutions":["Don't call low-level BufferedRef methods manually; drive prefetching through the public pipeline API (emit_pipeline / fetch_with_lookahead)","Ensure pipeline_mode prefetch configuration is consistent (prefetched_count > 0 with a bound window_ref)","If reproduced with supported APIs, file a jax issue with a minimal kernel"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only the public pipeline API (emit_pipeline/fetch_with_lookahead); never manipulate BufferedRef state directly","Report reproductions of this invariant error to the JAX project"],"tags":["jax","pallas","internal-invariant","prefetch"],"backgroundTag":"internal-invariant-violation","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}