Skip to content

Isolate per-job runtime paths and ownership-checked cleanup - #78863

Closed
lpcox wants to merge 28 commits into
mainfrom
copilot/finish-runtime-isolation-again
Closed

lpcox wants to merge 28 commits into
mainfrom
copilot/finish-runtime-isolation-again

Conversation

@lpcox

@lpcox lpcox commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Jobs sharing a self-hosted runner host currently reuse /tmp/gh-aw, allowing startup to delete another job’s runtime files while teardown cannot safely reclaim leftovers. This change introduces invocation-private paths and owned-resource cleanup.

  • Private runtime allocation

    • Allocate collision-resistant, owner-only runtime and trusted setup roots.
    • Propagate paths through generated workflows, sandbox mounts, gateway configuration, logs, audit outputs, detection artifacts, and CLI consumers.
    • Preserve read-only setup mounts separately from writable runtime state.
  • Scoped lifecycle

    • Replace global startup deletion with ownership-checked cleanup using tokens and saved directory identities.
    • Leave legacy and unowned state untouched; avoid sudo reclamation.
    • Suffix gh-aw sidecar names per invocation and preserve cache-save/post-action ordering.
  • Concurrency regressions

    • Cover simultaneous setup processes, scoped cleanup against one Docker daemon, interrupted setup, stale state, and ownership/symlink rejection.
  • Remaining boundary

    • Full shared-daemon AWF isolation remains incomplete. Upstream fixed container/network names and existing listener ports still prevent unrestricted concurrent execution. Runner documentation calls out this limitation.

@lpcox lpcox changed the title [WIP] Finish per-job runtime isolation for self-hosted jobs Isolate per-job runtime paths and ownership-checked cleanup Nov 18, 2026
@lpcox
lpcox marked this pull request as ready for review November 18, 2026 00:35
Copilot AI adaptive review requested due to automatic review settings November 18, 2026 00:35

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.

🟡 Changes recommended

Unresolved runtime-path relocation and expansion errors break work-queue and Windows workflows, while cleanup can cause otherwise successful jobs to fail.

14 open issues
What changed in this PR

Advances #78555 by moving gh-aw jobs from shared temporary state to invocation-private runtime and trusted setup directories, with ownership-checked cleanup for self-hosted runners.

Changes:

  • Propagates private paths through workflow generation, WSL, sandbox mounts, MCP configuration, logs, artifacts, and CLI consumers.
  • Adds token- and directory-identity checks for cleanup, invocation-specific sidecar names, and cache-save ordering.
  • Adds isolation regressions and documents destination migration and remaining shared-Docker limitations.
