From 8a391a61e065a39aaa1684294f0459c6ff664e6c Mon Sep 17 00:00:00 2001 From: Kailigithub Date: Sat, 6 Jun 2026 03:12:42 +0800 Subject: [PATCH] fix(stapp): fall back to st.rerun() when fragment scope rerun is unavailable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- frontends/stapp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontends/stapp.py b/frontends/stapp.py index 5c49c7f3..036b90a2 100644 --- a/frontends/stapp.py +++ b/frontends/stapp.py @@ -61,7 +61,11 @@ def render_sidebar(): st.caption(f"LLM Core: {llm_labels.get(current_idx, str(current_idx))}") 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") if selected_idx != current_idx: - agent.next_llm(selected_idx); st.rerun(scope="fragment") + agent.next_llm(selected_idx) + try: + st.rerun(scope="fragment") + except st.StreamlitAPIException: + st.rerun() if st.button(T('force_stop')): agent.abort(); st.toast("Stop signal sended"); st.rerun() if st.button(T('reinject_tools')):