Skip to content

Migrate threat detection to external threat-detect binary behind feature flag#40166

Open
Copilot wants to merge 23 commits into
mainfrom
copilot/migrate-gh-aw-inline-detection
Open

Migrate threat detection to external threat-detect binary behind feature flag#40166
Copilot wants to merge 23 commits into
mainfrom
copilot/migrate-gh-aw-inline-detection

Conversation

Copilot AI commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

gh-aw currently runs threat detection inline — invoking the workflow's engine inside AWF and scraping the transcript for a THREAT_DETECTION_RESULT: line, concluded by parse_threat_detection_results.cjs. This migrates to the standalone versioned threat-detect binary from github/gh-aw-threat-detection, gated behind features: gh-aw-detection: true for incremental rollout.

What changes

Feature flag & version pin

  • GHAWDetectionFeatureFlag = "gh-aw-detection" — opt-in, default off; existing compiled workflows unchanged
  • DefaultThreatDetectVersion = "v0.2.2" in version_constants.go — hard-pinned like AWF/mcpg, no lifecycle registry

New constants

  • ThreatDetectionDir = "/tmp/gh-aw/threat-detection"
  • ThreatDetectionResultPath = ".../detection_result.json"

Install script (actions/setup/sh/install_threat_detect_binary.sh)

  • Downloads threat-detect from GitHub Releases, SHA256-verified, Linux amd64/arm64 and macOS x64/arm64; follows install_awf_binary.sh pattern
  • Linux x64 binary is named threat-detect-linux-amd64 matching the published release assets

Compiler (threat_detection.go)

  • buildDetectionJobSteps branches at step 7 on the feature flag
  • New path emits: install AWF binary → install selected detection engine binary (for example Copilot CLI when engine is copilot) → install threat-detect → AWF execute with /tmp/gh-aw/threat-detection mounted rw → upload detection_result.json + detection.logthreat-detect conclude --result-file
  • Old path (inline engine + .cjs) unchanged

Early adopter workflows

  • smoke-copilot.md opts in via features: gh-aw-detection: true
  • changeset.md opts in via features: gh-aw-detection: true; the pre-existing threat-detection: engine: false config was replaced with threat-detection: {} so the detection job is compiled (when the inline engine is disabled with no custom steps, HasRunnableDetection() returns false and skips the job entirely, making the feature flag a no-op)

Gate contract preserved

The downstream interface is byte-identical to the inline path:

  • detection_conclusion / detection_reason / detection_success job outputs
  • GH_AW_DETECTION_CONCLUSION / GH_AW_DETECTION_REASON env vars
  • GH_AW_DETECTION_CONTINUE_ON_ERROR warn-vs-strict semantics

Only the producer changes: structured detection_result.json + threat-detect conclude instead of transcript-scraped THREAT_DETECTION_RESULT: + .cjs.

Example

# workflow.md frontmatter
features:
  gh-aw-detection: true   # opts into external detector

Compiled detection job (new path):

# Step: Install threat-detect binary
bash install_threat_detect_binary.sh v0.2.2

# Step: Execute threat detection with AWF
sudo -E awf ... --mount /tmp/gh-aw/threat-detection:/tmp/gh-aw/threat-detection:rw \
  -- /bin/bash -c 'threat-detect --engine copilot /tmp/gh-aw/threat-detection'

# Step: Conclude threat detection
threat-detect conclude --result-file /tmp/gh-aw/threat-detection/detection_result.json

Notes

  • parse_threat_detection_results.cjs is not referenced in new-flag workflows but is not yet deleted (per rollout plan)


✨ PR Review Safe Output Test - Run 27801033543

> [!WARNING]
>

> 💥 THE END] — Illustrated by [Smoke Claude · 84.3 AIC · ⌖ 27.9 AIC · ⊞ 8.5K ·


PR Review Safe Output Test - Run 27801991864

> [!WARNING]
>

> 💥 THE END] — Illustrated by [Smoke Claude · 122.4 AIC · ⌖ 28 AIC · ⊞ 8.5K ·

Copilot AI and others added 3 commits June 18, 2026 23:22
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…ure flag gh-aw-detection)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Migrate inline threat detection to standalone gh-aw-threat-detection Migrate threat detection to external threat-detect binary behind feature flag Jun 18, 2026
Copilot AI requested a review from pelikhan June 18, 2026 23:35
@pelikhan

Copy link
Copy Markdown
Collaborator

…inux-amd64

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot the release is https://github.com/github/gh-aw-threat-detection/releases

Updated DefaultThreatDetectVersion from the placeholder v0.1.0 to v0.2.2 (latest stable release). Also fixed the Linux binary name from threat-detect-linux-x64 to threat-detect-linux-amd64 to match the actual release asset name in checksums.txt. Commit: 6c2ced8.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot enable feature flag for smoke-copilot and changeset generator agentic workflows

…rkflows

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot enable feature flag for smoke-copilot and changeset generator agentic workflows

Added features: gh-aw-detection: true to both .github/workflows/smoke-copilot.md and .github/workflows/changeset.md, and recompiled both workflows. Both lock files now include the threat-detect binary install and conclude steps.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot not seeing the new codegen in compiled changeset lock.yml file

…nable detection job

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot not seeing the new codegen in compiled changeset lock.yml file

