Run `gh-aw` threat detection with OpenCode instead of GLM through the Claude CLI
Merged
DS
25d ago+1344+1344+0123456789012345678901234567890123456789-1921-1921-0123456789012345678901234567890123456789
This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.
No linked issue: a maintainer-requested change to the repository's agentic workflows.
Why
Our agentic workflows ran gh-aw threat detection on GLM through the Claude Code CLI. gh-aw runs detection only on its Copilot, Claude and Codex engines, so shared/engine-zai.md now sets safe-outputs.threat-detection.engine: false and runs our own detector as detection post-steps, with opencode-go/deepseek-v4.1-flash and OPENCODE_API_KEY. Detection still checks the agent's own outputs (prompt injection, secret leaks, malicious patches), not the PR.
New public surface
None. Repository CI only.
Behavior
gh_aw_opencode_detect.pysends the prompt gh-aw renders toGH_AW_PROMPTand runs OpenCode with douwebot's read-only lockdown in/tmp/gh-aw/threat-detection.- It writes
detection_result.json(no reasons) anddetection_result_full.json(reasons) in the strict schema ofthreat-detect concludev0.5.3. - The step keeps gh-aw's id
detection_agentic_execution, so gh-aw's conclusion step, warn mode and the Detection Runs tracker are unchanged. - An invalid verdict appends
THREAT_DETECTION_STATUS: reason=invalid_report_exhausted, which concludes asparse_error. A failed OpenCode run is retried three times (GH_AW_HARNESS_MAX_RETRIES, the old detector's policy) and then appendsengine_error, which concludes asagent_failure. A run that reaches the 13-minute deadline appendsengine_timeout. douwebot_opencode_run.run_read_onlyanddouwebot_opencode_result.final_textnow serve both douwebot and the detector.- The detector report step sums OpenCode's per-step token counters across every attempt.
Verification
test_gh_aw_opencode_detect.py,test_detector_telemetry.cjs, and the guard and lock assertions intest_agentic_workflow_guard.py- Valid verdict, CI Review run 42616052595 at
c764078404: every job succeeded. OpenCode ran indetection, which logged "Structured result file found and parsed successfully" and "No security threats detected";safe_outputsposted the review. Against the head, that commit's detection job differs only in the telemetry report's handling of a cut-off last line and missing token fields (covered bytest_detector_telemetry.cjs), plus a prompt line asking for an invalid verdict, which the model ignored. - Forced invalid verdict, run 42623028326 on a throwaway branch whose parser expects an unrequested prefix: the detector appended
THREAT_DETECTION_STATUS: reason=invalid_report_exhausted, detection concludedwarning/parse_error, the run stayed green, and the tracker got adetector_result_invalidcomment.
What changes for existing users
Nothing. Repository CI only.
Security review of the recompiled locks
gh aw compile asked for a review of new secrets and actions:
OPENCODE_API_KEYreaches the detection job. It is the repository secret douwebot's OpenCode fallback already uses. gh-aw now redacts it from detection logs and artifacts;ZAI_API_KEYleaves the detection job.actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1(v7.0.1, already pinned elsewhere) sparse-checks out.github/scriptsand.github/actions/setup-douwebot-toolsatgithub.workflow_sha, withpersist-credentials: false.- The local
setup-douwebot-toolsaction installs@opencode/cli@2.2.5, ripgrep andpydantic==2.13.4, as douwebot does. The detector's setup step setsNPM_CONFIG_MIN_RELEASE_AGE: '3', the cooldown the Claude CLI install used. - The detector runs as a plain runner step, outside AWF. OpenCode gets read, grep and glob in the inputs directory only, and an environment of
HOME,PATH,XDG_*andOPENCODE_API_KEY.
Deliberate scope
- gh-aw v1.2.1 still installs AWF, its container images and the Copilot CLI in the detection job under
engine: false. The detector uses none of them; they stay as compiled. - OpenCode cannot read the repository workspace. A path-scoped
external_directoryallow is still blocked by douwebot'stool.usepolicy (local OpenCode 2.2.5 probe). Only the weekly CE audit produces a patch, and the patch file is in the inputs directory. - The prompt is gh-aw's rendered
GH_AW_PROMPT, notthreat-detect's embedded prompt, whose analysis sections the Go binary computes. setup-douwebot-toolsmisses its cache in the detection job and installs fresh each run, as the Claude CLI install did.
PR decisions
2026-11-08 · own OpenCode detector, not a gh-aw engine · iter -
- Decision: safe-outputs.threat-detection.engine: false plus our post-step id detection_agentic_execution running OpenCode with opencode-go/deepseek-v4.1-flash
- Why: David: stop running GLM through the Claude CLI; gh-aw detection runs only copilot, claude or codex and rewrites pi to copilot (threat_detection_external.go at v0.86.2 and main)
- Source: https://github.com/pydantic/pydantic-ai/tree/feat/gh-aw-opencode-detector
- Session: 35c6987b-87c9-4ee4-adcb-589c6fe5df25
2026-11-08 · invalid output emits threat-detect status line · iter -
- Decision: On invalid model output write no verdict and append 'THREAT_DETECTION_STATUS: reason=invalid_report_exhausted exit=1' to detection.log; on OpenCode failure use reason=engine_error
- Why: threat-detect v0.5.3 conclude maps a missing result file to agent_failure unless detection.log carries that status line, which it maps to parse_error
- Source: https://github.com/github/gh-aw-threat-detection/blob/v0.5.3/cmd/threat-detect/conclude.go
- Session: 35c6987b-87c9-4ee4-adcb-589c6fe5df25
2026-11-08 · OpenCode runs in the detection inputs directory · iter -
- Decision: Run OpenCode with cwd /tmp/gh-aw/threat-detection under douwebot's unchanged lockdown; the repo workspace is not readable
- Why: Local OpenCode 2.2.5 probes: outside reads hit external_directory, and a path-scoped allow is still blocked by the tool.use policy; nested read, glob and grep inside cwd work. Only weekly-ce-audit produces a patch, and the patch file is in that directory
- Source: https://github.com/pydantic/pydantic-ai/tree/feat/gh-aw-opencode-detector
- Session: 35c6987b-87c9-4ee4-adcb-589c6fe5df25
2026-11-08 · prompt is gh-aw's rendered GH_AW_PROMPT · iter -
- Decision: Send the prompt gh-aw's Setup threat detection step renders to GH_AW_PROMPT and parse its THREAT_DETECTION_RESULT line
- Why: threat-detect has no render-only mode and fills its embedded prompt's PROMPT_ANALYSIS and ACTIVATION_CONTEXT in Go; GH_AW_PROMPT is the gh-aw-maintained prompt with every placeholder filled
- Source: https://github.com/github/gh-aw/blob/v1.2.1/actions/setup/js/setup_threat_detection.cjs
- Session: 35c6987b-87c9-4ee4-adcb-589c6fe5df25
2026-11-08 · implement directly, no plan PR · iter -
- Decision: Simple path: implement and open a ready PR
- Why: David settled the design in the dispatch; the premise check found adjustments, not blockers
- Source: https://github.com/pydantic/pydantic-ai/tree/feat/gh-aw-opencode-detector
- Session: 35c6987b-87c9-4ee4-adcb-589c6fe5df25
2026-11-08 · pre-push review 1 of 3 at 76fc0574146a249727070469d767337313348a18 · iter -
- Decision: reserved; outcome pending
- Why: tree b36ed28ccddf781881705e0a3c57d851e861394c; full branch scope c9c896e9f0..76fc057414; policy base c9c896e9f0 (upstream/main); first review; light tier (haiku)
- Source: https://github.com/pydantic/pydantic-ai/tree/feat/gh-aw-opencode-detector
- Session: 35c6987b-87c9-4ee4-adcb-589c6fe5df25
2026-11-08 · pre-push review 1 of 3 at 76fc0574146a249727070469d767337313348a18 · iter -
- Decision: remediated: telemetry filter no longer depends on step_finish key order (+test). Dismissed: GH_AW_PROMPT unset (setup_threat_detection.cjs exports it before ready=true, which the step requires); removed max-ai-credits cap (value was -1, no cap, and detection has no AWF now). Skipped: setup-douwebot-tools cache key misses in detection (exact-key restore, never saved there, so only a fresh install per run)
- Why: tree b36ed28ccd; full branch c9c896e9f0..76fc057414
- Source: https://github.com/pydantic/pydantic-ai/tree/feat/gh-aw-opencode-detector
- Session: 35c6987b-87c9-4ee4-adcb-589c6fe5df25
2026-11-08 · pre-push review 2 of 3 at 16bdc7be98adaf1ad265a64a05dbf76dc83a45ba · iter -
- Decision: reserved; outcome pending
- Why: tree 64ae11180048e4e79037ca2c8932939346fc21e2; follow-up scope 76fc057414..16bdc7be98adaf1ad265a64a05dbf76dc83a45ba; policy base c9c896e9f0 (upstream/main); light tier (haiku)
- Source: https://github.com/pydantic/pydantic-ai/tree/feat/gh-aw-opencode-detector
- Session: 35c6987b-87c9-4ee4-adcb-589c6fe5df25
2026-11-08 · pre-push review 2 of 3 at 16bdc7be98adaf1ad265a64a05dbf76dc83a45ba · iter -
- Decision: remediated: telemetry test's non-step event now reaches the type filter (mutation-checked: fails without the filter). Prior findings verified fixed or dismissals upheld
- Why: tree 64ae111800; follow-up 76fc057414..16bdc7be98
- Source: https://github.com/pydantic/pydantic-ai/tree/feat/gh-aw-opencode-detector
- Session: 35c6987b-87c9-4ee4-adcb-589c6fe5df25
2026-11-08 · exempt delta after review 2 at 884e0cbd04547e3e86d9ff9e9a797b183ef6f201 · iter -
- Decision: push without review 3: test-harness repair only
- Why: chains from reviewed 16bdc7be98; git diff 16bdc7be98..HEAD touches only .github/scripts/test_detector_telemetry.cjs; telemetry tests pass
- Source: https://github.com/pydantic/pydantic-ai/tree/feat/gh-aw-opencode-detector
- Session: 35c6987b-87c9-4ee4-adcb-589c6fe5df25
2026-11-09 · pre-push review 3 of 3 at 12efc0c4becda1e376be71f76f9b1df28cd6bc3e · iter -
- Decision: reserved; outcome pending
- Why: tree c5e8f184edfbf5aab26b02078b3f0546f3b9f550; follow-up scope 16bdc7be98..12efc0c4becda1e376be71f76f9b1df28cd6bc3e (884e0cbd test-only delta exempt); policy base c9c896e9f0 (upstream/main); light tier (haiku)
- Source: https://github.com/pydantic/pydantic-ai/pull/12893
- Session: 35c6987b-87c9-4ee4-adcb-589c6fe5df25
2026-11-09 · pre-push review 3 of 3 at 12efc0c4becda1e376be71f76f9b1df28cd6bc3e · iter -
- Decision: remediated: one stream file per OpenCode attempt, summed by the report step with an attempts attribute; a 13-minute script deadline stops retries and records engine_timeout before the 15-minute step limit. Budget exhausted: pushed after local checks
- Why: tree c5e8f184ed; follow-up 16bdc7be98..12efc0c4be; both findings valid and cheap
- Source: https://github.com/pydantic/pydantic-ai/pull/12893
- Session: 35c6987b-87c9-4ee4-adcb-589c6fe5df25
2026-11-09 · detector keeps the 3-retry detection policy · iter -
- Decision: The OpenCode step sets GH_AW_HARNESS_MAX_RETRIES "3" and the script retries failed runs that many times; an invalid verdict is not retried
- Why: CI run 42540011539 failed three tests pinning the old detector's retry policy; the old engine comment said detection 'retains normal recovery'
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/42540011539
- Session: 35c6987b-87c9-4ee4-adcb-589c6fe5df25
2026-11-09 · douwebot REQUEST_CHANGES at 15fa083f addressed · iter -
- Decision: Set NPM_CONFIG_MIN_RELEASE_AGE '3' on the detector's Set up OpenCode step only (douwebot's own install unchanged); check the remaining deadline before each attempt. Left: detection cache-key miss (documented)
- Why: Restores the Claude CLI install's cooldown on the new detection path; douwebot said either cooldown or cache-key fix suffices
- Source: https://github.com/pydantic/pydantic-ai/pull/12893#discussion_r4508457144
- Session: 35c6987b-87c9-4ee4-adcb-589c6fe5df25
2026-11-09 · merge main at 9a863d0158 · iter -
- Decision: Kept upstream's deletion of pydantic-ai-attention-triage.lock.yml (#12930 removed the workflow); 13 remaining locks recompiled with no diff
- Why: modify/delete conflict on a lock whose source upstream deleted
- Source: https://github.com/pydantic/pydantic-ai/pull/12893#issuecomment-6739949018
- Session: 35c6987b-87c9-4ee4-adcb-589c6fe5df25
2026-11-09 · merge main at f780e46a23 · iter -
- Decision: Lock conflicts from #12894 resolved by taking main's locks and recompiling all 13 with gh-aw v1.2.1; each lock differs from main only in its detection job
- Why: generated files; sources merged cleanly
- Source: https://github.com/pydantic/pydantic-ai/pull/12894
- Session: 35c6987b-87c9-4ee4-adcb-589c6fe5df25
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.