Skip to content

Force-unset GEM_HOME/GEM_PATH/RUBYLIB in the harness scrub - #66

Open
JPDuchesne wants to merge 1 commit into
mainfrom
jpd/harness-env-scrub-gem-keys
Open

JPDuchesne wants to merge 1 commit into
mainfrom
jpd/harness-env-scrub-gem-keys

Conversation

@JPDuchesne

Copy link
Copy Markdown
Contributor

Summary

  • HarnessEnv.scrub relied on Bundler.original_env to undo harness activation, but keys exported before the dispatcher's bundler booted — shadowenv's GEM_HOME/GEM_PATH activating .ai-flow, dev's RUBYLIB — are recorded as "original" and were faithfully restored into every spawn. TOOLCHAIN_KEYS covered their siblings (GEM_ROOT, RUBY_ROOT) but not them.
  • Adds the three keys to the force-unset list and corrects the doc comment, which claimed the GEM_HOME leak was handled. Unlike dev's own entrypoint where GEM_HOME/GEM_PATH are legitimate user config (bin/dev: self-defending entrypoint — scrub foreign bundler activation before Ruby boots dev#94), at this spawn seam they can only be harness activation.
  • Fallout that motivated this: in plans run 32146691480 the /build agent inherited the polluted keys, fell back to per-call env -u scrubbing (the anti-pattern the boundary scrub exists to prevent), and its bundle install compiled Ruby 4.0 native extensions into the harness's 3.3 gem home — breaking every later ai-flow run on that runner, including origin-firing on dev#120. The runner's gem dir has been repaired with gem pristine.

Test plan

  • Regression test: aligns ENV with Bundler.original_env for the three keys (the pre-bundler-export state the restore half cannot undo) and asserts the overlay force-unsets them; failed before the fix, passes after
  • Full suite (250 tests, 0 failures), srb tc clean, RuboCop clean

Made with Cursor

Bundler.original_env only undoes what bundler itself mutated; keys the
harness exported before the dispatcher's bundler booted — shadowenv's
GEM_HOME/GEM_PATH activating .ai-flow, dev's RUBYLIB — are recorded as
"original" and were faithfully restored into every spawn. The leak made
a /build agent's bundle install compile Ruby 4.0 native extensions into
the harness's 3.3 gem home, breaking every later run on that machine
(plans run 32146691480, origin-firing failure on dev#120).

Co-authored-by: Cursor <cursoragent@cursor.com>
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

1 participant