Skip to content

fix: correctly recover runner tool on PATH (after sudo w/ secure_path). remove incorrect reading from GITHUB_PATH#5144

Draft
zarenner wants to merge 11 commits into
mainfrom
zr/recover-runner-tool-cache-path
Draft

fix: correctly recover runner tool on PATH (after sudo w/ secure_path). remove incorrect reading from GITHUB_PATH#5144
zarenner wants to merge 11 commits into
mainfrom
zr/recover-runner-tool-cache-path

Conversation

@zarenner

@zarenner zarenner commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

Recover runner toolcache bin directories into the chroot PATH used by the agent container when AWF runs under sudo or when the runner tool cache contains needed binaries. This avoids preflight failures (e.g., missing node) caused by sudo sanitizing PATH on self-hosted/DinD runners.

Root cause

When sudo is used inside some self-hosted runner environments, secure_path in /etc/sudoers may remove the runner's tool-cache bin directories from PATH. AWF's previous attempt to read per-step GITHUB_PATH was incorrect (it's per-step and cannot reliably recover prior step changes), which led to brittle behavior and confusing documentation.

What this change does

  • Adds discovery of RUNNER_TOOL_CACHE bin directories and merges them ahead of the existing PATH into AWF_HOST_PATH so chrooted agent processes can find tool binaries.
  • Removes the previous, incorrect attempt to read GITHUB_PATH for PATH recovery.
  • Restores toolchain env var recovery from GITHUB_ENV when AWF is running under sudo (unchanged behavior, but clarified).
  • Adds unit tests for edge cases around RUNNER_TOOL_CACHE discovery.

Testing

  • Unit tests added/updated to cover:
    • discovery of nested toolcache/*/<version>/<arch>/bin directories
    • behavior when RUNNER_TOOL_CACHE is not set
    • behavior when RUNNER_TOOL_CACHE points to non-directories or contains non-directory entries
    • recovery of toolchain vars from GITHUB_ENV when running as root with SUDO_UID set
  • Ran full test suite locally: npm test -- --coverage — all tests passed.

Risk and rollout

Low-risk. Changes are localized to host-path recovery logic and tests. If a regression is seen, revert the commit that modifies src/services/agent-environment/host-path-recovery.ts.

Notes for reviewers

  • Focus on the discoverRunnerToolCacheBinDirs logic and the test cases that exercise non-directory entries and permission-safe reads.
  • This change intentionally removes the incorrect GITHUB_PATH merging; see docs update in the branch for rationale.

Related

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Documentation Preview

Documentation build failed for this PR. View logs.

Built from commit 1374fa0

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Coverage Regression Detected

This PR decreases test coverage. Please add tests to maintain coverage levels.

Overall Coverage

Metric Base PR Delta
Lines 97.30% 97.29% ➡️ -0.01%
Statements 97.16% 97.11% 📉 -0.05%
Functions 98.84% 98.84% ➡️ +0.00%
Branches 91.92% 91.88% 📉 -0.04%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/services/agent-environment/host-path-recovery.ts 100.0% → 93.0% (-6.98%) 100.0% → 88.9% (-11.12%)
src/workdir-setup.ts 92.7% → 94.5% (+1.82%) 92.7% → 94.5% (+1.82%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

@zarenner zarenner changed the title Recover runner tool cache paths in chroot Recover runner tool cache paths in chroot (fix PATH preflight failures) Jun 17, 2026
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

⚠️ Coverage Regression Detected

This PR decreases test coverage. Please add tests to maintain coverage levels.

Overall Coverage

Metric Base PR Delta
Lines 97.30% 97.58% 📈 +0.28%
Statements 97.16% 97.51% 📈 +0.35%
Functions 98.84% 98.68% 📉 -0.16%
Branches 91.92% 92.99% 📈 +1.07%
📁 Per-file Coverage Changes (5 files)
File Lines (Before → After) Statements (Before → After)
src/services/agent-environment/host-path-recovery.ts 100.0% → 96.4% (-3.58%) 100.0% → 96.7% (-3.34%)
src/workdir-setup.ts 92.7% → 94.5% (+1.82%) 92.7% → 94.5% (+1.82%)
src/logs/audit-enricher.ts 89.4% → 95.7% (+6.38%) 83.6% → 95.1% (+11.48%)
src/services/agent-volumes/docker-host-staging.ts 87.2% → 95.7% (+8.51%) 87.8% → 95.9% (+8.16%)
src/commands/validators/log-and-limits.ts 90.3% → 100.0% (+9.68%) 90.3% → 100.0% (+9.68%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

@zarenner zarenner Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was wrong - GITHUB_PATH is meant to be written to (to then have the runner automatically add it to PATH in subsequent steps). It is not meant to be read from, and will be empty again on each new step.

@zarenner zarenner changed the title Recover runner tool cache paths in chroot (fix PATH preflight failures) fix: correctly recover runner tool on PATH (after sudo w/ secure_path). remove incorrect reading from GITHUB_PATH Jun 17, 2026
@zarenner zarenner marked this pull request as ready for review June 17, 2026 16:01
Copilot AI review requested due to automatic review settings June 17, 2026 16:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates AWF’s GitHub Actions path-recovery behavior so that tools installed into the runner tool cache remain discoverable inside the chroot when AWF is invoked under sudo (e.g., when secure_path sanitizes PATH). It removes the previous (incorrect) attempt to recover paths by reading $GITHUB_PATH, and instead derives AWF_HOST_PATH from the inherited PATH plus bin directories discovered under RUNNER_TOOL_CACHE.

Changes:

  • Build AWF_HOST_PATH by prepending discovered RUNNER_TOOL_CACHE/**/bin directories ahead of the current PATH, and stop reading $GITHUB_PATH.
  • Update/replace unit tests to cover RUNNER_TOOL_CACHE discovery and to align with the new PATH-building logic.
  • Update documentation to describe the new recovery mechanism and explicitly note that $GITHUB_PATH is not used.
Show a summary per file
File Description
tests/chroot-path-ordering.test.sh Updates fallback-path ordering assertions and adds coverage for self-hosted runner toolcache scanning.
src/services/agent-service.test.ts Reworks PATH-recovery unit tests to validate RUNNER_TOOL_CACHE-based merging behavior.
src/services/agent-environment/host-path-recovery.ts Implements RUNNER_TOOL_CACHE bin-dir discovery and merges into AWF_HOST_PATH; continues sudo $GITHUB_ENV recovery for toolchain vars.
src/github-env.ts Removes $GITHUB_PATH helpers and generalizes path merging helper as prependPathEntries.
src/github-env.test.ts Removes $GITHUB_PATH tests and renames/adjusts tests for prependPathEntries.
src/docker-manager-utils.test.ts Drops tests tied to removed $GITHUB_PATH helpers.
docs/environment.md Updates GitHub Actions tool-availability docs to describe PATH + RUNNER_TOOL_CACHE recovery (and not $GITHUB_PATH).
containers/agent/entrypoint.sh Removes $GITHUB_PATH ingestion in the fallback PATH construction branch.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 8/8 changed files
  • Comments generated: 5

Comment on lines 12 to 16
const runnerToolCacheBinDirs = discoverRunnerToolCacheBinDirs(process.env.RUNNER_TOOL_CACHE);
environment.AWF_HOST_PATH = prependPathEntries(process.env.PATH, runnerToolCacheBinDirs);
if (runnerToolCacheBinDirs.length > 0) {
logger.debug(`Merged ${runnerToolCacheBinDirs.length} runner tool cache bin path(s) into AWF_HOST_PATH`);
}
Comment on lines +479 to +482
// create a file instead of a directory
const tmpFile = fs.mkdtempSync(path.join(os.tmpdir(), 'awf-tool-cache-file-')) + '.file';
fs.writeFileSync(tmpFile, 'not a dir');
process.env.RUNNER_TOOL_CACHE = tmpFile;
Comment thread src/services/agent-service.test.ts Outdated
Comment thread docs/environment.md Outdated
Comment on lines 72 to 77
# Run the script in a sub-shell with a clean environment
(
export PATH="${base_path}"
[ -n "${github_path_file}" ] && export GITHUB_PATH="${github_path_file}"
eval "${script}"
eval "${check_expr}"
)
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

✅ Copilot review passed with no inline comments.

@zarenner Add the ready-for-aw label to this PR to trigger agentic CI smoke tests.

@zarenner zarenner marked this pull request as draft June 17, 2026 18:50
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.

2 participants