The root cause was threat-detection: engine: false in changeset.md — when the inline engine is disabled with no custom steps, HasRunnableDetection() returns false and the entire detection job is skipped, so the feature flag never takes effect. Fixed by replacing engine: false with {} (default config), which lets the detection job be compiled and routes through the external binary path via features: gh-aw-detection: true. Both changeset.lock.yml and smoke-copilot.lock.yml now include the Install threat-detect binary and threat-detect conclude steps.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot do not inject Python script in detection. Use bash or actions/github-script

…n runs

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot do not inject Python script in detection. Use bash or actions/github-script

Fixed in the latest commit. Added buildArcDindChrootConfigPatchBodyBash() which uses jq instead of Python to patch the AWF chroot config. BuildAWFCommand now selects the bash version for detection runs (IsDetectionRun: true), so no Python script is injected in the detection job. The agent job path is unchanged.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot merge main and recompile

Done in 8eadade. I merged the latest main into this branch and recompiled workflows.

@pelikhan

Copy link
Copy Markdown
Collaborator

/smoke-copilot

@github-actions

Copy link
Copy Markdown
Contributor

📰 BREAKING: Smoke Copilot is now investigating this issue comment. Sources say the story is developing...

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

Smoke pass. Two tiny notes left.

Warning

Firewall blocked 6 domains

The following domains were blocked by the firewall during workflow execution:

  • accounts.google.com
  • android.clients.google.com
  • clients2.google.com
  • contentautofill.googleapis.com
  • safebrowsingohttpgateway.googleapis.com
  • www.google.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "accounts.google.com"
    - "android.clients.google.com"
    - "clients2.google.com"
    - "contentautofill.googleapis.com"
    - "safebrowsingohttpgateway.googleapis.com"
    - "www.google.com"

See Network Configuration for more information.

📰 BREAKING: Report filed by Smoke Copilot · 236 AIC · ⊞ 19.9K

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot the agentic engine in detection job needs to be configured like the agent job

See error https://github.com/github/gh-aw/actions/runs/27806430889/job/82288105896#step:18:1

Copilot AI and others added 2 commits June 19, 2026 05:32
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot the agentic engine in detection job needs to be configured like the agent job

See error https://github.com/github/gh-aw/actions/runs/27806430889/job/82288105896#step:18:1

Fixed in ec7e8ac. The external detection path now reuses the engine’s generated execution env block, so detection installs and configures the engine like the agent job (including auth/runtime env such as Copilot token/model vars). I also added a regression test asserting detection env contains engine auth configuration.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot recompile

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot recompile

Recompiled on commit 4884394. No additional workflow diffs were produced (lock files are already up to date).

@pelikhan

Copy link
Copy Markdown
Collaborator

/smoke-copilot

@github-actions

Copy link
Copy Markdown
Contributor

📰 BREAKING: Smoke Copilot is now investigating this issue comment. Sources say the story is developing...

@github-actions

Copy link
Copy Markdown
Contributor

Caution

agentic threat detected
Threat detection flagged this output in warn mode. Manual review is REQUIRED before any follow-up automation.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Migrate threat detection to external threat-detect binary behind feature flag
1✅ 2✅ 3✅ 4✅ 5✅
6✅ 7✅ 8✅ 9✅ 10✅
11✅ 12✅ 13✅ 14✅ 15✅
Overall: PASS
Author: @app/copilot-swe-agent; Assignees: pelikhan, Copilot

Warning

Firewall blocked 6 domains

The following domains were blocked by the firewall during workflow execution:

  • accounts.google.com
  • android.clients.google.com
  • clients2.google.com
  • contentautofill.googleapis.com
  • safebrowsingohttpgateway.googleapis.com
  • www.google.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "accounts.google.com"
    - "android.clients.google.com"
    - "clients2.google.com"
    - "contentautofill.googleapis.com"
    - "safebrowsingohttpgateway.googleapis.com"
    - "www.google.com"

See Network Configuration for more information.

📰 BREAKING: Report filed by Smoke Copilot · 353.1 AIC · ⊞ 19.9K ·

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

Caution

agentic threat detected
Threat detection flagged this output in warn mode. Manual review is REQUIRED before any follow-up automation.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Smoke review completed.

Warning

Firewall blocked 6 domains

The following domains were blocked by the firewall during workflow execution:

  • accounts.google.com
  • android.clients.google.com
  • clients2.google.com
  • contentautofill.googleapis.com
  • safebrowsingohttpgateway.googleapis.com
  • www.google.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "accounts.google.com"
    - "android.clients.google.com"
    - "clients2.google.com"
    - "contentautofill.googleapis.com"
    - "safebrowsingohttpgateway.googleapis.com"
    - "www.google.com"

See Network Configuration for more information.

📰 BREAKING: Report filed by Smoke Copilot · 353.1 AIC · ⊞ 19.9K

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot the detection ran successfully but is marked as failed.

https://github.com/github/gh-aw/actions/runs/27808280974/job/82293839697#step:18:1

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot the detection ran successfully but is marked as failed.

https://github.com/github/gh-aw/actions/runs/27808280974/job/82293839697#step:18:1

Fixed in 6790529. Detection now runs threat-detect with --output /tmp/gh-aw/threat-detection/detection_result.json while still passing the artifacts directory, so the conclude step reads the result file and no longer reports a false failure. I also recompiled the affected lock workflows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants