mining: decouple the mining models from Streamlit session state #46

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

Severity: improvement (high: the models cannot be used or tested outside Streamlit)

Where

  • app/mining_algorithms/base_mining.py:3, :113-124, :755-783
  • app/io_operations/export_operations.py:5, :130-135

Problem

BaseMining, the domain layer, imports streamlit and:

  • writes widget keys (node_freq_threshold_*, edge_freq_threshold_*, last_*) into st.session_state in its constructor;
  • in _sync_thresholds, reads user input from st.session_state to decide which threshold "moved last", and writes corrected values back.

ExportOperations.export_to_xes_bytes also depends on st.session_state.session_tmp_dir.

Consequences:

  • Two sources of truth. Controllers pass thresholds to generate_graph, but the model overrides them from session state, so behaviour depends on hidden UI state (#11).
  • Miners cannot be used outside a Streamlit run (CLI, batch job, notebook, library API). Unit tests run with Streamlit "bare mode" warnings and leak state between tests.
  • The model modifies widget values after the widgets exist, which conflicts with Streamlit's rules. It only works because mining happens to run before the sidebar is rendered.

It also blocks running mining in a worker (#54).

Fix

  • Make miners pure: generate_graph(params) -> (graph, effective_params)
  • Move the normalized ↔ absolute threshold synchronization into the controller/view layer
  • Pass temp directories (or better, in-memory buffers) explicitly
  • Remove the streamlit import from the mining and IO layers

from issues/ARCH-001-mining-models-coupled-to-streamlit-session-state.md (code analysis of commit 6bcc646, 2026-10-03)

**Severity:** improvement (high: the models cannot be used or tested outside Streamlit) ## Where - `app/mining_algorithms/base_mining.py:3`, `:113-124`, `:755-783` - `app/io_operations/export_operations.py:5`, `:130-135` ## Problem `BaseMining`, the domain layer, imports `streamlit` and: - writes widget keys (`node_freq_threshold_*`, `edge_freq_threshold_*`, `last_*`) into `st.session_state` in its constructor; - in `_sync_thresholds`, **reads** user input from `st.session_state` to decide which threshold "moved last", and writes corrected values back. `ExportOperations.export_to_xes_bytes` also depends on `st.session_state.session_tmp_dir`. Consequences: - **Two sources of truth.** Controllers pass thresholds to `generate_graph`, but the model overrides them from session state, so behaviour depends on hidden UI state (#11). - Miners cannot be used outside a Streamlit run (CLI, batch job, notebook, library API). Unit tests run with Streamlit "bare mode" warnings and leak state between tests. - The model modifies widget values after the widgets exist, which conflicts with Streamlit's rules. It only works because mining happens to run before the sidebar is rendered. It also blocks running mining in a worker (#54). ## Fix - Make miners pure: `generate_graph(params) -> (graph, effective_params)` - Move the normalized ↔ absolute threshold synchronization into the controller/view layer - Pass temp directories (or better, in-memory buffers) explicitly - Remove the `streamlit` import from the mining and IO layers --- from `issues/ARCH-001-mining-models-coupled-to-streamlit-session-state.md` (code analysis of commit 6bcc646, 2026-10-03)
Author
Owner

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

Review: partially correct.

The hidden session-state dependency and two sources of truth are supported. However, “the models cannot be used or tested outside Streamlit” is too strong. The repository already runs miner unit tests in ordinary Python bare mode, and I constructed a HeuristicMining model and generated a graph with nodes Start, End, a outside a Streamlit script. Streamlit emits context warnings; it does not categorically prohibit execution. The accurate concern is that standalone use is noisy and not reliably isolated/pure, and explicit parameters can be overridden by hidden state. XES-byte export additionally requires its temp-directory session key. Decoupling is still justified.

Code references: app/mining_algorithms/base_mining.py:113, app/mining_algorithms/base_mining.py:755.

Reviewed by **Codex (GPT-6)** against origin/main [`6bcc646eb464`](https://code.swisdata.eu/ffrauenberger/ProcessIntel/commit/6bcc646eb464e0dd897228b5e49867f65d7255c4). **Review: partially correct.** The hidden session-state dependency and two sources of truth are supported. However, “the models cannot be used or tested outside Streamlit” is too strong. The repository already runs miner unit tests in ordinary Python bare mode, and I constructed a `HeuristicMining` model and generated a graph with nodes `Start`, `End`, `a` outside a Streamlit script. Streamlit emits context warnings; it does not categorically prohibit execution. The accurate concern is that standalone use is noisy and not reliably isolated/pure, and explicit parameters can be overridden by hidden state. XES-byte export additionally requires its temp-directory session key. Decoupling is still justified. Code references: [app/mining_algorithms/base_mining.py:113](https://code.swisdata.eu/ffrauenberger/ProcessIntel/src/commit/6bcc646eb464e0dd897228b5e49867f65d7255c4/app/mining_algorithms/base_mining.py#L113), [app/mining_algorithms/base_mining.py:755](https://code.swisdata.eu/ffrauenberger/ProcessIntel/src/commit/6bcc646eb464e0dd897228b5e49867f65d7255c4/app/mining_algorithms/base_mining.py#L755).
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#46
No description provided.