Skip to content

fix: env-cache fast path dead on Codex/Gemini; PLUGIN_ROOT accepted unvalidated (#469, #471) - #476

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/469
Aug 29, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/469

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #469
Closes #471

Two non-blocking findings from the v0.24.0 round-1 release audit.

#469 -- the #227 env-cache fast path was permanently dead on Codex and Gemini CLI.
scripts/lib-env-cache.sh's _remember_env_cache_path keyed the cache file on the raw
CLAUDE_PROJECT_DIR, which neither host ever sets: resolve-paths.sh:270 exports the
resolved value only after a full slow-path run, so on those hosts a cache was written on
every invocation and never found by _remember_env_cache_load, which runs in a fresh
process before that export exists. Written every time, hit never -- so every prompt and
every tool call took the full resolve-paths.sh -> bootstrap-dirs.sh -> log.sh chain,
on a hook whose own header says a non-zero exit blocks the prompt and erases what the user
typed.

The key now falls back to REMEMBER_HOOK_CWD (the same fallback #411/#444 already gave
every hook from its own stdin cwd) when CLAUDE_PROJECT_DIR is unset, and the load-side
identity cross-check and publish-side guard compare against that same fallback-aware key.

A self-review pass found a second half: the key was recomputed per call, so a publish made
after resolve-paths.sh had normalised and exported CLAUDE_PROJECT_DIR (Windows/Git-Bash
drive-letter rewriting) keyed under the normalised string while an earlier load in the same
process had keyed on the raw one -- the same never-agree bug relocated to Windows. The key
is pinned once per process in the second commit. Reproduced genuinely red on the pre-pin
code by forcing OSTYPE=msys, the technique tests/test_windows_native_hook_cwd_448.py
already uses.

#471 -- PLUGIN_ROOT was accepted with only a directory-exists check. Four lines below
a sibling branch that already checks for a specific marker file. An unrelated directory that
merely happens to be named by that generic, unnamespaced variable became the directory this
plugin loads and executes from -- PIPELINE_DIR is the python3 -m pipeline.shell import
root, the source of scripts/log.sh, the executable scripts/save-session.sh and the
hooks.d dispatch root. Now validated with the same pipeline/haiku.py marker check,
falling through to CLAUDE_PLUGIN_ROOT on failure, which turns a name collision into a
fallback rather than a wrong execution root. #407's precedence order is unchanged.

Tests. tests/test_env_cache_hook_cwd_key_469.py (274 lines) and
tests/test_plugin_root_validated_471.py (135 lines), both written against the old code and
watched fail first. tests/test_host_shell_parity_407.py's alias test used to pin an empty
CLAUDE_PLUGIN_ROOT as accepted -- exactly the gap #471 closes -- so it now builds a
directory that actually looks like a plugin install. Three pre-existing fixtures built a fake
plugin root with no pipeline/haiku.py; each is given a stub so the new validation does not
break them.

Platform. The #469 Windows half is reasoned, plus a forced-OSTYPE reproduction on
macOS; it is not observed on a real Windows box. The CI matrix is what will observe it.

…validated

#469: scripts/lib-env-cache.sh keyed its cache file on the raw
CLAUDE_PROJECT_DIR, which Codex and Gemini CLI never set -- resolve-paths.sh
exports the RESOLVED value only after a full slow-path run, so a cache was
written on every invocation on those hosts and never found by a fresh
process reading it before that export exists. _remember_env_cache_path now
falls back to REMEMBER_HOOK_CWD (the same fallback #411/#444 already gave
every hook), and the load-side identity check and publish-side guard/record
now compare against that same fallback-aware key.

#471: scripts/resolve-paths.sh accepted PLUGIN_ROOT/CLAUDE_PLUGIN_ROOT with
only [ -d ], four lines above a sibling branch that already checks for
pipeline/haiku.py. An unrelated directory merely named by the generic
PLUGIN_ROOT var could become this plugin's execution root. Now validated
the same way, with a fallthrough to CLAUDE_PLUGIN_ROOT on a PLUGIN_ROOT
collision. tests/test_host_shell_parity_407.py's alias test, which used to
pin an empty directory as accepted, is updated deliberately to build a real
plugin install.

Three pre-existing test fixtures (test_post_tool_hook_stdin_size.py,
test_staging_growth_warning_349.py,
test_staging_lock_missing_log_dependency_394.py) built a fake
CLAUDE_PLUGIN_ROOT with no pipeline/haiku.py; given a stub/symlink so the
new #471 validation does not break them.

Co-Authored-By: Max <noreply>
Self-review finding on the #469/#471 commit: _remember_env_cache_path was
recomputed on every call, so a publish call made after resolve-paths.sh had
already normalised and exported CLAUDE_PROJECT_DIR (Windows/Git-Bash
drive-letter rewriting) would key the cache under that normalised string --
a different one than the raw REMEMBER_HOOK_CWD an earlier
_remember_env_cache_load call in the same process had already keyed on.
Write and read would still never agree, just relocated to Windows instead
of Codex/Gemini's absent CLAUDE_PROJECT_DIR. The key is now pinned once per
process (resolve-paths.sh only resolves once per hook invocation, so this
is safe): once _REMEMBER_ENV_CACHE_KEY is set, later calls in the same
process reuse it instead of asking the environment again.

Reproduced and verified genuinely red on the pre-pin code by forcing
OSTYPE=msys, which runs the real drive-letter-rewriting branch of
_remember_normalize_win_path regardless of host OS -- the same technique
tests/test_windows_native_hook_cwd_448.py already uses.

Co-Authored-By: Max <noreply>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant