Skip to content

Cached numpy / numeric-column values are read-only and alias the L1 buffer #157

@27Bslash6

Description

@27Bslash6

Summary

np.frombuffer is used to reconstruct numpy arrays and numeric DataFrame/Series columns. The returned arrays are writeable=False, owndata=False, and alias the source bytes. On an L1 hit they alias the live L1-cached bytes.

Evidence

  • src/cachekit/serializers/auto_serializer.py:642 (numpy), :705 (numeric DataFrame col), :766 (numeric Series)
  • Empirically: np.frombuffer(...).reshape(...)flags.writeable=False; mutation raises ValueError: assignment destination is read-only

Impact

  1. Behavioral regression: a caller who mutates a returned array/frame gets a crash that an uncached call would not produce.
  2. Aliasing risk: on L1 hits the returned array shares memory with the cached entry; mutating-by-copy patterns can be surprising. DATA-IS-SACRED adjacency.

Fix

Return a writable copy (np.array(frombuffer(...))) or document the read-only contract explicitly and copy-on-return for the L1 path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpythonPython library

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions