{"record":{"id":"ca2395aba6e22282","repo":"jax-ml/jax","slug":"attempting-to-get-contents-of-allocation-with-key","errorCode":null,"errorMessage":"Attempting to get contents of allocation with key `{key}` that is not a `Buffer`.","messagePattern":"Attempting to get contents of allocation with key `(.+?)` that is not a `Buffer`\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic/interpret/shared_memory.py","lineNumber":537,"sourceCode":"      thread: The thread reading the buffer.\n      increment_clock: Whether to increment the given thread's vector clock\n      logging_info: Information about the source of the read.\n\n    Returns:\n      - The contents of the read range of the buffer, or None if reading\n        entirely out of bounds.\n      - The shape and dtype of the full content array of the buffer.\n      - The incremented vector clock for the given thread.\n        None if race detection is not enabled or if `increment_clock` is False.\n    \"\"\"\n    clock = None\n    with self.lock:\n      if self.detect_races and increment_clock and thread is not None:\n        clock = self.incr_clock(thread, take_lock=False)\n\n      buff = self.mem[key]\n      if not isinstance(buff, Buffer):\n        raise ValueError(\n            f\"Attempting to get contents of allocation with key `{key}` that is\"\n            \" not a `Buffer`.\"\n        )\n      shape_and_dtype = ShapeAndDtype(buff.logical_shape, buff.dtype)\n\n      try:\n        result = buff[rnge].copy()\n      except IndexError:\n        # `buf` was accessed with `rnge` entirely out of bounds.\n        result = None\n\n      if self.enable_logging and logging_info is not None:\n        self._log(\n            logging_info.format(\n                f\"{key=}, {rnge=},\"\n                f\" in_bounds={result is not None}.\\n\"\n                f\"logical_shape={buff.logical_shape},\"\n                f\" content_shape={buff.shape},\"","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic/interpret/shared_memory.py#L519-L555","documentation":"get_buffer_content looked up a memory key whose stored object is not a Buffer (e.g. it is a Semaphore). Reads with clock/race tracking require a Buffer with logical shape and dtype.","triggerScenarios":"Calling SharedMemManager.get (or ops routed through it, like wgmma or deref helpers) with a key that maps to a semaphore or other non-Buffer allocation.","commonSituations":"Semaphore IDs colliding with buffer memory keys; passing the wrong MemKey to a load op; races between allocation and access in multi-threaded interpret simulation.","solutions":["Check the key was obtained from allocate_buffer, not get_semaphore/fixed-ID semaphores","Fix key generation so buffers and semaphores cannot collide","Reproduce single-threaded to rule out allocation/access races in the interpreter harness"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"def is_buffer_key(mgr, key):\n    with mgr.lock:\n        return isinstance(mgr.mem.get(key), Buffer)","tryCatchPattern":"try:\n    val = mgr.get(key, ...)\nexcept ValueError as e:\n    if 'not a `Buffer`' in str(e):\n        raise KeyError(f'{key} is not a buffer allocation') from e\n    raise","preventionTips":["Thread the original MemKey from allocation through to every load op","Avoid fixed-ID semaphores that can collide with buffer keys"],"tags":["jax","pallas","mosaic","shared-memory","key-collision","interpret-mode"],"backgroundTag":"invalid-key-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}