File Description
pkg/​workflow/​windows_runner.go Adapts WSL bootstrap, paths, and environment forwarding.
pkg/​workflow/​runtime_isolation.go Adds allocation, relocation, and fallback cleanup.
pkg/​workflow/​runtime_isolation_test.go Covers compiler isolation and lifecycle behavior.
pkg/​workflow/​runtime_isolation_cache.go Splits runtime cache restore/save before cleanup.
pkg/​workflow/​runner_temp_safety.go Integrates runtime isolation into finalization.
pkg/​workflow/​mcp_setup_gateway.go Forwards isolation variables to the gateway.
pkg/​workflow/​mcp_renderer_builtin.go Adds isolation variables to built-in MCP configurations.
pkg/​workflow/​mcp_config_refactor_test.go Updates expected MCP environment lists.
pkg/​workflow/​jobs_test.go Updates Windows runtime-path expectations.
pkg/​workflow/​compiler_yaml_step_generation.go Quotes script-mode setup and cleanup paths.
pkg/​workflow/​compiler_yaml_ai_execution.go Removes ownership credentials from agent execution.
pkg/​workflow/​compiler_difc_proxy.go Configures invocation-scoped certificate trust.
pkg/​workflow/​awf_installer_integration_test.go Updates relocated installer-path expectations.
pkg/​workflow/​awf_command_builder.go Propagates paths and clears ownership credentials.
pkg/​cli/​runtime_paths.go Resolves private paths and validates cache roots.
pkg/​cli/​runtime_paths_test.go Covers path resolution and cache isolation.
pkg/​cli/​runtime_owner_unix.go Checks Unix runtime-directory ownership.
pkg/​cli/​runtime_owner_other.go Rejects unsupported ownership checks.
pkg/​cli/​mcp_tools_privileged.go Relocates MCP logs and audit outputs.
pkg/​cli/​mcp_tool_arguments_test.go Handles fallible runtime-path resolution.
pkg/​cli/​mcp_timeout_test.go Updates audit argument assertions.
pkg/​cli/​mcp_logs_positional_test.go Updates logs argument assertions.
pkg/​cli/​mcp_logs_guardrail.go Anchors cache operations to opened roots.
pkg/​cli/​mcp_logs_episode.go Relocates episode-log output directories.
pkg/​cli/​logs_utils.go Recognizes flattened private-root log paths.
pkg/​cli/​logs_timeout_test.go Handles runtime-path errors in budget tests.
pkg/​cli/​logs_storage_options_test.go Updates continuation argument handling.
pkg/​cli/​logs_episode_retrieval_command_test.go Updates episode command argument handling.
docs/​src/​content/​docs/​reference/​self-hosted-runners.md Documents cleanup ownership and concurrency limits.
actions/​setup/​wsl.js Adds setup and post-action WSL dispatch.
actions/​setup/​sh/​stop_difc_proxy.sh Removes system trust-store cleanup.
actions/​setup/​sh/​start_difc_proxy.sh Uses dynamic ports and local certificate trust.
actions/​setup/​sh/​start_cli_proxy.sh Publishes the selected CLI proxy port.
actions/​setup/​sh/​create_gh_aw_tmp_dir.sh Validates and prepares private runtime directories.
actions/​setup/​sh/​create_gh_aw_tmp_dir_test.sh Covers unsafe-directory rejection without reclamation.
actions/​setup/​setup.sh Allocates private roots and relocates staged assets.
actions/​setup/​README.md Documents private paths and destination migration.
actions/​setup/​post.js Uses saved ownership state for teardown.
actions/​setup/​js/​start_cli_proxy.test.cjs Covers dynamic and legacy proxy ports.
actions/​setup/​js/​setup_invocation_isolation.test.cjs Covers concurrent setup and scoped teardown.
actions/​setup/​js/​runtime_isolation.test.cjs Covers ownership, relocation, and sidecar isolation.
actions/​setup/​js/​runtime_isolation.cjs Implements allocation, validation, relocation, and cleanup.
actions/​setup/​js/​prompt_literal_values.cjs Relocates restored literal runtime paths.
actions/​setup/​js/​memory_validation_isolation.test.cjs Covers decoded validator-path relocation.
actions/​setup/​js/​memory_custom_validation.cjs Relocates custom validator script paths.
actions/​setup/​js/​create_prompt.test.cjs Covers prompt relocation without source mutation.
actions/​setup/​js/​create_prompt.cjs Relocates rendered prompt paths.
actions/​setup/​js/​chroot_home_cleanup.test.js Updates scoped post-cleanup expectations.
actions/​setup/​js/​apply_samples.cjs Places sample patches inside invocation runtime roots.
actions/​setup/​index.js Allocates roots and coordinates setup completion.
actions/​setup/​clean.sh Adds owned cleanup and post-action deferral.
actions/​setup/​action.yml Updates the destination input description.

Review effort: Max (adaptive)

" id: setup\n",
" run: |\n",
" bash /tmp/gh-aw/actions-source/actions/setup/setup.sh\n",
" bash \"/tmp/gh-aw/actions-source/actions/setup/setup.sh\"\n",

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.

Updated the script-mode, Windows runner, and work-queue path assertions in 9e476a0; the focused compilation tests pass.


