fix(usage-status): prevent crash on Pi reload from stale ExtensionContext#51
Closed
rnavarro wants to merge 1 commit into
Closed
fix(usage-status): prevent crash on Pi reload from stale ExtensionContext#51rnavarro wants to merge 1 commit into
rnavarro wants to merge 1 commit into
Conversation
…text
Pi crashes on reload when the usage-status extension's setInterval
timer fires with an ExtensionContext that has gone stale. The
ExtensionContext.hasUI getter calls assertActive(), which throws
after session replacement or reload.
I hit this when reloading Pi after switching providers with Ctrl+P.
Pi would crash immediately with:
Error: This extension ctx is stale after session replacement
or reload.
at ExtensionRunner.assertActive (runner.js:297)
The timer callback and several other code paths accessed captured
ctx properties (hasUI, ui.setStatus, modelRegistry) without
checking liveness. A ctx that becomes stale during an async gap
(e.g., after await getSyntheticApiKey) also caused unhandled
rejections from the catch block re-touching ctx.ui.
Add isCtxLive() helper that safely probes hasUI in a try/catch
to detect stale contexts, and apply it at every entry point that
touches a captured ExtensionContext:
- setInterval callback: isCtxLive guard before updateFooterStatus
- stopAutoRefresh(): clear activeContext; guard ctx.ui access
- updateFooterStatus(): isCtxLive at entry and after each await
- updateFooterStatus() catch: guard against double-throw
- updateFooterStatus() queuedRefresh: use activeContext instead
of the captured ctx parameter (which may belong to a prior session)
- setLoadingStatus(): isCtxLive after await
- renderFromLastSnapshot(): isCtxLive guard
- SYNTHETIC_CONFIG_UPDATED_EVENT handler: isCtxLive on currentContext
14 new tests cover the stale context guard, stop behavior,
mid-session staleness, stopAutoRefresh with stale ctx, and
non-UI mode (hasUI=false on a live context).
Owner
Author
|
Nice! Good stuff, thanks for all you do on this extension! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pi crashes on reload when the usage-status extension's
setIntervaltimer fires with anExtensionContextthat has gone stale. TheExtensionContext.hasUIgetter callsassertActive(), which throws after session replacement or reload.I hit this when reloading Pi after switching providers with Ctrl+P. Pi would crash immediately with:
The timer callback and several other code paths accessed captured ctx properties (
hasUI,ui.setStatus,modelRegistry) without checking liveness. A ctx that becomes stale during an async gap (e.g., afterawait getSyntheticApiKey) also caused unhandled rejections from the catch block re-touchingctx.ui.Fix: Add
isCtxLive()helper that safely probeshasUIin a try/catch to detect stale contexts, and apply it at every entry point that touches a capturedExtensionContext:setIntervalcallback:isCtxLiveguard beforeupdateFooterStatusstopAutoRefresh(): clearactiveContext; guardctx.uiaccessupdateFooterStatus():isCtxLiveat entry and after eachawaitupdateFooterStatus()catch: guard against double-throw on stale ctxupdateFooterStatus()queuedRefresh: useactiveContextinstead of the capturedctxparameter (which may belong to a prior session)setLoadingStatus():isCtxLiveafterawaitrenderFromLastSnapshot():isCtxLiveguardSYNTHETIC_CONFIG_UPDATED_EVENThandler:isCtxLiveoncurrentContext14 new tests cover the stale context guard, stop behavior, mid-session staleness,
stopAutoRefreshwith stale ctx, and non-UI mode (hasUI=falseon a live context).