Prevent system theme sync from crashing after Pi reloads - #3
Open
GodGardensGuns wants to merge 1 commit into
Open
Prevent system theme sync from crashing after Pi reloads#3GodGardensGuns wants to merge 1 commit into
GodGardensGuns wants to merge 1 commit into
Conversation
MainasuK
added a commit
to MainasuK/pi-system-theme
that referenced
this pull request
Sep 6, 2026
…ction Fix upstream issues ferologics#3/ferologics#4: polling captured a session ExtensionContext and resumed async detection on contexts pi had invalidated after session replacement (/new, fork, switchSession) or /reload, throwing 'This extension ctx is stale...' and crashing pi. - ctx is never captured in the interval; each poll reads the current session context behind a generation token - generation is re-checked after every await before touching ctx.ui - polling stops on session_shutdown and restarts on session_start; beginSession claims the context before the config-load await and clears stale polling/in-flight state - sync/poll errors are caught and logged, never uncaught Add configurable appearance source ('os' | 'env' | 'force-dark' | 'force-light') for SSH/headless hosts where OS appearance APIs describe the host GUI session, not the terminal the user sees. env uses COLORFGBG (the only client-terminal signal extensions can access). Document that for exact terminal-following over SSH pi's built-in 'light/dark' auto theme is the reliable mechanism. Adds 12 regression tests (21 total); verified in a real interactive pi run across /new and /reload with no stale-context errors.
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.
Issue
Pi now marks extension contexts as stale after session replacement or reload.
pi-system-themekeeps a polling interval that captures thectxfromsession_start. If Pi reloads, forks, switches sessions, or otherwise shuts down the current extension runtime while an appearance detection poll is in flight, that async poll can resume later and accessctx.ui.That raises:
In interactive mode this can crash Pi via an uncaught exception.
Fix
session_shutdownctx.ui/system-themesave/apply behavior guarded against stale sessions as wellTesting
npx --yes vitest runAlso added a regression test that simulates shutdown while appearance detection is in flight and verifies the stale
ctx.uiis not accessed.