Repository navigation
refactor(desktop): stabilize app-shell action factory identities - #1162
Merged
Merged
Conversation
The 9 createAppShell*Actions factories ran unmemoized in the AppShell render body, so every render allocated fresh handler identities. The one observable harm: the streaming-settle fallback effect lists settleAssistantStreaming in its deps and therefore tore down and re-armed its 1s timer on every render while armed (#1043). Introduce useStableActions: the factory still runs every render (so closures always capture the latest deps, identical to calling it bare), but consumers receive a once-created delegating facade whose method identities never change. Publication to the facade happens in useLayoutEffect, so only the latest COMMITTED render's actions are reachable — an interrupted or discarded concurrent render cannot leak its closures to event handlers, timers, or subscriptions (render-phase ref writes are limited to the lazy initialization React permits). The settle timer now arms once by construction, and any future effect-dep or memoized-child consumer is safe by the same mechanism. - createDelegatingActions (pure, React-free) pinned by node:test unit tests; source-contract tests pin the wiring at all 9 call sites and forbid the render-phase publication this design rejected - remove the hand-rolled sessionRowActionHandlersRef mirror superseded by the facade; the fail-soft contract moves to the facade pattern with unchanged semantics (dedup registry, no fire-and-forget void) - createAppShellStopAction stays unwrapped: it returns a bare function and only feeds JSX props, never effect deps
Astro-Han
force-pushed
the
refactor/1043-app-shell-stable-actions
branch
from
July 17, 2026 06:37
5427669 to
09534b4
Compare
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.
Summary
Refs #1043 (step 1 of the plan documented there).
The 9
createAppShell*Actionsfactories ran unmemoized in the AppShell render body, so every render allocated fresh handler identities. The one observable harm: the streaming-settle fallback effect listssettleAssistantStreamingin its deps, so its 1s timer tore down and re-armed on every render while armed — under continuous render churn the fallback could be postponed indefinitely.Rather than patching the one effect, this fixes the defect class. The new
useStableActionsstill runs the factory every render (closures always capture the latest deps, identical to calling it bare), but returns a once-created delegating facade whose method identities never change. Publication to the facade happens inuseLayoutEffect, so only the latest committed render's actions are reachable — an interrupted or discarded concurrent render cannot leak its closures to event handlers, timers, or subscriptions. The settle timer now arms once by construction, and any future effect-dep or memoized-child consumer is safe by the same mechanism.createDelegatingActionsis pure and React-free so the behavior is testable through the repo'snode:testchain; source contracts pin the wiring at all 9 call sites and forbid the render-phase publication this design rejected.sessionRowActionHandlersRefmirror is removed — superseded by the facade. The fail-soft contract moves to the facade pattern with unchanged semantics (dedup registry, no fire-and-forgetvoid).createAppShellStopActiondeliberately stays unwrapped: it returns a bare function (no object to facade) and only feeds JSX props, never effect deps.Not TDD for the timer behavior itself — the repo has no React-rendering test harness; identity stability is pinned by unit + source contracts and the streaming journey by the existing E2E below.
Verification
tsc -p tsconfig.main.jsonandtsconfig.renderer.json— clean.node --test dist/main/**/*.test.js— 2650/2651. The one failure (menu-highlight-recipe-contract) fails identically on cleanmain; unrelated, not touched here.app-shell-stable-actions-contract.test.ts(7 tests — facade delegation/identity, constant key set under shape change, wiring, commit-time publication).npm run test:checks(console / a11y / copy) — clean;biome linton changed files — clean.e2e/send-message.spec.ts(fake-backend streaming journey through the settle path) — passes.Review focus
An external review round (Codex) flagged that the first iteration published
latestRef.currentduring render, which under concurrent React can expose closures from an uncommitted render. Fixed at the owner: publication moved touseLayoutEffect, render-phase writes limited to lazy initialization, and a source contract now forbids the rejected pattern. One known pre-existing instance of the old pattern remains atopenSessionInChatRef(single-function mirror, not a factory) — out of scope here, candidate for a follow-up sweep.