func runtimeEarlyCleanupStep(windows bool) string {
var step strings.Builder
step.WriteString(" - name: Clean isolated runtime directories\n if: ${{ always() && env.GH_AW_SETUP_ACTION_COMPLETE != 'true' }}\n")

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.

Owned-root cleanup now warns and continues when removal fails. Added a regression simulating an unremovable owned root in fb feb14f.

Comment thread pkg/workflow/runtime_isolation.go Outdated
}
}
step.WriteString(" run: |\n")
for _, line := range windowsWSLRunWrapper(script, names) {

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.

The Windows allocator remains encoded without rewriting its legacy-prefix substitutions; the regression is covered in 9e476a0.

Comment thread pkg/workflow/runtime_isolation.go Outdated
if inExecutable || singleLineExecutableRE.MatchString(source) {
// Setup roots inherit arbitrary RUNNER_TEMP characters: keep them
// data-bound, never splice them into executable Actions expressions.
rewritten = strings.ReplaceAll(rewritten, setupRootExpression, "${GH_AW_SETUP_ROOT}")

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.

Quoted-heredoc paths now remain data-bound: Linux uses the Actions environment expression, and the WSL wrapper substitutes private-root markers. Added regression in fbfeb14.

Comment thread actions/setup/index.js Outdated
process.env.INPUT_JOB_NAME = inputJobName;
process.env.INPUT_OTLP_OIDC_TOKEN = inputOTLPOIDCToken;
const { run } = require(path.join(__dirname, "js", "action_setup_otlp.cjs"));
const { run } = require(path.join(process.env.GH_AW_SETUP_ROOT, "actions", "action_setup_otlp.cjs"));

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.

Setup telemetry now loads from the validated custom destination, saves that relative path in action state, and uses it during post cleanup in 9e476a0.

text = strings.ReplaceAll(text, conclusionWorkQueueActivationArtifactDir, setupRootExpression+"/activation")
text = strings.ReplaceAll(text, constants.GhAwRootDir+"-protected-capture-", setupRootExpression+"/protected-capture-")
text = logicalSetupPathRE.ReplaceAllString(text, setupRootExpression+"$1")
text = logicalRuntimePathRE.ReplaceAllString(text, runtimeRootExpression+"$1")

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.

Cache actions now use a stable workspace-relative archive path and transfer content to/from the private runtime root in 9e476a0.

Comment thread pkg/workflow/runtime_isolation_cache.go Outdated
func scriptRuntimeCacheEdits(steps *yaml.Node) ([]runtimeYAMLEdit, error) {
cleanupLine := -1
for _, step := range steps.Content {
if run := runtimeMappingValue(step, "run"); run != nil && strings.Contains(run.Value, "/actions/setup/clean.sh") {

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.

Cache-save generation now recognizes the stable Clean Scripts step name, preserving save-before-cleanup ordering for Windows wrappers in 9e476a0.

Comment thread pkg/workflow/runtime_isolation_cache.go Outdated
Comment on lines +104 to +108
inputs := runtimeMappingValue(step, "with")
if lookup := runtimeMappingValue(inputs, "lookup-only"); lookup != nil && lookup.Value == "true" {
return rendered, "", nil
}
save, err := renderScriptRuntimeCacheSave(step, inputs, id, ref)

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.

Lookup-only combined cache actions now still generate the conditional save step; the regression expectation was updated in 9e476a0.

}
indentation := line[:len(line)-len(strings.TrimLeft(line, " "))]
replacement := constants.GhAwRootDir + strings.TrimPrefix(path, constants.TmpGhAwDir)
replacement := windowsRuntimeRootExpression + strings.TrimPrefix(path, constants.TmpGhAwDir)

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.

Windows agent-output rewriting now applies wslpath to the private runtime root in 9e476a0.

"GH_AW_SAFE_OUTPUTS_CONFIG_PATH",
"GH_AW_SAFE_OUTPUTS_TOOLS_PATH",
"GH_AW_WSL_WORKING_DIRECTORY",
"GH_AW_WSL_WORKING_DIRECTORY", "GH_AW_RUNTIME_ROOT", "GH_AW_SETUP_ROOT", "GH_AW_RUNTIME_TOKEN", "GH_AW_RESOURCE_SUFFIX",

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.

Both proxy-port variables are now forwarded into WSL alongside the runtime paths in 9e476a0.

@lpcox

lpcox commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot address review feedback

lpcox and others added 2 commits November 18, 2026 01:42

Copilot AI commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

@copilot address review feedback

Pushed the review fixes in 9e476a0e and refreshed both compiler golden sets in 84a8fc69. Targeted runtime, cache, work-queue, CLI, and telemetry tests passed, and 11 affected workflows compiled successfully. The full validation gate did not complete, and CodeQL timed out.

Comment thread pkg/workflow/runtime_isolation.go Resolved
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/workflow/compiler_yaml_step_generation.go:250): address unresolved feedback - Review comment
  3. Review (pkg/workflow/runtime_isolation.go:98): address unresolved feedback - Review comment
  4. Review (pkg/workflow/runtime_isolation.go:208): address unresolved feedback - Review comment
  5. Review (pkg/workflow/runtime_isolation.go:350): address unresolved feedback - Review comment
  6. Review (actions/setup/index.js:85): address unresolved feedback - Review comment
  7. Review (actions/setup/js/runtime_isolation.cjs:203): address unresolved feedback - Review comment
  8. Review (pkg/workflow/runtime_isolation.go:40): address unresolved feedback - Review comment
  9. Review (pkg/workflow/runtime_isolation.go:40): address unresolved feedback - Review comment
  10. Review (pkg/workflow/runtime_isolation.go:52): address unresolved feedback - Review comment
  11. Review (pkg/workflow/runtime_isolation.go:53): address unresolved feedback - Review comment
  12. Review (pkg/workflow/runtime_isolation_cache.go:46): address unresolved feedback - Review comment
  13. Review (pkg/workflow/runtime_isolation_cache.go:108): address unresolved feedback - Review comment
  14. Review (pkg/workflow/windows_runner.go:299): address unresolved feedback - Review comment
  15. Review (pkg/workflow/windows_runner.go:565): address unresolved feedback - Review comment

Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering.

Structured data
{
  "completed_task": 0,
  "head": "84a8fc69cf9a52b94397fd0c686f3e3555d2b652",
  "kind": "requested",
  "schema_version": "1",
  "state": "79a45a61c0fc07ab09caad71b125476ecdbd4e6af16eac133eef1865b45f2f3b",
  "work": [
    "04150ba1632d72ffb57d41481c5be7cd6089a10e3761f08d92d8233c761edf3a",
    "067a6d2e2384d71b24d61d4152c8d175417402d2409f074d00c63b810804a7be",
    "13c62ff909c0f7ddc8e610b81daf29b82b8a09bdf95fc0132670c96a2eae382e",
    "18c090c32aa686391b58200f4d07f9fd0681b854c3ae5e1c72d53ba38eecd1aa",
    "397b87021dd578525178722e6f3296503339e363b80a84641fa5bab1365e366a",
    "564dcff33d44dafda95bc273f314a43dbddd629f782b5f46cabbd1d5de22a2fe",
    "5d5ebc0a82ba25f584eebbb416ff4fdab9db6483946202bbe17822753ccd822b",
    "72825baf1815c33fbaa339f4df7329afc6d999f2cfad98c47cef18867f9970be",
    "a34a9ea1be05268a4c6ac91b1d649581e3f6315098f8ab9c5a201e774abedc92",
    "a386365cf49a93aa37646badecb230d51ec16b64b2e7aeb0d9df527e7199cd9b",
    "bcf6343e9f09ecdb95c0d65fb700bf2eb2bb3dbfc79167dc11e1a43a40e86740",
    "bdd5ed57dc25314dc9998c79fbb16657cc088143da7a6b9e344795f2bcc5ec4c",
    "ecb8a4a26cb1bae2ea3a140e373a8a0f81d569c039cfa5e64e7ef3a7ed5484ce",
    "f6115678b8fd92659ff527261bc8a224a8e33b208186ca0464ef1b338a3c023a"
  ],
  "workflow": "pr-sous-chef"
}

Generated by 👨🍳 PR Sous Chef · pi · routed: haiku55 xhigh · ~3 AIC · ⌖ ~2 AIC · ⊞ 7K · ◷
Comment /souschef to run again

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Comment thread actions/setup/js/create_prompt.cjs Resolved
@lpcox

lpcox commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot merge main and resolve conflicts

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@lpcox

lpcox commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot fix the failing ci checks

…e-isolation-again

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
gh-aw-bot and others added 2 commits November 18, 2026 21:38
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Comment thread actions/setup/js/create_prompt.cjs Outdated
* @param {string} text
*/
function assertNoPromptControlMarkers(section, text) {
const controlMarkerPattern = /<\|im_start\|>|<\|im_end\|>|<\|system\|>|<\|assistant\|>|<\|user\|>|BEGIN\s+SYSTEM\s+PROMPT|END\s+SYSTEM\s+PROMPT/iu;
lpcox and others added 2 commits November 18, 2026 22:03
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Comment thread pkg/cli/runtime_paths.go
// cliRuntimePath resolves canonical paths for binary consumers that cannot be
// rewritten by the workflow compiler. An unset root preserves standalone CLI use.
// This validates path syntax, not filesystem ownership.
func cliRuntimePath(canonical string) (string, error) {
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

Warning

Threat detection engine error

Threat detection could not complete its analysis due to a tooling error. This is not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs to troubleshoot the error.

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.

Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering.

Structured data
{
  "completed_task": 0,
  "head": "c1d21b37b10098e43368c484aec936a022f2dacf",
  "kind": "requested",
  "schema_version": "1",
  "state": "48e00ac62249ed8f651de46f1dcef8bb26dc04169573cbcc9724a37a80e0c34a",
  "work": [],
  "workflow": "pr-sous-chef"
}

Generated by 👨🍳 PR Sous Chef · pi · routed: haiku55 xhigh · ~3 AIC · ⊞ 7K · ◷
Comment /souschef to run again

gh-aw-bot and others added 2 commits November 19, 2026 00:45
…e-isolation-again

# Conflicts:
#	.github/workflows/agentic-token-trend-audit.lock.yml
#	.github/workflows/smoke-claude.lock.yml
#	.github/workflows/smoke-codex.lock.yml
#	.github/workflows/smoke-copilot.lock.yml
#	.github/workflows/smoke-factory.lock.yml
#	.github/workflows/smoke-gemini.lock.yml
#	.github/workflows/smoke-opencode.lock.yml
#	.github/workflows/smoke-test-tools.lock.yml
#	.github/workflows/workflow-normalizer.lock.yml

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@lpcox

lpcox commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot address review feedback and fix all failing ci checks

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
if (translated.error || translated.status !== 0) throw new Error("Unable to persist native Windows setup path");
persistedValues.GH_AW_SETUP_ROOT = translated.stdout.trim();
}
append(env.GITHUB_ENV, persistedValues);
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

Warning

Threat detection engine error

Threat detection could not complete its analysis due to a tooling error. This is not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs to troubleshoot the error.

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Fix failing check impacted-go-tests (FAILURE): Check run.
  3. Fix failing check JS Tests (shard 1/8) (FAILURE): Check run.
  4. Fix failing check Unit tests (A-B) (FAILURE): Check run.
  5. Fix failing check Unit tests (C) (FAILURE): Check run.
  6. Fix failing check Unit tests (D-G) (FAILURE): Check run.
  7. Fix failing check Unit tests (N-R) (FAILURE): Check run.
  8. Fix failing check Unit tests (S-Z and other) (FAILURE): Check run.

Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering.

Structured data
{
  "completed_task": 0,
  "head": "7a5648ecfb7403641eb016de37cd3aee901ae08b",
  "kind": "requested",
  "schema_version": "1",
  "state": "e0d5026764e08a14b9936a050327996c26416eb8f72b1f5e1438bb5bc78aa4a6",
  "work": [
    "070b5fed6c77e6f99af8aa0864293d562a676d9316dad5428bdc04c242733226",
    "225d12c41865546fe8081fb8f05cc202f7419fea92819f49b031ccb8d73b2538",
    "42e5d572d9d75b7168fe7d0aeda0717cc07e65ed240f6d299e6fec661214f1ac",
    "48a183c3e95bbf17204364ee4c81061de61a873e8585852342c81727b022959c",
    "49c80a00fb3786e9cd4801737bd50a4de83978035bb4a487a6bb6689f2c3cd03",
    "be8977fed8539981a9de7f424c3c95730603faded3a88272a303c0b1b996a2af",
    "e9d7501fc834b70ac771af5e7694ba7f29ea683b65e0f01f096571f99da4b76f"
  ],
  "workflow": "pr-sous-chef"
}

Generated by 👨🍳 PR Sous Chef · pi · routed: haiku55 xhigh · ~4 AIC · ⊞ 7K · ◷
Comment /souschef to run again

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.

Finish per-job runtime isolation instead of sharing /tmp/gh-aw across self-hosted jobs

5 participants