fix(server-client): cancel cached data polling and surface fetch failures

Merged
LO
21d ago
+908-256

Viewer loading coordination: Complete progress, model finalization and load telemetry follow geometry readiness. Optional properties continue independently in a model-keyed store run slot, survive the initiating component's unmount/remount, and appear as a cancellable activity-tray job. They never inherit the loader's metadataAbort signal. The loader and useIfcServer.ts have no additional changes in this round; the latter stays at exactly 400 lines.

Removal, clear-all, session teardown, model/source replacement, failed models, load-identity supersession and a newer primary load from any hook instance end the poll. Publication checks both the lease and the captured model identity, then updates that model's record, including when inactive. Source-file and initial data-store identity are intentionally preserved by the geometry finalizer; another writer replacing either identity invalidates the older property result. A fast property response waits for geometry finalization before publishing, so the finalizer's null placeholder cannot overwrite it. None of this delays geometry completion. No component state or generation counter owns the work.

Missing-model-id audit: the only production loadFromServer call is useIfcLoader.loadFile (apps/viewer/src/hooks/useIfcLoader.ts:1240). It passes its explicit modelId; its primary placeholder is registered by upsertModel around line 471 before the server branch. That branch requires target.kind === 'primary'; federation uses the canonical loader but skips this branch. useIfc delegates to that loader. There is no separate legacy single-model caller or caller registering after the server result. The first-load-from-empty-store loader regression reaches property polling successfully. Invalid direct calls with null or unregistered ids now warn rather than silently losing hydration; both paths are tested.

Server-client contract and callers

Both cached-data polling methods accept a caller signal and stop fetch/backoff on abort. fetchDataModel rejects HTTP failures and exhausted transport failures rather than resolving null; fetchSymbolic follows the same contract. Null means missing or still pending. Ready-response body-read failures reject immediately without retrying the body. The guide, app callers and generated server example catch optional-property rejection without discarding successful geometry. The generated streaming example has its own optional-fetch catch.

Changesets: @ifc-lite/server-client major, @ifc-lite/viewer patch (private app), create-ifc-lite patch. The viewer changeset describes the store-owned poll surviving component remounts. There is no exported-symbol snapshot change.

Validation

All validation runs locally with systemd-run --user --scope -q -p MemoryMax=8G -p MemorySwapMax=0; built TypeScript siblings are used, with no Rust/WASM rebuild. Two interrupted typecheck attempts supplied no acceptance result; only the completed gate below is counted.

  • Viewer loader/server/federation/canceller family: 212 passed, 2 skipped (missing IFC5 fixtures; the skip points to pnpm fixtures). Server-client: 146 passed across 19 files.
  • Both viewer and viewer-embed typechecks passed, including their test sources. The focused model-properties witness passed 24/24 on final source.
  • Full lint passed: 13,000 files, 0 errors, 3 unrelated warnings.
  • Module-size and source-text-assertion checks passed. Every grown production file was compared against origin/main: new server-attempt helper 19, properties coordinator 85, new store slice 41, store index 288→290, teardown registry 150→152, generated server-stream template 118, cached-data helper 52; each is below the default 400-line limit. Loader stays 2,170 against its tightened 2,170 budget (main 2,171); server hook 400 (main 436; allowance deleted); federation 551/551; server-client 929/929. No budget is raised.
  • Post-commit pre-handoff: 13 passed, retained-free viewer check skipped because apps/viewer/dist is absent.
  • Production-revert oracle: OBSERVED. Baseline 24 passed; reverting all seven changed viewer production files yields 21 assertion failures, 3 passes, without missing-module failures; verified restoration passes 24/24 again. The working tree is clean.

Rerunnable root commands (apply the systemd cap above to each):

TEST_PATTERN='(useIfcLoader|useIfcFederation|useIfcServer|modelLoadCanceller)[^/]*\.test\.tsx?$' pnpm test --filter=@ifc-lite/viewer --filter=@ifc-lite/server-client --only
TEST_PATTERN='^src/hooks/useIfcServer.modelProperties.test.tsx$' pnpm test --filter=@ifc-lite/viewer --only
TEST_PATTERN='^src/store/teardown[^/]*\.test\.ts$' pnpm test --filter=@ifc-lite/viewer --only
pnpm exec turbo typecheck --filter=@ifc-lite/viewer --filter=@ifc-lite/viewer-embed --only --concurrency=1 --force
pnpm lint
node scripts/check-module-size.mjs
node scripts/check-source-text-assertions.mjs
node scripts/pre-handoff.mjs
node scripts/check-test-revert-oracle.mjs --base origin/main --only apps/viewer/src --test apps/viewer/src/hooks/useIfcServer.modelProperties.test.tsx --verify-restored --ci

Local lint serializes its real compiler children using an external resource-only flock preload to fit 8 GiB; compiler arguments, scope, diagnostics, statuses and baselines are unchanged. The standalone unused-locals baseline test remains skipped as requested; full lint still runs the actual unused-locals gate. CI also runs root Typecheck and Lint.

Regression and mutation evidence

Both component-survival tests failed first on the previous implementation, with signal.aborted === true instead of false. Exact witnesses in useIfcServer.modelProperties.test.tsx:

  • #9538 unmount of the starting component keeps model properties alive and publishes
  • #9538 a remount of the starting component keeps model properties alive and publishes
  • #9538 late properties publish into their still-current model
  • #9538 silent supersession is checked again at the publication boundary
  • #9538 fast properties wait for finalization so its null placeholder cannot overwrite them
  • #9538 teardown while properties wait for finalization aborts and releases both watchers
  • #9538 the activity tray can cancel model properties after the starting component unmounts
  • #9538 unregistered model null reports why optional properties cannot start
  • #9538 unregistered model not-registered reports why optional properties cannot start

The parameterized abort witness has the exact name #9538 <cause> aborts model properties and a transport ignoring abort cannot publish, for each of: remove, clear, session-reset, reused-id, replace, supersede, failed-model, other-hook-primary, source-replace. Each asserts prompt signal abortion and releases a valid real Parquet property payload through a transport deliberately ignoring abort to verify no late write.

useIfcLoader.serverStaleness.test.tsx retains these exact witnesses:

  • #9538 geometry completes and load finally leaves the model property poll alive: starts with an empty store, observes loaded/Complete before releasing the optional request, and checks that finally leaves its signal live.
  • #9538 cancel during server geometry never enters the local fallback
  • #9538 supersede during server geometry never enters the local fallback
  • #9538 a current server failure starts local processing

This round: 22 of 23 targeted mutants killed, not exhaustive coverage. Killed mutations restore component ownership; remove source/data identity, failed-model/staleness checks, cross-hook primary watching, store observation, lease/publication/scope settlement checks, warning, missing-response preservation, finalization barrier/abort cleanup, unsubscribe or success-before-publication; or reuse the metadata signal / remove the stale and current-failure server-attempt guards. Removal and clear each have a combined mutation disabling the teardown arm and reactive identity invalidation, since those are independent defenses. Session-reset teardown is killed independently. The one survivor removes the defensive owner-token comparison in the slot's read binding: dropping the prior record before starting the replacement already ends that lease; no independent coverage is claimed for that additional defense. Generic shared run-slot internals and every decode/error branch are not individually mutated.

Unverified: a live remote server and real-browser drawing/mobile remount interactions. Tests use controlled transport with real server-wire decoding; no claim of a live IFC/browser acceptance run. Labels are unchanged.

šŸ¤– Generated with Claude Code