← Back to Pull requests

Fix Store tokenization including file manager's random id #11831

Closed
unknown closed this pull request without merging on Nov 14, 2026 20:56 UTC
View on GitHub
unknown unknown commented on Oct 30, 2026 13:51 UTC
Author

Description

This PR fixes the tokenization of Store objects so that they are unique (non-random) for read mode cases. See #11814 for details. This is already the case for when a Path/str is passed directly to open_dataset, but if you pass a Store object then you would always get random tokens. This means that the same file opened with a store and then passed to open_dataset with chunks= defined to use dask would get a different dask token every time it was opened. This would cause dask to recompute/reload the data from the file when it could be sharing the computation.

The main problem starts with open_dataset tokenizing the input str/Path/object:

https://github.com/pydata/xarray/blob/c753f1ed366d3b97cf67abea4dee5f3d0eb20be3/xarray/backends/api.py#L269

For a filename this is a simple tokenization and the mtime is included. For a Store object it ends up going to dask, getting pickled, and then tokenized based on those bytes. However, this includes the underlying file manager object that some stores have and file manager's include a random id value. This means every instance gets a new token instead of sharing the same token like they could (see the minimal example in the related issue).

The fix is tokenize the store and file manager's state which is a tuple and dask will tokenize recursively. By customizing the file manager's tokenization to not include the id, or the lock, or anything that isn't specific to what is being read and how it is read this now produces the same token for every input. This can't be done reliably for all store types, but for the usual NetCDF and HDF5-based ones it works. Zarr would be nice but you'd have to somehow manage the modification time of all the individual zarr files and usually (?) I'd expect zarr to be used for remote files so that wouldn't work anyway.

#11826 should probably be merged before this and I can rebase after that.

Checklist

<!-- Feel free to remove check-list items aren't relevant to your change -->

  • Closes #11814

  • Tests added

  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • AI Disclosure

    <!--- Please review our AI & contribution guidelines: https://docs.xarray.dev/en/stable/contribute/ai-policy.html. Remove this section if your PR does not contain AI-generated content. --->

  • This PR contains AI-generated content.

  • - [x] I have tested any AI-generated content in my PR.
    - [x] I take responsibility for any AI-generated content in my PR.
    <!--- If you used AI to generate code, please specify the tool used and the prompt below. --->
    Tools: Claude (Opus)

    Diff: 330 lines (+247 / -83) across 4 files Reviewer: djhoese Review duration: 22025m
    All Vouch review confidence checks passed
    Residual risk 0.26 = Change Risk (0.65) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.65 · 330 lines diff across 4 files
    0.65
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.347
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.065
    Real PR Conversation Timeline
    1 comments
    "Review active on #11831"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 65.3% (HIGH) · Higher = larger blast radius
    65.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.8% · Safe to merge
    25.8%
    Repository