Skip to content

Commit 3303cc0

Browse files
committed
diag: print stdout markers in click handler
Streamlit Cloud's runtime log captures stdout. Adding [CANAID-DIAG] markers at every step of the click → handler → stream path so the last marker before the page goes blank tells us where the script died: click_received → user_message_rendered → assistant_block_opened → entering_frame_stream → frame=intent → frame=token → ... Plus stream_exception with full traceback if any frame iteration raises. This is debug instrumentation; will be removed once we identify the failure point.
1 parent df92df2 commit 3303cc0

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/canaid/ui/streamlit_app.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,17 @@ def _render_usage(usage: dict | None) -> None:
327327

328328

329329
if prompt:
330+
# ---- diagnostic markers — go straight to stdout, captured by Streamlit
331+
# Cloud's runtime log even if the page itself fails to render.
332+
print(f"[CANAID-DIAG] click_received len={len(prompt)} embedded={EMBEDDED_MODE}", flush=True)
333+
330334
st.session_state.messages.append({"role": "user", "content": prompt})
331335
with st.chat_message("user"):
332336
st.markdown(prompt)
337+
print("[CANAID-DIAG] user_message_rendered", flush=True)
333338

334339
with st.chat_message("assistant"):
340+
print("[CANAID-DIAG] assistant_block_opened", flush=True)
335341
# Layout order matches how the eye reads the message: cache badge
336342
# at the very top (rare, signals "this was free"), then the
337343
# response body, then the supporting trace expanders below.
@@ -355,10 +361,12 @@ def _render_usage(usage: dict | None) -> None:
355361
cache_hit = False
356362

357363
try:
364+
print("[CANAID-DIAG] entering_frame_stream", flush=True)
358365
for payload in _frame_stream(prompt, st.session_state.conversation_id):
366+
kind = payload.get("type")
367+
print(f"[CANAID-DIAG] frame={kind}", flush=True)
359368
# Clear the cold-start status the moment any frame arrives.
360369
status_box.empty()
361-
kind = payload.get("type")
362370
if kind == "cache_hit":
363371
cache_hit = True
364372
cache_box.success("⚡ cache hit — replayed without LLM call")
@@ -403,14 +411,15 @@ def _render_usage(usage: dict | None) -> None:
403411
)
404412
elif kind == "error":
405413
accumulated = f"_Error: {payload.get('message')}_"
406-
except Exception as exc:
414+
except Exception as exc: # noqa: BLE001
407415
status_box.empty()
416+
tb_text = traceback.format_exc()
417+
print(f"[CANAID-DIAG] stream_exception {type(exc).__name__}: {exc}\n{tb_text}", flush=True)
408418
# Surface the full traceback inline so Streamlit Cloud users can
409419
# see what went wrong without digging into the logs panel.
410-
import traceback
411420
accumulated = (
412421
f"**Stream error — {type(exc).__name__}: {exc}**\n\n"
413-
f"```\n{traceback.format_exc()}\n```"
422+
f"```\n{tb_text}\n```"
414423
)
415424

416425
body.markdown(accumulated or "_(no response)_")

0 commit comments

Comments
 (0)