Skip to content

Commit aaabb69

Browse files
fix: add print statements with flush=True for Cloud Run logs (#33)
1 parent 4ffb918 commit aaabb69

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/policyengine_api/agent_sandbox.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def run_claude_code_in_sandbox(
4646

4747
from policyengine_api.config import settings
4848

49+
print("[SANDBOX] run_claude_code_in_sandbox starting", flush=True)
4950
logfire.info(
5051
"run_claude_code_in_sandbox: starting",
5152
question=question[:100],
@@ -63,10 +64,13 @@ def run_claude_code_in_sandbox(
6364
}}"""
6465

6566
# Get reference to deployed app (required when calling from outside Modal)
67+
print("[SANDBOX] looking up Modal app", flush=True)
6668
logfire.info("run_claude_code_in_sandbox: looking up Modal app")
6769
sandbox_app = modal.App.lookup("policyengine-sandbox", create_if_missing=True)
70+
print("[SANDBOX] Modal app found", flush=True)
6871
logfire.info("run_claude_code_in_sandbox: Modal app found")
6972

73+
print("[SANDBOX] creating sandbox", flush=True)
7074
logfire.info("run_claude_code_in_sandbox: creating sandbox")
7175
sb = modal.Sandbox.create(
7276
app=sandbox_app,
@@ -75,6 +79,7 @@ def run_claude_code_in_sandbox(
7579
timeout=600,
7680
workdir="/tmp",
7781
)
82+
print("[SANDBOX] sandbox created", flush=True)
7883
logfire.info("run_claude_code_in_sandbox: sandbox created")
7984

8085
# Log from inside the sandbox via Python

src/policyengine_api/api/agent.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,16 @@ async def _stream_modal_sandbox(question: str, api_base_url: str):
8989
"""Stream output from Claude Code running in Modal Sandbox."""
9090
from concurrent.futures import ThreadPoolExecutor
9191

92-
# Immediate log and yield
92+
# Immediate log
93+
print("[AGENT] _stream_modal_sandbox started", flush=True)
9394
logfire.info("_stream_modal_sandbox: started", question=question[:100])
9495

9596
sb = None
9697
executor = ThreadPoolExecutor(max_workers=1)
9798
try:
9899
from policyengine_api.agent_sandbox import run_claude_code_in_sandbox
99100

101+
print("[AGENT] creating sandbox", flush=True)
100102
logfire.info(
101103
"_stream_modal_sandbox: creating sandbox", api_base_url=api_base_url
102104
)
@@ -106,6 +108,7 @@ async def _stream_modal_sandbox(question: str, api_base_url: str):
106108
sb, process = await loop.run_in_executor(
107109
executor, run_claude_code_in_sandbox, question, api_base_url
108110
)
111+
print("[AGENT] sandbox created", flush=True)
109112
logfire.info("_stream_modal_sandbox: sandbox created")
110113

111114
# Poll for lines with timeout to allow other async tasks
@@ -215,6 +218,7 @@ async def stream_analysis(request: AskRequest):
215218
data: {"type": "done", "returncode": 0}
216219
```
217220
"""
221+
print(f"[AGENT] /stream called, use_modal={settings.agent_use_modal}", flush=True)
218222
api_base_url = settings.policyengine_api_url
219223
logfire.info(
220224
"stream_analysis: called",

0 commit comments

Comments
 (0)