Skip to content

[CoreAI] Add atomic cache storage primitives - #23388

Draft
metascroy wants to merge 1 commit into
coreai-v2/01-export-parserfrom
coreai-v2/02-filesystem
Draft

metascroy wants to merge 1 commit into
coreai-v2/01-export-parserfrom
coreai-v2/02-filesystem

Conversation

@metascroy

@metascroy metascroy commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Adds the filesystem layer the Core AI runtime uses for its asset and bookmark cache (runtime/coreai_storage.{h,mm}, runtime/coreai_file.h).

  • Prepare an absolute, application-chosen storage root. Creating a root also excludes it from backup; inspecting an existing root changes nothing.
  • Enumerate directories through descriptors and return sorted names, failing on operational errors rather than returning partial listings.
  • Write files relative to a directory descriptor and fsync each file and its parent directory.
  • Publish data atomically: write a temporary file, fsync + F_FULLFSYNC it, renameat it into place and sync the directory. A failure before the rename keeps the old bytes and removes the temporary file.
  • Trust model: the application owns the cache directory; the helpers do not defend against other processes of the same user swapping paths inside it.
  • Fault injection uses storage_fault(), which compiles to a constant 0 unless COREAI_ASSETS_TESTING is defined (only in coreai_host_test).
  • Tests: the storage suite in coreai_host_test.
  • README: the "Asset storage" root, durability and backup-exclusion text.

No changes outside backends/apple/coreai.

Stack: 2 of 9, based on #23387. Review only this PR's commit. Next: #23389.

Test plan: built locally for macOS 27.0; ctest -N lists coreai_host_test, which the Core AI workflow runs on the macOS 27 runner. lintrunner is clean.

@pytorch-bot

pytorch-bot Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/23388

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 7998984 with merge base 0b3d26d (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 3, 2026
Summary:
Add the filesystem layer the Core AI runtime uses for its asset and bookmark
cache (`runtime/coreai_storage.{h,mm}`, `runtime/coreai_file.h`).

- Prepare an absolute storage root chosen by the application. Creating a root
  also excludes it from backup; inspecting an existing root changes nothing.
- Enumerate directories through descriptors and return sorted names, failing
  on operational errors rather than returning partial listings.
- Write new files relative to a directory descriptor and `fsync` each file and
  its parent directory.
- Publish data atomically: write a temporary file, `fsync` and `F_FULLFSYNC`
  it, `renameat` it into place and sync the directory. Readers see either the
  old or the new complete bytes. A failure before the rename leaves the old
  bytes and removes the temporary file.
- Tree removal is not included here; it lands with cache clearing.
- README: the "Asset storage" root, durability and backup-exclusion text.

Trust model: the application owns the cache directory. The helpers do not
defend against other processes of the same user renaming or replacing paths
inside it.

Fault injection points use `storage_fault()`, which compiles to a constant 0
unless `COREAI_ASSETS_TESTING` is defined. Only the `coreai_host_test` target
defines it.

No changes outside `backends/apple/coreai`.

Test Plan:
```
# Local: configure and build only
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_OSX_DEPLOYMENT_TARGET=27.0 -DEXECUTORCH_BUILD_COREAI=ON \
  -DEXECUTORCH_BUILD_TESTS=ON -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON
cmake --build build --target backends/apple/coreai/all
# CI (macOS 27 runner, .github/workflows/coreai.yml)
ctest --test-dir build/backends/apple/coreai --output-on-failure --no-tests=error
```
CTest runs `coreai_host_test`, which adds the storage suite.
AtomicPublicationPreservesOldBytesOnFailure checks that a failed rename leaves
the old bytes and no `.tmp-*` entry.
@metascroy
metascroy force-pushed the coreai-v2/01-export-parser branch from 0485975 to 8bdd47d Compare October 5, 2026 03:14
@metascroy
metascroy force-pushed the coreai-v2/02-filesystem branch from aa99feb to 7998984 Compare October 5, 2026 03:14

This branch was successfully deployed

1 active deployment
cadence — 7998984b Deployed Oct 5, 2026 by metascroy via hifi-op-test / hifi4 #31514
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant