Skip to content

Serialize self-hosted AWF jobs sharing a Docker daemon - #79119

Merged
lpcox merged 13 commits into
mainfrom
copilot/isolate-awf-docker-resources
Nov 21, 2026
Merged

lpcox merged 13 commits into
mainfrom
copilot/isolate-awf-docker-resources

Conversation

@lpcox

@lpcox lpcox commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

AWF’s fixed Docker names and listener ports can collide across simultaneous self-hosted jobs, even with isolated runtime paths. This change serializes the shared-daemon lifecycle until upstream supports resource namespacing.

  • Daemon coordination

    • Reserve an atomic Docker lease from setup through always/post cleanup.
    • Assign unique invocation identities across runs, retries, and matrix copies.
    • Bound contention waits to ten minutes.
  • Ownership and recovery

    • Require a validated lease before startup or teardown.
    • Label gh-aw service containers and verify ownership before replacement or cleanup.
    • Retain leases when resources remain; never automatically expire or steal interrupted jobs’ leases.
  • Concurrency contract

    • Document shared resources, supported topology, and administrator recovery.
    • Add two-process Docker regressions for shared-name/listener contention and interruption.

Compatibility boundary: shared-daemon jobs are serialized, not independently namespaced. Unrestricted parallelism still requires isolated hosts/VMs and Docker daemons.

@lpcox lpcox changed the title [WIP] Fix Docker resource isolation for concurrent AWF jobs Serialize self-hosted AWF jobs sharing a Docker daemon Nov 18, 2026
@lpcox
lpcox marked this pull request as ready for review November 21, 2026 18:23
Copilot AI adaptive review requested due to automatic review settings November 21, 2026 18:23
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Specification Reviewer completed successfully!

Generated by PR Specification Reviewer for #79119 · copilot · gpt56 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.7K · ◷

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

🧪 Test quality analysis by Test Quality Sentinel · copilot · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ⊞ 7.2K · ◷

@github-actions

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer is reviewing this pull request using Matt Pocock's engineering skills...

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

PR Code Quality Reviewer

Outcome: reported_action

The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt56 · ~5 AIC · ⌖ ~1 AIC · ⊞ 1.6K · ◷

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated by Ponytail Reviewer for #79119 · codex · routed: gpt61 medium · ~5 AIC · ⌖ ~1 AIC · ⊞ 185 · ◷

@lpcox

lpcox commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

@github-actions github-actions Bot 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.

Reviewed head 5257544dd92f585abbd5db9da6d59be136f702bb.

Applicable contract: docs/src/content/docs/reference/self-hosted-runners.md, Shared-daemon concurrency (§ Shared-daemon concurrency / Compatibility resource inventory). The documented lease acquisition is not implementable as written: docker image import receives 1024 zero bytes rather than a valid archive, so setup fails before reserving the lease. This is blocking because the advertised self-hosted serialization path cannot start. One inline finding was published. No other directly applicable normative specification was identified; this static review did not execute tests or workflows.

Generated by PR Specification Reviewer for #79119 · copilot · gpt50 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.7K
Comment /review-specs to run again


Self-hosted jobs using the same Docker daemon are **serialized**, not run concurrently inside AWF. Setup acquires the daemon-visible `gh-aw-daemon-lease` container before modifying shared runtime state and holds it through the action's always/post cleanup. Another job waits up to ten minutes, then fails without starting AWF or stopping the lease owner's services. Startup retries retain the lease. Separate runs, reruns, and matrix copies receive distinct SHA-256 invocation identities incorporating run metadata and a random UUID.

The lease and its private, non-executable image carry the `io.github.gh-aw.invocation` label. The container also records repository, run ID, attempt, and job labels. Acquisition uses Docker's atomic container-name reservation, not a local lock file, so separate runner processes targeting the same daemon coordinate. Cleanup verifies the invocation label and removes the lease by immutable container ID. No lock image is downloaded or started.

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.

