pages: replace the hand-written session-state router #52

Open
opened 2026-10-06 13:53:24 +00:00 by ffrauenberger · 1 comment
Owner

Severity: improvement (medium)

Where

  • app/pages/main_app.py:24-36
  • app/components/buttons.py:25-100
  • All controllers' process_session_state

Problem

The app uses st.navigation for the top-level pages (Home/Imprint/Privacy), but inside "home" it has a second router: st.session_state.page ∈ {Home, ColumnSelection, Algorithm, Export, Documentation}.

  • Navigation is a side effect inside on_click callbacks. These are bound methods of the previous run's controller instance (navigation_button(beforeNavigate=self.controller.set_df, …)), so they act on state captured during the last render.
  • to_home() runs st.session_state.clear(), which removes everything, including infrastructure keys like session_tmp_dir (#20) and user preferences. It is also the only reason the shared widget keys do not leak between algorithms (#48).
  • Redirects are spread across controllers and easy to get wrong (#9, #21, #22): some call st.rerun(), some do not.
  • Pages cannot be bookmarked, and the browser back button does not work.

Related: #9, #20, #21, #22, #48.

Fix

  • Use real st.Pages, or a small explicit state machine, with one navigate(route) helper that always ends in st.rerun()
  • Keep workflow data in a typed state object (dataclass) per workflow instead of loose keys, and reset only that object

from issues/ARCH-007-custom-session-state-router.md (code analysis of commit 6bcc646, 2026-10-03)

**Severity:** improvement (medium) ## Where - `app/pages/main_app.py:24-36` - `app/components/buttons.py:25-100` - All controllers' `process_session_state` ## Problem The app uses `st.navigation` for the top-level pages (Home/Imprint/Privacy), but inside "home" it has a second router: `st.session_state.page` ∈ {Home, ColumnSelection, Algorithm, Export, Documentation}. - Navigation is a side effect inside `on_click` callbacks. These are bound methods of the **previous** run's controller instance (`navigation_button(beforeNavigate=self.controller.set_df, …)`), so they act on state captured during the last render. - `to_home()` runs `st.session_state.clear()`, which removes everything, including infrastructure keys like `session_tmp_dir` (#20) and user preferences. It is also the only reason the shared widget keys do not leak between algorithms (#48). - Redirects are spread across controllers and easy to get wrong (#9, #21, #22): some call `st.rerun()`, some do not. - Pages cannot be bookmarked, and the browser back button does not work. Related: #9, #20, #21, #22, #48. ## Fix - Use real `st.Page`s, or a small explicit state machine, with one `navigate(route)` helper that always ends in `st.rerun()` - Keep workflow data in a typed state object (dataclass) per workflow instead of loose keys, and reset only that object --- from `issues/ARCH-007-custom-session-state-router.md` (code analysis of commit 6bcc646, 2026-10-03)
Author
Owner

Reviewed by Codex (GPT-6) against origin/main 6bcc646eb464.

Review: partially correct.

The routing and broad-reset concerns are supported. The proposed navigation helper should distinguish callbacks from redirects during script execution. Existing buttons call navigate_to as an on_click callback; Streamlit automatically reruns after callbacks, and calling st.rerun() inside a callback is a no-op with a warning. A helper that “always ends in st.rerun” therefore does not itself guarantee termination in both contexts. Keep callbacks as state updates, and make in-script redirects explicitly abort/rerun, or use the framework navigation mechanism.

Code references: app/components/buttons.py:75, app/components/buttons.py:98, app/pages/main_app.py:27.

Reviewed by **Codex (GPT-6)** against origin/main [`6bcc646eb464`](https://code.swisdata.eu/ffrauenberger/ProcessIntel/commit/6bcc646eb464e0dd897228b5e49867f65d7255c4). **Review: partially correct.** The routing and broad-reset concerns are supported. The proposed navigation helper should distinguish callbacks from redirects during script execution. Existing buttons call `navigate_to` as an `on_click` callback; Streamlit automatically reruns after callbacks, and calling `st.rerun()` inside a callback is a no-op with a warning. A helper that “always ends in st.rerun” therefore does not itself guarantee termination in both contexts. Keep callbacks as state updates, and make in-script redirects explicitly abort/rerun, or use the framework navigation mechanism. Code references: [app/components/buttons.py:75](https://code.swisdata.eu/ffrauenberger/ProcessIntel/src/commit/6bcc646eb464e0dd897228b5e49867f65d7255c4/app/components/buttons.py#L75), [app/components/buttons.py:98](https://code.swisdata.eu/ffrauenberger/ProcessIntel/src/commit/6bcc646eb464e0dd897228b5e49867f65d7255c4/app/components/buttons.py#L98), [app/pages/main_app.py:27](https://code.swisdata.eu/ffrauenberger/ProcessIntel/src/commit/6bcc646eb464e0dd897228b5e49867f65d7255c4/app/pages/main_app.py#L27).
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ffrauenberger/ProcessIntel#52
No description provided.