Skip to content

[6.x] Skip a Stache file that is removed while it is being read - #15903

Merged
jasonvarga merged 1 commit into
statamic:6.xfrom
joshdaugherty:fix-stache-vanished-files
Nov 18, 2026
Merged

jasonvarga merged 1 commit into
statamic:6.xfrom
joshdaugherty:fix-stache-vanished-files

Conversation

@joshdaugherty

Copy link
Copy Markdown
Contributor

Skips a Stache file that is removed while it is being traversed or read, instead of aborting the traversal or rebuilding the file as a new, empty item.

  • Traverser::traverse(): if getMTime() throws, skip the file only when a fresh scandir() shows it is gone; otherwise rethrow.
  • Store::paths(), Store::getItemFromModifiedPath(), BasicStore::getItem() and TaxonomyTermsStore (paths(), getItem(), getItemFromModifiedPath()): when File::get() returns null and a fresh listing confirms the file is gone, treat it as gone.

Tests: a file removed between listing and stat is skipped by the traverser; paths() skips a path that no longer exists; getItem() returns null for a file removed after its path was recorded. Each fails on 6.x without the change. The taxonomy term variants share the same guard and have no separate test.

Fixes #15902

@jasonvarga
jasonvarga merged commit 08c095f into statamic:6.x Nov 18, 2026
62 checks passed
joshdaugherty added a commit to UAMS-Web/aether-people that referenced this pull request Nov 23, 2026
…he patches (#160)

Closes #158.

Adopts `uams-web/patches-statamic-cms` `v1.2.0`, the release that
retires the seven Stache vanished-file patches and pins `statamic/cms`
at `6.43.1`, where the upstream fix (`statamic/cms#15903`, in `v6.43.0`)
ships. The seven entries leave `patches.json`; the four remaining
`statamic/cms` patches stay.

## Approach

-
[`composer.json`](https://github.com/UAMS-Web/aether-people/blob/158-adopt-patches-statamic-cms-1-2/composer.json):
`uams-web/patches-statamic-cms` from `^1.1` to `^1.2`, so an install
without the lock cannot resolve the release that still carries the
retired patches.
- `composer.lock`: `uams-web/patches-statamic-cms` `v1.1.0` to `v1.2.0`
and `statamic/cms` `v6.40.0` to `v6.43.1`. The update named both
packages: `composer update uams-web/patches-statamic-cms
--with-dependencies` alone reports "Nothing to modify in lock file",
because `statamic/cms` is a root requirement and stays at its locked
version unless named. It also moved nine other packages that
`statamic/cms` `6.43.1` allows.
-
[`patches.json`](https://github.com/UAMS-Web/aether-people/blob/158-adopt-patches-statamic-cms-1-2/patches.json):
the traverser patch, the store `paths()` and `getItemFromModifiedPath()`
patches, the `BasicStore` and the three taxonomy terms store patches are
removed.
- `patches.lock.json`: recreated with `composer patches-relock`; a
second relock leaves it byte-identical.
- Nothing else here served those patches:
`UAMS-Web/patches-statamic-cms#6` in `src/ServiceProvider.php` and the
word "vanished" in `PeopleMergeServiceDetailTest` concern other things
(a different patch and entries removed between planning and retiring).

## Verification

Windows 11, Git Bash, PHP 8.4; macOS not measured.

- The first `composer update` with the new lock failed on install, as
expected while `patches.json` still named a patch the package no longer
carries: `No available patcher was able to apply patch
vendor/uams-web/patches-statamic-cms/patches/statamic-stache-traverser-vanished-file.patch
to statamic/cms`. After the seven entries were removed and the patches
relocked, `composer reinstall statamic/cms` applied the four remaining
`statamic/cms` patches (four patch files found and applied, exit 0), so
the tree matches a fresh install.
- Installed after the change: `statamic/cms` `v6.43.1`,
`uams-web/patches-statamic-cms` `v1.2.0`; `composer validate` reports
`./composer.json is valid`.
- `composer test`: `Tests: 2311 passed (5779 assertions)`, `Duration:
132.84s`, the same count as on `main`.

## Out of scope

Any other patch, and any release of this add-on.

## Test plan

- [x] The release that drops the seven patches exists and is the one
adopted (`v1.2.0`, published 2026-11-22)
- [x] `composer.lock` shows `uams-web/patches-statamic-cms` `v1.2.0` and
`statamic/cms` `v6.43.1`
- [x] The remaining patches apply in order on install (`composer
reinstall statamic/cms`, four patches, exit 0)
- [x] Nothing remains that only served the retired patches (grep of
`src`, `tests`, `docs` and `composer.json`, hits explained above)
- [x] Remote CI on the head `f84a9ca` passes: `CI`, `Attribution
footer`, `Closing keywords`, and every other check success or skipped

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
joshdaugherty added a commit to UAMS-Web/aether-wordpress-importer that referenced this pull request Nov 24, 2026
Closes #616.

Raises the exact `statamic/cms` pin from `6.42.0` to `6.43.1`, so a
release cut from `main` installs beside `uams-web/patches-statamic-cms`
v1.2.0, which pins `6.43.1`. No other package moves.

## Files

- **edit**
[`composer.json`](https://github.com/UAMS-Web/aether-wordpress-importer/blob/616-statamic-cms-6-43-1/composer.json):
`require.statamic/cms` `6.42.0` to `6.43.1`.
- **edit**
[`composer.lock`](https://github.com/UAMS-Web/aether-wordpress-importer/blob/616-statamic-cms-6-43-1/composer.lock):
`statamic/cms` `v6.42.0` (`3b28f8c`) to `v6.43.1` (`71387ae`), and the
`content-hash`.

## Verification

- `composer update statamic/cms` reported `Lock file operations: 0
installs, 1 update, 0 removals`: `Upgrading statamic/cms (v6.42.0 =>
v6.43.1)`. The lock diff touches only the `statamic/cms` entry and
`content-hash`, so `ueberdosis/tiptap-php` stays where it was. The local
Composer wrote `plugin-api-version` `2.11.0`; that line was restored to
`2.9.0` so the diff carries no tool-version churn. `composer validate
--no-check-publish` reports no lock-file errors.
- Clean install (`vendor/` removed, `composer install`) exit 0, read to
its end: `Patching pestphp/pest-plugin-mutate` lists 15 patch lines and
no failure line, against 15 entries in `patches.json`. Reversing all 15
patches in stack order on a copy of the installed package succeeded for
15 of 15, so each one is applied. Every registered patch targets
`pestphp/pest-plugin-mutate`, none `statamic/cms`.
- Pre-push checks on `9df54f3` (Windows 11): Pint `--test` passed,
Rector dry run clean, `node scripts/run-spell.mjs` 135 files 0 issues,
`check-mutate-ignore-breadth` no annotation flagged outside the
baseline, PHPStan `[OK] No errors`.

### Statamic changes between 6.42.0 and 6.43.1 that touch importer
surfaces

Read from the upstream release notes for `v6.43.0` and `v6.43.1`. None
needs a code change here; each is listed because an import exercises the
area:

- Prevent term localizations from saving a copy of the non-localizable
slug (statamic/cms#15952): term writes in non-default sites.
- Rebuild a collection's entries when its sites change
(statamic/cms#15906).
- Throw an exception when an uploaded file cannot be written to the disk
(statamic/cms#15919): an asset write that failed silently now throws.
- Do not regenerate asset meta when a value is null
(statamic/cms#15978).
- Prevent duplicate field handles across imported fieldsets
(statamic/cms#15933).
- Skip a Stache file that is removed while it is being read
(statamic/cms#15903).

## Behavior change found: re-imported flat terms are not found

Remote CI on `9df54f3` fails `checks / Pest` on ubuntu-latest and
macos-latest: all 5 cases of
`tests/Integration/FlatTermReimportTest.php` (13152 passed, 5 failed, 4
skipped). Reproduced on Windows 11: 5 of 5 fail.

- **Cause:** statamic/cms#15897 (in `v6.43.0`) stops `Store::clear()`
from forgetting which indexes queries have used. Restoring the two
removed lines in the installed `src/Stache/Stores/Store.php` makes all 5
cases pass; with the file as shipped, all 5 fail.
- **Effect on the importer:** after the flat term pass saves,
`rebuildTermStoreFromDisk()` runs `clear()` and `warm()` on the
taxonomy's term store. Under `6.43.1`,
`Term::whereTaxonomy('tags')->count()` then returns `0` while the term
file is on disk and the store's `paths()` lists it; a second `clear()`
and `warm()` returns `1`. So a re-import does not see its existing
terms: `Overwrite matching terms` creates instead of updating, and
`Create an additional term` reuses the base slug.
- This pull request stays a draft until that is resolved.

## Companion PRs

`UAMS-Web/uams-statamic#1248` waits on a release that carries this pin.
Cutting that release is separate and is not part of this pull request.

## Out of scope

- Cutting a release.
- Moving any other package.

## Test plan

- [x] `composer.json` requires `statamic/cms` `6.43.1` and
`composer.lock` locks it; the lock diff changes no other package.
- [x] Clean install read to its end: 15 of 15 registered patches
applied, none failed.
- [x] Pre-push checks pass on `9df54f3`, and again on `b7a2661` after
the sync with `main` (Pint, PHPStan, Rector, cspell,
`check-mutate-ignore-breadth`).
- [x] Remote CI green on the head (Linux, Windows, macOS): [`CI` run
45451223175](https://github.com/UAMS-Web/aether-wordpress-importer/actions/runs/45451223175)
on `b7a2661` succeeded; 45 checks succeeded and 11 were skipped. The end
of each Pest job:

  ```text
ubuntu-latest Tests: 4 skipped, 13172 passed (36771 assertions)
Duration: 274.44s
macos-latest Tests: 3 skipped, 13173 passed (36827 assertions) Duration:
305.43s
windows-latest Tests: 26 skipped, 13150 passed (36619 assertions)
Duration: 491.47s
  ```

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
bpmore pushed a commit to UAMS-Web/uams-statamic that referenced this pull request Nov 26, 2026
Closes #1250.

Moves to `uams-web/patches-statamic-cms` `v1.2.0`, the release that
drops the seven Stache vanished-file patches because `statamic/cms`
`v6.43.0` carries their fix
([statamic/cms#15903](statamic/cms#15903)).
Following the ticket's Scope ruling, three packages move and nothing
else.

## Release adopted

`v1.2.0`, not the latest `v1.4.0`. `v1.2.0` is the release that retires
these seven patches. `v1.3.0` (the updates-badge retirement) belongs to
#1261, and `v1.4.0` (the stale file items patch) belongs to #1509; per
the ruling, each lands after the previous one merges.

## Lock changes

Read from `composer.lock` against `main`:

| Package | From | To | Why |
| --- | --- | --- | --- |
| `uams-web/patches-statamic-cms` | `v1.1.0` | `v1.2.0` | the release
that drops the seven patches |
| `statamic/cms` | `v6.40.0` | `v6.43.1` | `v1.2.0` requires `6.43.1`
exactly |
| `uams-web/aether-wordpress-importer` | `v0.34.0` | `v0.37.0` |
`v0.34.0` requires `statamic/cms` `6.40.0` exactly; `v0.37.0` is the
first release that allows `6.43.1` (scope widened on the ticket) |

No other package changes version or reference. `phpstan/phpstan` `2.3.7`
gains a `published-time` metadata field from the re-resolve; its version
and reference are unchanged. `composer.json` raises the `statamic/cms`
pin to `6.43.1` and the package floor to `^1.2`.

Command: `composer update uams-web/patches-statamic-cms statamic/cms
uams-web/aether-wordpress-importer --with
uams-web/patches-statamic-cms:1.2.0 --with
uams-web/aether-wordpress-importer:0.37.0`, then `composer
patches-relock`, `composer update --lock` and `composer reinstall
statamic/cms`. The first install failed, as expected, on the stale
`patches.lock.json` entry for
`statamic-stache-traverser-vanished-file.patch`; the relock fixed it.

## Patches

`patches.lock.json` now lists four `statamic/cms` patches, in the
package's order: collection create label, taxonomy create label,
updates-overview badge, blueprint namespace slash. On reinstall all four
apply, and `ensure-patches-applied.php` reports `all 22 checked
patch(es) are applied in vendor/`.

## Tests kept, not deleted


[`TraverserVanishedFileTest.php`](https://github.com/UAMS-Web/uams-statamic/blob/1250-patches-statamic-cms-v1.2.0/tests/Feature/Stache/TraverserVanishedFileTest.php)
and
[`StoreVanishedFileTest.php`](https://github.com/UAMS-Web/uams-statamic/blob/1250-patches-statamic-cms-v1.2.0/tests/Feature/Stache/StoreVanishedFileTest.php)
run real race windows rather than checking for patch text, so they stay
as tests of the upstream behavior. Their docblocks now say so.
Upstream's `Traverser::traverse()` `catch` matches the retired patch:
skip only when a fresh `scandir()` no longer lists the file, and rethrow
otherwise.

On stock `6.43.1`, 16 of the 18 cases passed unchanged. The two "still
raises" controls failed with no exception thrown. `6.43.1` iterates
Finder lazily instead of calling `sortByName()` first, so Finder stats
each file just before the filter runs, and `getMTime()` was answered
from PHP's stat cache without reaching the failing stream wrapper. Each
control now calls `clearstatcache()` after setting up the failure.
Mutation-checked by hand against the vendored `Traverser`, with the file
restored byte-identical afterwards:

- With the rethrow condition replaced by `if (false)`, the two "still
raises" controls fail.
- With the `continue` replaced by `throw $e`, the two "skips a file
removed" cases fail.

## Removed or annotated

-
[`patches/README.md`](https://github.com/UAMS-Web/uams-statamic/blob/1250-patches-statamic-cms-v1.2.0/patches/README.md):
the two guard-table rows for the retired patches.
-
[`docs/DECISIONS.md`](https://github.com/UAMS-Web/uams-statamic/blob/1250-patches-statamic-cms-v1.2.0/docs/DECISIONS.md):
the 2026-09-29 traverser entry and the 2026-09-30 store entry each get a
**Retired** note; neither entry is deleted.
- `git grep statamic-stache-traverser-vanished-file`, excluding
`docs/DECISIONS.md` and `composer.lock`, returns 0 hits; in
`docs/DECISIONS.md` it returns 2, the annotated entry. `vanished-file`
appears 0 times in `composer.lock` and `patches.lock.json`.

## `statamic/cms` changes between `6.40.0` and `6.43.1`

The release notes for `v6.41.0` to `v6.43.0` change a lot of Stache
internals: faster traversal and cold entry builds (statamic/cms#15821,
statamic/cms#15826), blueprint and fieldset YAML kept between requests
(statamic/cms#15813), term associations built once on warm
(statamic/cms#15872), duplicate ids kept across clear and warm
(statamic/cms#15883), and which indexes are used kept across a clear
(statamic/cms#15897). Nothing in them is marked breaking. The full suite
on the three-OS CI matrix is the check for this repository's
Stache-backed code.

## Test plan

- [x] `composer validate --no-check-publish --no-check-all` passes
- [x] Pint `--test` on the changed tests passes
- [x] `composer stan`: no errors
- [x] cspell on the changed Markdown and PHP files: 0 issues
- [x] `check-mutate-ignore-breadth` and `check-parallel-safe-tests` pass
- [x] `php artisan test --compact
tests/Feature/Stache/TraverserVanishedFileTest.php
tests/Feature/Stache/StoreVanishedFileTest.php`: 18 passed, run as two
invocations (6 + 12; the store suite was 12 of the first run's 16
passes)
- [x] Remote CI green on Linux, Windows and macOS (head `9172bc421`; the
macOS shard 3 job passed on re-run after a `TableSetPartialTest` failure
that does not reproduce alone)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A Stache file deleted while it is being traversed or read aborts the traversal or is rebuilt as an empty item

2 participants