fix(viewer): end IDS and rule-set runs when their model set changes mid-run
Defect
An in-flight IDS (useIDS.runValidation) or rule-set (useInformationValidation.run) validation published its report even when the models it read changed while it ran. useValidationEpoch only moves on run, cancel and definition change. The teardowns that change the model set reset flags and nothing else:
removeModel/clearAllModelscallclearIdsValidationReport(), which setsidsLoading: false.- The session reset ("open a new file",
idsSlice.teardown.ts) also setsidsLoading: false. - A collab peer edit swaps a model's store, and nothing resets anything.
The run carried on. It kept writing idsProgress while idsLoading was already false, then published a report whose snapshot named the removed model and recoloured its entity ids. After a reload, those ids can belong to unrelated entities.
Scenario
- Load federated A+B and run IDS (or a rule set).
- Remove B, clear all, open a new file, or let a peer edit replace B's store.
- The run completes and publishes a report for A+B.
Fix
- Shared check, moved from clash. The federation-identity token and the whole-federation check move from
lib/clash/federation-identity.tstolib/federation/federation-identity.ts, asfederationIsCurrent,recordGatheredModeland the newcaptureFederationIdentity. Clash imports them from there with the same token and logic, so its behaviour is unchanged. The clash file keeps only the clash parts: the per-result identity and the per-ref checks. - New
hooks/validation/validationRunGuard.ts. It captures the identity of the models the run actually read and the store'svalidationRunGeneration.- The models are passed in by the hook rather than read from
getState().useIDSpasses the render-timemodelsandifcDataStoreit resolved the target from, so a retained stalerunValidationclosure cannot look current. - It subscribes for the run's lifetime, the same pattern as
lib/scan-to-bim/run-detection.ts. When either signal changes, it calls the hook's own cancel (epoch bump, abort, loading/progress reset), deferred to a microtask. - The publish site also checks
isCurrent(). That check refuses a run whose captured models were already stale at start, and a change the subscription cannot see. A refused IDS run clears its own progress.
- The models are passed in by the hook rather than read from
- Teardown now ends the run. The
session-resetteardown arm bumpsvalidationRunGeneration. - Why two signals. A session reset keeps
models(it only nulls the top-levelifcDataStore), so the identity alone misses it in a federated session. A peer-edit store swap bumps nothing, so the generation alone misses that. Removal and clear-all are caught by the identity. - Models added mid-run keep a federated run, the same rule clash uses. A legacy single-store run that sees a federated model added is cancelled. That cancellation is spurious but harmless: nothing wrong is published, and a comment on
runModelsnotes it.
Clash, compare and flow teardown are not changed. The shared helper does not make any of them a one-line change.
Tests
All test runs were capped with systemd-run --user --scope -p MemoryMax=8G -p MemorySwapMax=0. No run hit the cap.
-
src/hooks/useIDS.federation-change-mid-run.test.tsx, 6/6 at head:- remove model, clear all, session reset, entity-table swap, and model added (still publishes);
- a retained
runValidationfrom before a removal refuses to publish for the removed model. - The store is restored between tests.
- Before the fix, the remove, clear-all and session-reset cases failed.
-
src/hooks/validation/useInformationValidation.federation-change-mid-run.test.tsx, 4/4 at head:- remove model, session reset, and an in-place swap the subscription cannot see (refused at publish);
- an untouched model set still publishes.
- Before the fix, the remove and session-reset cases failed.
-
src/store/teardown-registry.test.ts, 6/6 at head.validationRunGenerationis in bothPINNED_OWNED_KEYSand the session-reset write list. -
Mutation checks, each run on both new files with the source restored afterwards. Each mutation makes the named tests fail:
Mutation Tests that fail M3: remove the publish-site isCurrent()check from both hooksIDS stale-closure, rule-set in-place swap M4: the guard captures store.getState()instead of the run's modelsIDS stale-closure M5: drop the session-reset bump both session-reset tests (IDS and rule set) -
Related suites at head: 94 files in one run, covering every
useClash*,useIDS*,useInformationValidation*, idsSlice, teardown,lib/clash,lib/compare,useValidation*, validationDraft, modelLifecycle and clearAllModels test. Results: 777 tests, 776 pass, 0 fail, 1 skipped. The skip is the #8040 Revit fixture, which is absent locally. -
check-module-size: OK.check-source-text-assertions: OK.
Typecheck: root pnpm typecheck passed through the fleet on 8a2358c83 (job c8971083, exit 0, all 4696 test files in a typecheck program).
Unverified
- No manual browser run of the scenario.
- The full viewer suite was not run locally; it runs in the merge queue.
š¤ Generated with Claude Code