Repository navigation
Description
Whether LTM runs in discovery or exhaustive mode is stored as a flag on the project in the incremental-compile database, not passed as an argument to the queries that need it.
Every flip of the flag is a new database revision, so switching modes throws away the other mode's cached LTM work and forces every cached value in the project to be re-checked.
The mode should be a query argument, the way the LTM on/off choice already is.
Example
A pysimlin session that alternates an LTM simulation (exhaustive mode by default) with Model.analyze() (discovery mode) on one project.
analyze_model sets the flag to discovery and restores the caller's value afterwards, so each analyze call costs two revisions and the exhaustive-mode LTM variables are rebuilt on the next simulation.
For the analogous LTM on/off flag, the same pattern cost about 2.5-2.9 billion instructions per flip on C-LEARN before it was made an argument (docs/design/engine-performance.md, "The LTM overlay is an argument, not an input").
Discovery mode has not been measured.
Why it matters
Shared-database callers (libsimlin, so pysimlin) keep one database per project so repeat queries are cheap; this flag defeats that for anyone who uses both modes.
The browser editor and the MCP tools do not alternate: the editor never runs discovery, and the MCP tools build a fresh database per call.
It is also two mechanisms for two knobs of the same shape, and the set/restore code in analyze_model, wasmgen::compile_datamodel_to_artifact, and libsimlin model.rs exists only to keep the flag clean.
Fix
Add a requested-mode argument to model_ltm_mode and model_ltm_variables and thread it through their dependents; delete the project field, set_project_ltm_discovery_mode, and the set/restore code.
Cost: when both modes are used on one project, both sets of LTM values stay cached (the on/off change cost about 5 MiB on C-LEARN; this tier is larger).
Measure the pysimlin alternation on C-LEARN first.
Pointers
src/simlin-engine/src/db/input.rs(ltm_discovery_mode),db.rs(set_project_ltm_discovery_mode)src/simlin-engine/src/db/ltm/mod.rs(model_ltm_mode,model_ltm_variables)src/simlin-engine/src/analysis.rs(analyze_model),src/libsimlin/src/model.rssrc/simlin-engine/src/db/ltm_overlay_tests.rs(how the on/off argument is tested)
Activity
[-]engine: ltm_discovery_mode is still a salsa input; flipping it discards the other mode's memos[/-][+]engine: switching LTM discovery mode discards cached LTM work[/+]