Skip to content

Commit 5eaaf6b

Browse files
committed
fix(stapp): fall back to st.rerun() when fragment scope rerun is unavailable
Issue #564 reports a StreamlitAPIException on startup when the LLM selectbox in the sidebar detects a stale selected_idx (e.g. from a prior session_state). The handler calls st.rerun(scope="fragment"), which is only legal during a fragment rerun — on the initial script run it raises: StreamlitAPIException: scope="fragment" can only be specified from @st.fragment-decorated functions during fragment reruns. Wrap the call so that on the initial run (or any context where fragment rerun is unavailable) we fall back to a full st.rerun() instead of crashing.
1 parent b1e173d commit 5eaaf6b

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

frontends/stapp.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ def render_sidebar():
105105
st.caption(f"LLM Core: {llm_labels.get(current_idx, str(current_idx))}")
106106
selected_idx = st.selectbox("LLM", [idx for idx, _, _ in llm_options], index=next((i for i, (idx, _, _) in enumerate(llm_options) if idx == current_idx), 0), format_func=llm_labels.get, label_visibility="collapsed", key="sidebar_llm_select")
107107
if selected_idx != current_idx:
108-
agent.next_llm(selected_idx); st.rerun(scope="fragment")
108+
agent.next_llm(selected_idx)
109+
try:
110+
st.rerun(scope="fragment")
111+
except st.StreamlitAPIException:
112+
st.rerun()
109113
if st.button(T('force_stop')):
110114
agent.abort(); st.toast("Stop signal sended"); st.rerun()
111115
if st.button(T('desktop_pet')):

0 commit comments

Comments
 (0)