Describe the bug
When the agent starts streaming output in the Streamlit frontend (frontends/stapp.py), Streamlit raises:
A fragment tried to write to a container created outside the fragment. This is not allowed. Streamlit may not be able to correctly render the container ... Could not reserve a stable position.
Environment
- GenericAgent commit:
d426d45 (main, 2026-08-08)
- Streamlit: 1.60.0 (declared requirement is
streamlit>=1.28)
- Platform: macOS, Python 3.12
Root cause
_tick() is a @st.fragment(run_every=...) that writes into _stream_fh, a container created outside the fragment (module scope). Streamlit only allows a fragment to write to an external container if that container has already been claimed during a full app run; otherwise the first write raises the error above. The current code never claims the container before writing expanders into it.
Steps to reproduce
streamlit run frontends/stapp.py
- Send any prompt that produces streaming output (LLM Running ...)
- Observe the fragment error once the first step expander is folded into
_stream_fh
Suggested fix
Claim the external container before streaming into it, e.g. inside _tick:
_stream_claimed = False # module scope
# inside _tick(), before the first expander write:
if frozen == 0 and not _stream_claimed:
with _stream_fh:
st.markdown("") # claim: reserve a stable position in the external container
_stream_claimed = True
This works on Streamlit 1.60 and avoids the error entirely.
Related: #574 (fragment rerun scope fallback) fixed a different fragment issue but not this one.
Describe the bug
When the agent starts streaming output in the Streamlit frontend (
frontends/stapp.py), Streamlit raises:Environment
d426d45(main, 2026-08-08)streamlit>=1.28)Root cause
_tick()is a@st.fragment(run_every=...)that writes into_stream_fh, a container created outside the fragment (module scope). Streamlit only allows a fragment to write to an external container if that container has already been claimed during a full app run; otherwise the first write raises the error above. The current code never claims the container before writing expanders into it.Steps to reproduce
streamlit run frontends/stapp.py_stream_fhSuggested fix
Claim the external container before streaming into it, e.g. inside
_tick:This works on Streamlit 1.60 and avoids the error entirely.
Related: #574 (fragment rerun scope fallback) fixed a different fragment issue but not this one.