Skip to content

Commit 70aa48c

Browse files
Fix/agent stream debug (#37)
* debug: log line length and preview without scrubbing * fix: use Modal text=True bufsize=1 for line-buffered streaming Modal buffers all stdout by default until process exits, causing Claude Code's streaming output to arrive as a single blob. Using text=True, bufsize=1 enables line-buffered streaming.
1 parent f4dae3a commit 70aa48c

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/policyengine_api/agent_sandbox.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,17 @@ def run_claude_code_in_sandbox(
9797
# Escape the question and config for shell
9898
escaped_question = question.replace("'", "'\"'\"'")
9999
escaped_mcp_config = mcp_config_json.replace("'", "'\"'\"'")
100-
# Use stdbuf -oL to force line-buffered stdout (prevents buffering issues)
100+
# Modal handles line buffering with text=True, bufsize=1
101101
cmd = (
102-
f"stdbuf -oL claude -p '{escaped_question}' "
102+
f"claude -p '{escaped_question}' "
103103
f"--mcp-config '{escaped_mcp_config}' "
104104
"--output-format stream-json --verbose --max-turns 10 "
105105
"--allowedTools 'mcp__policyengine__*,Bash,Read,Grep,Glob,Write,Edit' "
106106
"< /dev/null 2>&1"
107107
)
108108
logfire.info("run_claude_code_in_sandbox: executing", cmd=cmd[:200])
109-
process = sb.exec("sh", "-c", cmd)
109+
# text=True, bufsize=1 enables line-buffered streaming (otherwise Modal buffers all output)
110+
process = sb.exec("sh", "-c", cmd, text=True, bufsize=1)
110111
print("[SANDBOX] claude CLI process started", flush=True)
111112
logfire.info("run_claude_code_in_sandbox: claude CLI process started, returning")
112113

0 commit comments

Comments
 (0)