execute_cortex.py exits after init event when -p + --input-format stream-json on Cortex Code v1.0.56
execute_cortex.py exits after system/init event when invoked with -p + --input-format stream-json on Cortex Code v1.0.56
Repository: Snowflake-Labs/subagent-cortex-code
Affects: scripts/execute_cortex.py
Cortex Code version: 1.0.56
Discovered: 2026-04-16
Severity: High — the documented "auto" / "envelope_only" approval modes are unusable; only prompt mode (which is unsuitable for headless agents) functions
Summary
The skill's headless execution path silently fails. execute_cortex.py invokes:
cortex -p "<prompt>" --output-format stream-json --input-format stream-json -c <conn> --disallowed-tools …
with stdin=subprocess.DEVNULL. Cortex emits only the system/init event, then exits with code 0. No assistant turns, no tool calls, no result event. The script returns final_result: null with no error.
Reproduction
Minimal repro using the skill exactly as published (approval_mode: auto in config.yaml):
python scripts/execute_cortex.py \
--prompt "Run this SQL and return the result: SELECT CURRENT_USER()" \
--connection <any-valid-conn> \
--envelope RO \
--approval-mode auto
Expected: Cortex executes the SQL via its snowflake_sql_execute tool, streams tool_use and assistant events, ends with a result event containing the SQL result.
Actual: Only the system/init event is emitted (~4.8 KB JSON containing tools list, available skills, etc.). Process exits with code 0.
Sample captured output (truncated):
{
"session_id": "23534d50-3a72-4b49-9c73-a7529786aecc",
"events": [
{
"type": "system",
"subtype": "init",
"session_id": "23534d50-…",
"model": "auto",
"tools": ["read","write","edit","bash",…,"snowflake_sql_execute",…],
…
}
],
"permission_requests": [],
"final_result": null,
"error": null
}
Platforms tested (rules out OS-specific cause)
| Platform | Cortex Code | Result |
|---|---|---|
Windows 11 native (%LOCALAPPDATA%\cortex\<version>\cortex.exe) |
1.0.56 | Fails identically |
WSL Ubuntu (~/.local/bin/cortex, fresh installer) |
1.0.56 | Fails identically |
Both paths show single system/init event then exit. Not a platform issue — appears to be a protocol issue between -p + --input-format stream-json + closed stdin.
Hypothesis
--input-format stream-json puts Cortex into programmatic mode, expecting user messages as JSON lines on stdin. With stdin=subprocess.DEVNULL the stdin is closed → Cortex reads EOF → concludes the session before processing the -p prompt. Either:
- The
-pflag should seed the first user message into the JSON stream (so closed stdin still yields one message), or - The script should pipe the prompt as a JSON-formatted user message to stdin instead of using
-p.
The skill's README.md describes this combo as the supported headless path, so the current behavior contradicts the documented design.
Verified workaround
Replacing --input-format stream-json with --bypass in the same invocation works correctly:
cortex --bypass -c <any-valid-conn> --disallowed-tools Edit Write "Bash(rm *)" \
-p "Run this SQL: SELECT CURRENT_USER()"
Returns the SQL result via snowflake_sql_execute. Envelope blocklist is still honored. The skill's README notes some organizations may disable --bypass; for environments where that's available, this is a viable substitute.
Suggested fix
In scripts/execute_cortex.py, change the subprocess invocation pattern. Two options:
Option A: replace --input-format stream-json + -p with bypass-based invocation
cmd = ["cortex", "--bypass", "-c", connection]
for tool in final_disallowed_tools: cmd.extend(["--disallowed-tools", tool])
cmd.extend(["-p", prompt])
…with a configurable fallback to org-policy-friendly mode if --bypass is disabled.
Option B: feed the prompt as JSON on stdin
Wrap the prompt as {"type":"user","message":{"role":"user","content":"<prompt>"}}\n and pipe via stdin=subprocess.PIPE instead of DEVNULL. Drop the -p "<prompt>" argument since the prompt now arrives via the stream.
Option B preserves the documented design intent but requires verifying the exact JSON message schema Cortex expects on the input stream.
Impact on consumers
Skill currently unusable for autonomous orchestration on Cortex Code v1.0.56:
promptapproval mode requires human-in-the-loopautoandenvelope_onlymodes both go through the broken stream-json path
In our deployment (Paperclip multi-agent system, FERPA-compliant student analytics), we wrote a thin replacement wrapper that calls cortex --bypass directly with envelope blocklist + JSONL audit logging. We'd prefer to use the official skill once this is fixed.
Environment
- OS: Windows 11 (also reproduced on WSL Ubuntu)
- Cortex Code CLI:
1.0.56 - subagent-cortex-code: cloned 2026-04-16, latest
main - Snowflake account: us-east AWS region
- Auth: RSA key-pair (
SNOWFLAKE_JWT) - Python: 3.13.5
uv: 0.8.3
Fixed on main; wrappers now use cortex -p ... --output-format stream-json and explicitly avoid --input-format stream-json with closed stdin. Regression tests cover this.