`PREBUILT_CACHE` weaves and writes the cache when a class is missing from it (fails on read-only file systems)

Aperta
#808 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@lisachenko ci sta già lavorando.

Dal 5/11/2026.

  • #834 di @lisachenko — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
php
Ambito
backend

Direzione di ricerca

Read src/Instrument/ClassLoading/SourceTransformingLoader.php around saveToCache() and src/Instrument/ClassLoading/CachePathManager.php around flushCacheState(), then inspect the existing cache tests. First decide how PREBUILT_CACHE should handle cache misses and missing cached files; done means the chosen behavior avoids the reported write or warning, the documentation matches, and the acceptance tests pass. An open linked pull request is already addressing this issue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug

Found while benchmarking with goaop/shop-demo (PHP 8.5.12, framework b755e57). Follow-up of #680, which fixed the same promise for the advisor caches only.

Problem

Features::PREBUILT_CACHE is documented as "never writes to the cache directory … Works on read-only file systems" (docs/configuration.md:37, src/Aop/Features.php). A class below the include paths that is missing from the cache is nevertheless woven by the request that loads it, and the result is written:

  • SourceTransformingLoader::saveToCache() writes the woven source with no PREBUILT_CACHE guard (src/Instrument/ClassLoading/SourceTransformingLoader.php:311-346, write at :333);
  • CachePathManager::flushCacheState() rewrites both metadata files at shutdown; it is guarded by is_writable($this->cacheDir) only (src/Instrument/ClassLoading/CachePathManager.php:616).

On a read-only file system, CacheFileWriter::write() throws WeavingException::cacheDirectoryNotCreated / cacheFileNotWritten (src/Core/Cache/CacheFileWriter.php:61,76), so the request fails (from reading the code; not reproducible as root here).

Reproduction (writable cache)

cd shop-demo
APP_MODE=prebuilt vendor/bin/aspect cache:warmup:aop config/bootstrap.php
# add an advised class after the warm-up, e.g. src/Service/LateService.php (matched by
# MonitoringAspect's execution(public App\Service\*->*(*))), then load it with APP_MODE=prebuilt

Result: the request loads the parser, the transformers, the matcher and the aspects (234 files included for a script that only boots the kernel and creates this one object), writes var/cache/prebuilt/src/Service/LateService.php and LateServiceOriginalTrait.php, and rewrites _include.cache.

Related variant: when a record exists but its cached file is gone, PREBUILT_CACHE trusts the record, file_get_contents() of the missing file raises a warning (SourceTransformingLoader.php:298), and the class is woven and written again.

Proposal (decide which)

  1. Serve without saving: with PREBUILT_CACHE, a miss is woven and the woven source is emitted by the stream filter as usual, but nothing is written and nothing is flushed. The behaviour stays correct, the file system stays untouched, and each such request pays for weaving.
  2. Fail fast: throw a dedicated WeavingException (see src/Aop/Exception/AGENTS.md) that names the class and says to rebuild the cache with cache:warmup:aop.

Option 1 matches the documented contract; option 2 surfaces an incomplete deployment immediately. Either way, the missing-cached-file variant should take the same path instead of raising a warning.

Acceptance

  • With PREBUILT_CACHE, a miss writes nothing: tested on a read-only vfs and on real disk.
  • docs/configuration.md matches the behaviour.
  • composer test, composer analyze.

Estimate

Medium: SourceTransformingLoader::saveToCache() and CachePathManager::flushCacheState() guards, plus a decision on the semantics and tests.


Generated by Claude Code

Lingua principale
PHP
Stelle
1.7k
Fork
166
Merge medio
1g 1h
PR unite (30g)
42

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di goaop/framework

Tutte le issue di goaop/framework

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.