fix(stapp): fall back to st.rerun() when fragment scope rerun is unavailable#574
Open
Kailigithub wants to merge 1 commit into
Open
fix(stapp): fall back to st.rerun() when fragment scope rerun is unavailable#574Kailigithub wants to merge 1 commit into
Kailigithub wants to merge 1 commit into
Conversation
…ailable Issue lsdefine#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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #564
The Streamlit sidebar in
frontends/stapp.pycrashes on startup when the persisted LLM selectbox value (st.session_state['sidebar_llm_select']) disagrees with the agent's currentllm_no:Root cause
render_sidebar()is decorated with@st.fragment. On the initial app run, the function executes as part of the main script — not as a fragment rerun. Ifselected_idx != current_idxtriggers in that first execution, callingst.rerun(scope="fragment")is illegal and Streamlit aborts.The other
st.rerun(scope="app")calls in the same fragment are unaffected —scope="app"is legal from both fragment and non-fragment contexts; the restriction applies only toscope="fragment".Fix
Wrap the call so that when fragment-scoped rerun is unavailable (initial run / outside a fragment rerun), we fall back to a full
st.rerun(). The user-visible behavior is unchanged: the LLM is switched and the UI refreshes either way.frontends/stapp2.pydoes not usescope="fragment"and is unaffected. No other frontend touches this pattern.Verification
python3 -m py_compile frontends/stapp.py— passesruff check frontends/stapp.py— no new findings introduced by this change (60 pre-existing project-style warnings remain, untouched)scope="fragment"is legal and faster) is preserved