Skip to content

fix: stop threat detection from inheriting the agent's provider settings - #396

Merged
theletterf merged 1 commit into
mainfrom
fix/threat-detection-inherited-env
Oct 7, 2026
Merged

theletterf merged 1 commit into
mainfrom
fix/threat-detection-inherited-env

Conversation

@theletterf

@theletterf theletterf commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

While testing #395, I noticed that threat detection never produces a verdict in the docs review. In every run I checked, including production docs-content runs on October 2 and 5, the detection job fails before the scan starts:

[health-check][ERROR] Cannot connect to Anthropic API proxy at https://openrouter.ai/api
Threat Detection Engine Failure — The analysis engine could not complete.
ERR_SYSTEM: Detection result file not found at: /tmp/gh-aw/threat-detection/detection_result.json

Detection fails open (GH_AW_DETECTION_CONTINUE_ON_ERROR: true), and the safe_outputs job only checks that the detection job finished. So every review has posted without a threat scan, and nothing on the PR shows it. Project metadata has the same problem with OpenAI: Cannot connect to OpenAI API proxy.

The cause is in gh-aw: mergeThreatDetectionEngineEnv copies the main engine's engine.env into the detection step, even when detection runs on a different engine. The docs review runs Claude through OpenRouter and detects with Copilot, so detection inherited ANTHROPIC_BASE_URL. The firewall then set up an Anthropic proxy target that the Copilot sandbox can't use, and the health check killed the container. This behavior is the same in gh-aw v0.89.17, v0.91.1, and main. The model inheritance from elastic's earlier report (github/gh-aw#54047) is fixed, but the env inheritance isn't.

This PR applies the workaround that gh-aw-issue-scope already uses: empty values for the inherited provider settings on the detection engine. gh-aw treats an empty base URL as no custom target. I also blanked the API keys, so the OpenRouter key no longer reaches the detection step.

  • gh-aw-docs-review: ANTHROPIC_BASE_URL, ANTHROPIC_API_KEY, ANTHROPIC_CUSTOM_HEADERS, ANTHROPIC_DEFAULT_SONNET_MODEL
  • gh-aw-project-metadata: OPENAI_BASE_URL, OPENAI_API_KEY

The compiled lock files confirm that the detection step gets empty values and no custom proxy target, and that the agent jobs keep their OpenRouter settings.

Testing: a sandbox run of the docs review on this branch is in progress. It passes if the detection log shows [threat-detect] run start and the detection artifact contains detection_result.json. I'll add the result here. Project metadata uses the same mechanism that the gh-aw-issue-scope fix verified in sandbox run 34480489074, but I haven't run it separately.

Upstream: github/gh-aw#66203 asks gh-aw to stop inheriting another engine's provider settings. Follow-up: a guard that makes a missing detection verdict visible instead of failing open.

🤖 Generated with Claude Code

Related to #402

gh-aw copies the main engine's env into the threat detection step, even
when detection runs on a different engine. The docs review (Claude
through OpenRouter) and project metadata (Codex through OpenRouter) both
detect with Copilot, so detection inherited ANTHROPIC_BASE_URL or
OPENAI_BASE_URL. The firewall then set up a custom proxy target and its
health check failed before the scan started:

  [health-check][ERROR] Cannot connect to Anthropic API proxy at https://openrouter.ai/api

Detection fails open, so every run posted without a threat scan. Seen in
every docs review run checked since at least 2026-10-02 and in recent
project metadata runs.

Override the inherited provider settings with empty values on the
detection engine, as gh-aw-issue-scope already does. gh-aw treats an
empty base URL as no custom target. This also stops the OpenRouter API
key from reaching the detection step.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@theletterf

Copy link
Copy Markdown
Member Author

Sandbox result: detection works on this branch. In run 37485133515 (the docs review on a replica of elastic/docs-content#8643), the detection log shows [threat-detect] run start: version=v0.5.1 engine=copilot model=sonnet, and the detection artifact contains a verdict:

{"prompt_injection": false, "secret_leak": false, "malicious_patch": false, "reasons": [], "warnings": []}

Before this change, every run failed with Cannot connect to Anthropic API proxy and wrote no detection_result.json. I didn't run project metadata separately. It uses the same override that verified the Codex case in gh-aw-issue-scope.


Generated by Claude Code

@theletterf
theletterf marked this pull request as ready for review October 6, 2026 15:17
@theletterf
theletterf requested a review from a team as a code owner October 6, 2026 15:17
@theletterf
theletterf requested a review from Mpdreamz October 6, 2026 15:17
@theletterf theletterf self-assigned this Oct 6, 2026
@theletterf theletterf added the fix label Oct 6, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved: no actionable issues found.


What is this? | From workflow: PR Review

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

@theletterf
theletterf merged commit 0753402 into main Oct 7, 2026
14 of 19 checks passed
@theletterf
theletterf deleted the fix/threat-detection-inherited-env branch October 7, 2026 07:25
theletterf added a commit that referenced this pull request Oct 8, 2026
Restore the empty-string detection overrides from #396. Changing them to
unusable values belongs in its own PR, so project metadata goes back to
main. Escape leading code fences in summary fields so a field cannot
open a code block that swallows the later sections and the footer.

Merge main to resolve conflicts with #409 and #410.

Related to elastic/docs-eng-team#757

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant