Skip to content

Prevent setup.sh from deleting the in-flight activation prompt - #50341

Closed
pelikhan with Copilot wants to merge 2 commits into
mainfrom
copilot/deep-report-fix-prompt-file-error
Closed

pelikhan with Copilot wants to merge 2 commits into
mainfrom
copilot/deep-report-fix-prompt-file-error

Conversation

Copilot AI commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Copilot-engine runs across several workflows were crashing before the first turn with [copilot-sdk-driver] error: failed to read prompt file /tmp/gh-aw/aw-prompts/prompt.txt: ENOENT. The prompt file is deleted between the activation-artifact download and the agent execution step — not a sub-agent hang (#49022).

Root cause

actions/setup/setup.sh unconditionally runs rm -rf /tmp/gh-aw to guarantee a clean runtime tree, and pkg/cli/setup_action_test.go shells out to that script during go test. Any workflow that runs this repository's test suite after the activation artifact is downloaded therefore wipes its own prompt.

CI Optimization Coach run 30915139809 shows the sequence exactly:

step time
10 Download activation artifact → /tmp/gh-aw 13:43:47
17 Pre-flight validation (go test ./...) 13:44:04–13:50:20
35 Execute GitHub Copilot CLI → ENOENT ×4 13:50:53

The same shape applies to the other affected workflows, which also run tests in a pre-agent step.

Changes

  • actions/setup/setup.sh — skip the /tmp/gh-aw reset when /tmp/gh-aw/aw-prompts/prompt.txt is already present, or when GH_AW_SKIP_TMP_RESET=1. Behaviour at genuine job start (no prompt yet) is unchanged, including the existing root-owned / sudo reclaim paths.
  • pkg/cli/setup_action_test.go — sets GH_AW_SKIP_TMP_RESET=1 so the test can never clobber a live runtime tree, and adds TestSetupActionPreservesExistingActivationPrompt as a regression guard.
SKIP_TMP_RESET=""
if [ "${GH_AW_SKIP_TMP_RESET:-0}" = "1" ]; then
  SKIP_TMP_RESET="GH_AW_SKIP_TMP_RESET=1"
elif [ -f /tmp/gh-aw/aw-prompts/prompt.txt ]; then
  SKIP_TMP_RESET="an activation prompt is already present"
fi

if [ -n "${SKIP_TMP_RESET}" ]; then
  debug_log "Skipping /tmp/gh-aw reset: ${SKIP_TMP_RESET}"
elif [ -d /tmp/gh-aw ] && [ ! -w /tmp/gh-aw ]; then
  ...

The prompt-file check is the load-bearing guard (it covers any current or future caller); the env var is the explicit escape hatch for callers that know they are nested.

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Thanks for getting started on this! 👋 This PR is tackling a critical issue — the recurring prompt file ENOENT crash that has been affecting scheduled runs across multiple workflows. The focus is laser-sharp, and the approach is sound.

Since this is marked [WIP], here is what would help get it across the finish line:

  • Add tests — once the fix lands, include test coverage for the prompt-file-write step and the suspected race condition (workspace cleanup + cache restore ordering) to prevent regression.
  • Update the PR description — as you implement the fix, document what the root cause turned out to be so reviewers understand the diagnosis.

The diff is currently empty, so no other blockers yet. Keep us posted as the implementation progresses! 🚀

Generated by ✅ Contribution Check · auto · 56.1 AIC · ⌖ 8.95 AIC · ⊞ 8.8K · ◷

Copilot AI changed the title [WIP] Fix prompt file error causing copilot-engine crash Prevent setup.sh from deleting the in-flight activation prompt Aug 4, 2026
Copilot AI requested a review from pelikhan August 4, 2026 17:36
@pelikhan
pelikhan marked this pull request as ready for review August 4, 2026 17:42
Copilot AI balanced review requested due to automatic review settings August 4, 2026 17:43

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

Prevents nested setup runs from deleting an active workflow prompt.

Changes:

  • Adds reset guards for active prompts and explicit opt-out.
  • Adds regression coverage and protects the existing setup test.
Show a summary per file
File Description
actions/setup/setup.sh Conditionally skips /tmp/gh-aw cleanup.
pkg/cli/setup_action_test.go Adds prompt-preservation safeguards and coverage.

Review details

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread actions/setup/setup.sh
Comment on lines +109 to +110
elif [ -f /tmp/gh-aw/aw-prompts/prompt.txt ]; then
SKIP_TMP_RESET="an activation prompt is already present"
@github-actions

github-actions Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions

github-actions Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

✅ Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR does not have the 'implementation' label and has ≤100 new lines of code in business logic directories (40 additions detected, threshold is 100).

@github-actions

github-actions Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

@github-actions

github-actions Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ PR Code Quality Reviewer failed during code quality review.

@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.

Review

The fix correctly addresses the root cause: setup.sh now skips the /tmp/gh-aw reset when an activation prompt is already present, and the test suite sets GH_AW_SKIP_TMP_RESET=1 to prevent clobbering live runtime state during testing.

The regression test TestSetupActionPreservesExistingActivationPrompt is well-structured: it exercises the file-based guard (not the env-var path) by deliberately omitting GH_AW_SKIP_TMP_RESET, correctly skips when a real prompt already exists, and cleans up after itself.

One existing concern (flagged in a prior review comment at setup.sh:110): a stale prompt.txt left by an interrupted run on a persistent runner would suppress cleanup for the next job. This is worth tracking as a follow-up even if not blocking this fix.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 18.7 AIC · ⌖ 12.3 AIC · ⊞ 5.4K

@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.

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd — requesting changes on two targeted issues.

📋 Key Themes & Highlights

Key Themes

  • Stale-prompt false positive (setup.sh line 110): the file-existence guard protects the current run's prompt but also accidentally preserves a stale prompt.txt left by a prior interrupted run on a persistent/self-hosted runner, potentially blocking the cleanup of a broken tree.
  • Weak regression-test assertion (setup_action_test.go): the new test checks that prompt.txt survives but does not verify the skip control-flow path fired, so a future silent removal of the guard would still pass the test.

Positive Highlights

  • ✅ Root cause diagnosis is thorough — the step-sequence table in the PR body is exactly the right evidence.
  • ✅ Two-layer guard (prompt-file check + explicit env var) is a well-designed defence-in-depth pattern.
  • ✅ Protecting the existing test with GH_AW_SKIP_TMP_RESET=1 is a clean, low-risk change.
  • ✅ Test skip logic for a live prompt is considerate of the test running inside a live workflow.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 31 AIC · ⌖ 13.8 AIC · ⊞ 7.1K
Comment /matt to run again

Comment thread actions/setup/setup.sh
if [ "${GH_AW_SKIP_TMP_RESET:-0}" = "1" ]; then
SKIP_TMP_RESET="GH_AW_SKIP_TMP_RESET=1"
elif [ -f /tmp/gh-aw/aw-prompts/prompt.txt ]; then
SKIP_TMP_RESET="an activation prompt is already present"

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.

[/diagnosing-bugs] Stale-prompt false positive: prompt.txt left by a previous interrupted run on a persistent/self-hosted runner will also trigger the skip, silently preserving a stale tree instead of cleaning up — the exact concern raised in the existing review comment.

💡 Suggested mitigation

Write the current GITHUB_RUN_ID into a sentinel file during the artifact-download step, then cross-check it in the guard:

# During the activation-artifact download step:
echo "${GITHUB_RUN_ID}" > /tmp/gh-aw/aw-prompts/.run-id

# setup.sh guard (replace the current elif):
elif [ -f /tmp/gh-aw/aw-prompts/prompt.txt ] &&      [ "$(cat /tmp/gh-aw/aw-prompts/.run-id 2>/dev/null)" = "${GITHUB_RUN_ID:-}" ]; then
  SKIP_TMP_RESET="activation prompt for run ${GITHUB_RUN_ID} already present"

This ensures only the current run's prompt is preserved, not a stale leftover.

@copilot please address this.

}
require.NoError(t, os.MkdirAll(promptDir, 0o755), "Failed to create prompt directory")
t.Cleanup(func() { _ = os.RemoveAll(promptDir) })
require.NoError(t, os.WriteFile(promptFile, []byte("test prompt\n"), 0o644), "Failed to write prompt file")

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.

[/tdd] The regression test creates the prompt file itself but does not assert that setup.sh logged the skip reason — a future change that removes the guard silently and still exits 0 would pass this test.

💡 Strengthen the assertion

Capture setup.sh's combined output and assert the skip message appears:

output, err := cmd.CombinedOutput()
require.NoError(t, err, "setup.sh should succeed: %s", output)

assert.FileExists(t, promptFile, "setup.sh must not delete an existing activation prompt")
assert.Contains(t, string(output), "Skipping /tmp/gh-aw reset",
    "setup.sh should log that it skipped the reset when a prompt is present")

This turns the test into a specification: it verifies both the observable side-effect (file preserved) and the control-flow path that produced it (debug log emitted).

@copilot please address this.

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

⚠️ Test Quality Score: 70/100 — Acceptable

Analyzed 2 test(s): 1 design, 1 implementation, 0 violation(s).

Metrics: 50% design tests | 100% edge/error coverage | 0 violations

New Test: TestSetupActionPreservesExistingActivationPrompt

  • Validates that setup.sh doesn't delete /tmp/gh-aw/aw-prompts/prompt.txt when activation prompt exists
  • Comprehensive error handling + edge case coverage
  • Proper cleanup with t.Cleanup() and pre-flight skip
  • No mocks, real filesystem operations, correct build tag

Modified: TestSetupActionCopiesAntigravityLogParser

  • Added GH_AW_SKIP_TMP_RESET=1 to prevent test from interfering with in-flight workflows
  • Necessary fix for running in live agentic workflow environment

Test Inflation (2.35:1): Marginally exceeds 2:1 threshold but justified by integration-style setup requirements.

Verdict

✅ Passed — Design-oriented test validates behavioral contract. No guideline violations. Error paths fully covered.

🧪 Test quality analysis by Test Quality Sentinel · haiku45 · 15.2 AIC · ⌖ 6.29 AIC · ⊞ 8.6K · ◷
Comment /review to run again

@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.

✅ Test Quality Sentinel: 70/100. Design-oriented test validates behavioral contract (prompt preservation). Error paths fully covered. No guideline violations. 50% implementation tests (threshold: 30%).

@pelikhan pelikhan closed this Aug 4, 2026
@github-actions
github-actions Bot deleted the copilot/deep-report-fix-prompt-file-error branch August 14, 2026 02:52
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.

[deep-report] Root-cause recurring 'failed to read prompt file ENOENT' copilot-engine crash across workflows

3 participants