Skip to content

Threat detection cannot run on an imported engine definition #75276

In progress

Description

@dsfaccini

Migration implementation scope (PR 4)

With the detector bundled as JS, implement the imported-engine opt-in directly in gh-aw. This supersedes the original proposal below to release and pin a new external binary.

  • Support a definition declaring its own ID as its detection engine. Honor opt-in for explicit and inherited selection before provider fallback. Retain existing built-in replacements and fallback for definitions without opt-in. Warn with requested and effective IDs if an explicit choice is rewritten.
  • Reuse the selected engine’s runtime, install, harness, executable and model bindings on the fresh detection runner. Support engine-owned prerequisites, including Python installs, without replaying unrelated workflow-owned pre-agent steps. Preserve detection-specific isolation, limits and unrouted model behavior.
  • Verify actual execution with an imported Pydantic-style engine: inspect the generated detection job for prerequisites and harness, then require evidence from that harness and a recorded verdict consumed by host conclude. Add regression cases for declared built-in replacement, fallback, explicit override, inherited opt-in and legacy-inline flag behavior.
  • All engine types use the same reporting tool and binding structural eligibility checks. Include an imported-harness case that attempts an ineligible finding, receives correction, and records only an eligible verdict.

Original report

This issue was posted by Claude Code using claude-opus-5-5 on behalf of David.

Threat detection for an imported engine always runs copilot, claude or codex. A pydantic-ai workflow on GLM gets the Claude CLI pointed at GLM, outside the engine's harness and tracing.

Reproduction

.github/workflows/shared/engine.md:

---
engine:
  id: my-engine
  display-name: My Engine
  behaviors:
    execution:
      command-name: my-engine
      step-name: Execute My Engine
---

.github/workflows/repro.md:

---
on: workflow_dispatch
permissions:
  contents: read
imports: [shared/engine.md]
engine:
  id: my-engine
safe-outputs:
  create-issue:
  threat-detection:
    engine:
      id: my-engine
---
Say hello.

v1.0.1 and main f7b1cc2 compile this to threat-detect --engine copilot, with no detection warning. With engine: codex and id: codex, the output is --engine codex.

Expected: a definition can opt in to running detection itself.

Root cause

  • getThreatDetectionEngineID sends any ID but copilot, claude and codex to resolveCustomEngineDetectionEngineID, which falls back to copilot. The schema limits detection-engine to the same three.
  • gh-aw-threat-detection v0.5.3 engine.New rejects any other --engine.

ADR-59636 (#59636) chose this fallback over per-ID support. This asks for one generic, opt-in engine.

Plan

Compiler:

  1. Accept the definition's own id as detection-engine and return it from resolveCustomEngineDetectionEngineID. Other definitions keep the fallback.
  2. For an opted-in engine, emit its harness and install steps (runtimes, pre-agent-steps) in the detection job. Pass threat-detect its command-name and model-env-var.
  3. Warn when an explicit threat-detection.engine.id is rewritten.

Runtime:

  1. Add a generic engine to engine.New that runs node $RUNNER_TEMP/gh-aw/actions/<id>_harness.cjs <command-name> with GH_AW_PROMPT and threat_detection_result on PATH, keeping timeout, retry and sink handling. gh-aw already writes custom harnesses there.
  2. Bump DefaultThreatDetectVersion.

Acceptance: an opted-in definition compiles to --engine <id> with its install steps, and a smoke run records a verdict. Others still get --engine copilot.

Why a compiler-only change is not enough

I patched getThreatDetectionEngineID on f7b1cc2 to keep an explicit custom ID (one line), then compiled against pydantic/pydantic-ai's pydantic.md:

  • Default external path: the output is threat-detect --engine pydantic-ai, which engine.New rejects, and no step installs the engine.
  • Legacy inline path (features.gh-aw-detection: false): the detection job gets Write Pydantic AI harness script and Execute Pydantic AI CLI, but not the definition's Python setup or pip install. Behavior-defined GetInstallationSteps only emits npm installation.

The verdict contract is already engine-neutral. The external path reads the threat_detection_result tool. The inline path's parse_threat_detection_results.cjs reads a THREAT_DETECTION_RESULT: line from the log.

Metadata

Metadata

Labels

ai-inspectedbacklog:securitybugcommunitycompilerthreat-detection

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions