Skip to content

feat: auto-recover from LensAbortError on lens change#7

Open
msilivonik-sc wants to merge 2 commits into
mainfrom
fix/lens-abort-auto-recovery
Open

feat: auto-recover from LensAbortError on lens change#7
msilivonik-sc wants to merge 2 commits into
mainfrom
fix/lens-abort-auto-recovery

Conversation

@msilivonik-sc
Copy link
Copy Markdown
Collaborator

Summary

useApplyLens silently short-circuits when sdkStatus === "error", leaving consumers
wedged on the error view: handing <LensPlayer> a new, playable lensId did nothing,
and the only escape was a manual reinitialize(). This makes the library recover on its own.

The bug

  1. A lens crashes the WASM runtime → LensAbortError → SDK is torn down, sdkStatus = "error".
  2. Consumer sets a new lensId (a different, possibly-fine lens).
  3. useApplyLens sees it but bails because the SDK is still in error.
  4. Nothing reacts — the user stays stuck. Consumers had to ship a
    prevLensIdRef + reinitialize() workaround.

Change

When the lens intent (lensId + lensGroupId + launch-data hash) changes while the SDK
is in error and sdkError?.name === "LensAbortError", useApplyLens calls
reinitialize(). Once the SDK returns to ready, the existing apply effect applies the
new lens.

  • Gated to lens-abort only. A bootstrap failure (bad token, network, WebGL) is
    unrelated to the requested lens, so a lens change does not trigger a rebuild —
    distinguished via the existing sdkError, no new field.
  • Always-on, no loop risk. Only fires on an actual intent change; a lens that
    re-aborts under the same id won't churn. During reinit sdkStatus goes
    error → initializing → ready, so existing loading UI covers the recovery.
  • Emits an auto_reinit_on_lens_change metric.

No public API changes.

Testing

  • npm test → 309 passed, incl. 7 new recovery tests (TDD, confirmed red before green).
  • npm run typecheck clean.

Follow-ups (out of scope)

  • Removing the host's prevLensIdRef/reinitialize workaround once this ships.
  • Minor: provider's applyLens sets lens state to ready even when its apply was
    superseded (resolved false) — small targeted fix, tracked separately.

msilivonik-sc and others added 2 commits June 4, 2026 17:30
useApplyLens silently short-circuited when sdkStatus was "error", leaving
consumers wedged on the error view even when handed a new, playable lensId.

useApplyLens now reinitializes the SDK when the lens intent (lensId + groupId +
launch-data hash) changes while in a LensAbortError, then the existing apply
effect applies the new lens once the SDK is ready. Gated to lens-abort only
(bootstrap failures are unrelated to the requested lens) via the existing
sdkError; emits an auto_reinit_on_lens_change metric. Always-on, no loop on a
re-aborting lens.

No public API changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread src/useApplyLens.ts
const prevRecoveryKeyRef = useRef(recoveryKey);
useEffect(() => {
const changed = prevRecoveryKeyRef.current !== recoveryKey;
prevRecoveryKeyRef.current = recoveryKey;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont you need to move it to line 109?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants