Skip to content

Don't invalidate container cache on user-interactions in the shell#4924

Merged
ondrejmirtes merged 1 commit into
phpstan:2.1.xfrom
staabm:cache-container
Feb 14, 2026
Merged

Don't invalidate container cache on user-interactions in the shell#4924
ondrejmirtes merged 1 commit into
phpstan:2.1.xfrom
staabm:cache-container

Conversation

@staabm

@staabm staabm commented Feb 14, 2026

Copy link
Copy Markdown
Contributor

refs phpstan/phpstan#14072 (comment)


ENV variables used for building the container key sometimes change, based on user interactions in the shell.

Image

it happens after you cd between folders and run PHPStan again.

see https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html

OLDPWD
The previous working directory as set by the cd builtin.


I see another case: the container invalidates as soon as you re-size the shell window, because a ENV var exists which defines the LINES and COLUMNS in the window

Image

while I think this is just a workaround for a more general problem - I see no way atm to find out which ENV vars are relevant for us and which are not

@staabm staabm marked this pull request as ready for review February 14, 2026 07:57
@phpstan-bot

Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes ondrejmirtes merged commit e2067b2 into phpstan:2.1.x Feb 14, 2026
638 of 643 checks passed
@ondrejmirtes

Copy link
Copy Markdown
Member

Thank you!

@staabm staabm deleted the cache-container branch February 14, 2026 08:20
SanderMuller added a commit to SanderMuller/phpstan-src that referenced this pull request Jun 24, 2026
The container cache key included the entire environment (minus a hand-maintained
denylist - phpstan#4924, phpstan#4925), so any unrelated env var that differs between invocations
(CI runners inject per-job vars on every run) flipped the key and forced a full
container recompile + ignoreErrors re-validation.

The container only depends on the environment through (a) %env.X% references in
loaded configs and (b) env read at build time by a CompilerExtension (PHPStan reads
only PHPSTAN_FNSR, in FnsrExtension::beforeCompile()). Keep exactly those env vars
in the cache key - the %env.NAME% names (matching Nette's %([\w.-]*)% grammar) plus
self::BUILD_TIME_ENV_VARIABLES - and drop the rest. The container parameters still
carry the full env, so %env.*% resolution is unaffected; this only narrows the key.

ContainerCacheKeyEnvGuardTest enforces that every env var read at build time by a
CompilerExtension is declared, so a future build-time getenv() cannot silently reuse
a stale container.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants