Skip to content

fix: make Copilot and Codex agents work end-to-end on Windows - #23

Merged
vsn411 merged 2 commits into
secfoo-com:mainfrom
karthickmk2001:fix/copilot-codex-windows
Oct 1, 2026
Merged

vsn411 merged 2 commits into
secfoo-com:mainfrom
karthickmk2001:fix/copilot-codex-windows

Conversation

@karthickmk2001

@karthickmk2001 karthickmk2001 commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

End-to-end test of the Copilot (#15) and Codex (#12) adapters on Windows 11 (SECFOO-10) found that neither worked there. This fixes the secfoo side of each failure.

# Problem found Effect before this PR Fix
1 Popen(["copilot", ...]) ignores PATHEXT, but shutil.which doesn't secfoo agents shows the agent as available, then every run crashes with FileNotFoundError: [WinError 2]. This affects every npm-installed agent (Copilot, Codex, Gemini). base.py launches the path shutil.which resolved. A launch OSError now returns failed instead of a traceback.
2 The prompt was passed as an argument, and npm shims run through cmd.exe The prompt was silently cut off at its first newline: Copilot answered only the first line of a two-line test prompt. New opt-in AgentAdapter.prompt_via_stdin, used by Copilot (piped stdin, no -p) and Codex (codex exec -).
3 Copilot's built-in security-review subagent streams to stdout at the same time as the main answer The report was interleaved mid-line, e.g. **Severity:# Secret LOW Scanning Report, which is worse than the duplication the adapter docstring describes Use --output-format json and keep the last non-empty assistant.message without an agentId (subagent events always carry one). --stream off was tried too: it stops the interleaving but renders Markdown to plain text, which drops the headings the parsers need.
4 On Windows codex exec --sandbox read-only rejects every command, reads included ("blocked by policy") Codex exits 0 with a "could not inspect the target" report, and secfoo stored it as success, which looks like a clean scan New AgentAdapter.detect_failure() hook. Codex marks the run failed when its commands were rejected, with an explanation in stderr.
5 Output was decoded with the Windows default encoding (cp1252) Possible UnicodeDecodeError on UTF-8 agent output encoding="utf-8", errors="replace"

E2E results (Windows 11, fixture repo with a fake AWS key, a SQL injection and a command injection)

  • Copilot 1.0.89: passes. sast finds the command injection (Critical, CWE-78, app.py:24) and the SQL injection (High, CWE-89, app.py:19), and extract_findings_register_rows parses both. secret-scanning finds the AWS key pair and rates it Low (it recognises the AWS documentation example key). Each skill takes about 80s.
  • Codex 0.159.2: now reported correctly as failed, but it still can't read the target on Windows. windows.sandbox="unelevated" still blocks reads. "elevated" starts a one-time admin-approved sandbox install, which I didn't approve on the test machine, so whether it fixes this is unverified. The failure message points users to that setup. I deliberately didn't switch to danger-full-access.

Behaviour change outside Windows

Copilot and Codex now get the prompt on stdin on every OS. Both CLIs' help documents stdin input, but I only ran it on Windows, so a macOS/Linux smoke run before merging would be worthwhile.

Test plan

  • 8 new regression tests, covering resolved-path launch, launch-error status, stdin prompts, Copilot subagent filtering (real event shapes) and Codex sandbox rejection (real stderr)
  • pytest: 703 passed, 5 failed. The 5 (test_cloud permissions and 4 architecture dashboard tests) fail the same way on untouched origin/main on Windows.
  • Real secfoo run -s secret-scanning -s sast -a copilot on Windows
  • Real secfoo run -s sast -a codex on Windows (now failed with a reason, previously a false success)
  • macOS/Linux smoke run for Copilot and Codex

Not in this PR

  • A run that raises an unexpected exception is left at running in secfoo list forever. It's seen less often now that launch errors are handled, but it's still possible.
  • Copilot reports usage in AI credits (session.usage_checkpoint), not dollars, so cost still shows -.

karthickmk2001 and others added 2 commits September 30, 2026 03:58
Found by an end-to-end test of both adapters on Windows 11 (SECFOO-10,
copilot 1.0.89, codex-cli 0.159.2):

- Launch the path shutil.which resolved. Popen ignores PATHEXT, so the
  bare name missed npm's .cmd/.bat shims and every npm-installed agent
  crashed with WinError 2 while `secfoo agents` showed it as available.
  A launch OSError now returns a failed result instead of a traceback.
- Send the prompt on stdin for Copilot and Codex (`codex exec -`). As an
  argv it went through cmd.exe, which cut it off at the first newline.
- Copilot: read --output-format json and keep only the main agent's
  final message. In text mode its built-in security-review subagent
  streamed concurrently and interleaved mid-line into the report.
- Codex: mark a run failed when its sandbox rejected the commands. On
  Windows `--sandbox read-only` refuses even reads, yet `codex exec`
  exits 0 with an empty "could not inspect" report that was stored as a
  success.
- Decode agent output as UTF-8 rather than the Windows locale codepage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vsn411
vsn411 merged commit ef80f45 into secfoo-com:main Oct 1, 2026
2 checks passed
Varunpoojari added a commit that referenced this pull request Oct 3, 2026
PR #23 moved Codex and Copilot to stdin because npm-installed CLIs are
`.cmd` shims on Windows and cmd.exe cuts an argv prompt at its first
newline. The Claude adapter still passed the prompt as an argument.

`claude -p` with no prompt argument reads it from stdin; a two-line
prompt was read in full on Linux with Claude Code 2.1.288. The Windows
truncation itself was not reproduced for Claude (no Windows machine).

- claude.py: `prompt_via_stdin = True`, prompt dropped from the argv.
- test_base.py: the "stdin is DEVNULL" test used Claude as its example
  of an argv-prompt adapter; it now uses Cursor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JkVdBSUgu2rKg3G7Tg6DJD
@Varunpoojari Varunpoojari mentioned this pull request Oct 9, 2026
4 tasks done
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.

2 participants