This contract currently cannot be fulfilled by the acquisition implementation: docker_lease.cjs calls docker image import with Buffer.alloc(1024) as stdin (line 110), which is not a valid tar archive for docker image import, so setup fails before creating the lease. Please use a valid minimal image/archive (while preserving the non-executable/no-download guarantees) or adjust the implementation and tests before documenting this behavior.

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 lease archive is now built as a valid ustar containing the locally generated static pause binary; the lease container runs it without network access, and no image or executable is downloaded. The archive and ELF headers are covered by the lease tests.

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (spec-review-history)
{"id":"ldg-62f8aa22-2e10-410e-8e87-409dd1415c05","parents":[],"payload":{"id":"ldg-b21efdbe-5a6c-4a1d-b789-68f111192532","operation":"append","value":{"finding_count":1,"head_sha":"5257544dd92f585abbd5db9da6d59be136f702bb","outcome":"regression"}},"sha":"sha256:667576095d68448942b9c0d38f4ae76834de3000a99ed24d8b038d259b19f9c6","timestamp":"2026-11-21T18:30:19.852Z","type":"ledger_append","version":1}
History

@github-actions github-actions Bot 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.

Found two blocking correctness/test-quality issues:

  • The stopped lease container is removable by routine Docker prune, allowing a second job to acquire the name and overlap the active owner.
  • The setup ordering regression test can pass when the acquire call is absent because it does not assert both search results exist.

Static review only; repository code was not executed per review constraints.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~5 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again

}
});

it("acquires before setup's first shared filesystem deletion and releases last", () => {

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.

This ordering assertion is vacuous if the acquire call is removed: indexOf(...) returns -1, and -1 < indexOf("sudo -n rm -rf /tmp/gh-aw") still passes. Since this test is the guard for the critical acquire-before-cleanup invariant, assert both indices are non-negative before comparing them.

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 setup-order regression asserts both indices are non-negative before comparing them, so removing the acquisition call now fails the test.

Comment thread actions/setup/js/docker_lease.cjs Outdated
while (true) {
if (!inspectLease(run)) {
try {
run(["container", "create", "--name", LEASE_NAME, "--network", "none", "--label", `${OWNER_LABEL}=${owner}`, ...metadata, image, "/never-executed"]);

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.

This lease is created but never started, so a routine docker container prune (or docker system prune) can delete it while the owner is still active. The next invocation then acquires the fixed name and runs concurrently, defeating the serialization guarantee. Please make the lease container ineligible for normal pruning (for example, keep a minimal command running) or otherwise add a daemon-enforced protection; documentation alone cannot preserve the lock.

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 lease container is started and runs the local pause executable with networking disabled and an unless-stopped restart policy, so normal prune operations cannot remove an active lease.

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (review-history)
{"id":"ldg-975f3bd5-62bf-4248-9cc2-c144e8066962","parents":[],"payload":{"id":"ldg-f93778f1-0e32-4c11-bb53-c7e28134538f","operation":"append","value":{"finding_count":2,"head_sha":"5257544dd92f585abbd5db9da6d59be136f702bb","outcome":"findings"}},"sha":"sha256:f43feb0bb0697896cd3a25a5edf81fa85a8db3b7ef655b39686035cef440365f","timestamp":"2026-11-21T18:32:50.669Z","type":"ledger_append","version":1}
History

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

Critical lease-ownership and cleanup gaps can interfere with other jobs, strand leases and host processes, and leave persistent runner trust changes behind.

7 open issues
What changed in this PR

Introduces a Docker-daemon lease to serialize self-hosted AWF jobs that share fixed container names and listener ports, addressing #79118. This extends gh-aw’s runtime-path isolation with shared-resource coordination.

Changes:

  • Adds atomic lease acquisition, unique invocation identities, bounded waits, and ownership-aware release.
  • Adds lease checks and container labels to shell startup and teardown paths.
  • Documents concurrency limits and recovery, with unit and two-process Docker regressions.
File Description
docs/​src/​content/​docs/​reference/​self-hosted-runners.md Documents shared resources, serialization, and administrator recovery.
actions/​setup/​sh/​stop_mcp_gateway.sh Checks ownership before gateway shutdown.
actions/​setup/​sh/​stop_difc_proxy.sh Checks ownership before DIFC proxy teardown.
actions/​setup/​sh/​stop_cli_proxy.sh Checks ownership before CLI proxy removal.
actions/​setup/​sh/​start_mcp_gateway.sh Validates the lease and labels shell-launched gateways.
actions/​setup/​sh/​start_difc_proxy.sh Validates the lease and labels DIFC containers.
actions/​setup/​sh/​start_cli_proxy.sh Validates the lease and labels CLI proxy containers.
actions/​setup/​sh/​run_awf_with_startup_retries.sh Requires a validated lease before AWF execution.
actions/​setup/​sh/​assert_docker_lease.sh Provides a shared shell ownership-check helper.
actions/​setup/​setup.sh Acquires the lease before shared setup work.
actions/​setup/​post.js Releases the lease after post-action cleanup.
actions/​setup/​js/​docker_lease.test.cjs Tests identities, contention, ownership, and failure handling.
actions/​setup/​js/​docker_lease.integration.test.cjs Adds opt-in shared-daemon and interruption regressions.
actions/​setup/​js/​docker_lease.cjs Implements lease acquisition, validation, inventory, and release.
actions/​setup/​clean.sh Adds lease release to script-mode cleanup.

Review effort: Max (adaptive)

Comment on lines +132 to +133
if (Date.now() >= deadline) {
throw new Error("Timed out waiting for the shared-daemon AWF lease. It may belong to a running or interrupted job; never remove it without checking its owner.");

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.

Shared-runtime finalization is gated on a validated lease in both action post and script cleanup; rejected contenders skip telemetry/output finalization and leave the active owner’s shared tree untouched.

Comment thread actions/setup/js/docker_lease.cjs Outdated
Comment on lines +155 to +156
requireCleanDaemon(run);
run(["container", "rm", lease.Id]);

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 MCP Scripts PID is recorded with its invocation owner, classified as a shared host listener, and stopped with exit confirmation before lease release. Cleanup retains the lease if the process does not exit.

Comment thread actions/setup/setup.sh Outdated

# Acquire before touching shared paths, containers, or listeners. Kept until always/post.
if [[ "${RUNNER_ENVIRONMENT:-}" == "self-hosted" ]]; then
node "$(dirname "${BASH_SOURCE[0]}")/js/docker_lease.cjs" acquire

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.

Script-mode action-source checkouts use a per-run, attempt, job, and matrix-index path, preventing contenders from replacing the active invocation’s checkout.

Comment thread actions/setup/setup.sh Outdated

# Acquire before touching shared paths, containers, or listeners. Kept until always/post.
if [[ "${RUNNER_ENVIRONMENT:-}" == "self-hosted" ]]; then
node "$(dirname "${BASH_SOURCE[0]}")/js/docker_lease.cjs" acquire

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.

Action mode passes the bundled process.execPath into setup; script mode emits a pinned actions/setup-node step before setup acquires the lease.

Comment thread actions/setup/setup.sh Outdated

# Acquire before touching shared paths, containers, or listeners. Kept until always/post.
if [[ "${RUNNER_ENVIRONMENT:-}" == "self-hosted" ]]; then
node "$(dirname "${BASH_SOURCE[0]}")/js/docker_lease.cjs" acquire

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.

Script-mode setup callers, including gateway provenance and admission, now append the if: always() cleanup step so leases are released after success or failure.

Comment thread actions/setup/sh/stop_difc_proxy.sh Outdated

if [[ "${RUNNER_ENVIRONMENT:-}" == "self-hosted" ]]; then
# shellcheck source=assert_docker_lease.sh
source "$(dirname "${BASH_SOURCE[0]}")/assert_docker_lease.sh" awmg-proxy

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.

Commit 4c0d732 separates host-trust cleanup status from Docker teardown status. Owned CA/remote state is cleaned even when Docker inspection fails, while teardown still fails and prevents unsafe lease release.


if [[ "${RUNNER_ENVIRONMENT:-}" == "self-hosted" ]]; then
# shellcheck source=assert_docker_lease.sh
source "$(dirname "${BASH_SOURCE[0]}")/assert_docker_lease.sh" awmg-mcpg

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 JavaScript gateway launcher validates the lease and existing service owner before replacement, adds the invocation label to startup, and is covered alongside the cleanup ownership checks in the gateway and lease tests.

@lpcox

lpcox commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot address review feedback

lpcox and others added 2 commits November 21, 2026 19:15
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@lpcox

lpcox commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot merge main and recompile workflows

lpcox and others added 2 commits November 21, 2026 20:14

Copilot AI commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

@copilot address review feedback

Fixed in 314627f7: refreshed the workflow goldens for the lease-ownership guard and made the CJS frontmatter test independent of optional metadata order. Generated locks are synchronized (9e5a75ea); targeted tests and the full workflow drift validation passed.

lpcox and others added 2 commits November 21, 2026 20:24
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
lpcox and others added 3 commits November 21, 2026 20:26
…rces' into copilot/isolate-awf-docker-resources

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

Copilot AI commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

@copilot merge main and recompile workflows

Merged main in e9b2db7e1a. Recompilation processed 210 workflows before npm registry DNS blocked validation, so the full recompile remains incomplete.

@copilot address review feedback

The lease ownership, cleanup, checkout, Node provisioning and gateway feedback was addressed in 6cb143e430.

@copilot address all review feedback and fix the failing ci checks https://github.com/github/gh-aw/actions/runs/44935298183/job/136940607083?pr=79119 https://github.com/github/gh-aw/actions/runs/4493...

Review fixes are in 6cb143e430; CGO hashes pass and golden fixtures were updated in 314627f78c. The reviewer job failed because it emitted no terminal safe output; its cause remains undetermined.

@lpcox

lpcox commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

@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 (docs/src/content/docs/reference/self-hosted-runners.md:75): address unresolved feedback - Review comment
  3. Review (actions/setup/js/docker_lease.test.cjs:199): address unresolved feedback - Review comment
  4. Review (actions/setup/js/docker_lease.cjs:118): address unresolved feedback - Review comment
  5. Review (actions/setup/js/docker_lease.cjs:170): address unresolved feedback - Review comment
  6. Review (actions/setup/js/docker_lease.cjs:156): address unresolved feedback - Review comment
  7. Review (actions/setup/setup.sh:91): address unresolved feedback - Review comment
  8. Review (actions/setup/setup.sh:91): address unresolved feedback - Review comment
  9. Review (actions/setup/setup.sh:91): address unresolved feedback - Review comment
  10. Review (actions/setup/sh/stop_difc_proxy.sh:17): address unresolved feedback - Review comment
  11. Review (actions/setup/sh/stop_mcp_gateway.sh:13): address unresolved feedback - Review comment
  12. Fix failing check JS Tests (shard 7/8) (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": "5f15f27506bf7e5df45a6efe914d6518a2d969b4",
  "kind": "requested",
  "schema_version": "1",
  "state": "26a2636e1d9a3170138d83fe43d727244646ce17978ad094f3602b8298c56b2f",
  "work": [
    "130c3a5e319c5067c33128676c8e8033d0cd3bf29288f5a0e5c134e8bd3ba3ca",
    "47f188a12b316525c2202f4f75b82185d76be0a140c0f99eae185cf2b7d8acb1",
    "4cfbab64c0207356aa61ab0fd09744c7681bb2bb5b58ae2cc5c32b6f7a6b0a41",
    "90bcee77287b19fd7de7aeb6a2c85cf52a359e2a13f84db25946a9d3f8ee91fa",
    "95a70dfd18ba9582418af7a1f12bf16b2fe0ac9dfd317910810645f42b8171ef",
    "a2cbdbd1db4bb0b87f7ba923fbb73a78a6eb7c267852264c49c364f7f3ceaa5e",
    "b022f26d67a7632b7f68197c960c6f2e68122ab9add8f6b90e0e11f9a4c438d0",
    "bf178e67abe2dc2ba9696f3bc658f75fdee094c31260b6e429b36bdaf3d59aad",
    "d9e4b77c16b5b9b566062f7943df499f8b0037f9999bc6ad8f505e08ce692e00",
    "dbae9eaaa7c0a9c5a1910418564fe763280e6908f9cc368d75c155a6a2200048",
    "de0c09763a8b5c03ef404816e49a24c6c74aa0336e6a7e7a6637a58c7de9ef43"
  ],
  "workflow": "pr-sous-chef"
}

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

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

Copilot AI commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

@copilot fix the failing ci check https://github.com/github/gh-aw/actions/runs/44946370290/job/136974582535?pr=79119

Fixed the stale launcher assertion and included the generated workflow locks required by drift validation in commit 95e81299. The focused CJS test passed; the final validation gate passed. CodeQL timed out and could not complete.

@lpcox
lpcox merged commit c742cec into main Nov 21, 2026
111 checks passed
@lpcox
lpcox deleted the copilot/isolate-awf-docker-resources branch November 21, 2026 21:46

Copilot AI commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

@copilot

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

Merged latest main and recompiled all 370 workflows. The stale CJS launcher assertion was fixed in 95e8129; final validation passed, including 260 setup JS tests (1 skipped). The DIFC cleanup follow-up is in 4c0d732.

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.

Self-hosted: isolate AWF Docker resources and listener ports across concurrent jobs

4 participants