Repository navigation
fix(pi): retire stale spinner and prompt timers across reloads - #20035
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe Pi titlebar extension now manages pane ownership through a shared global registry and disposal state. It uses runtime event registration, clears owned timers during lifecycle changes and failures, and prevents animation after failed initial rendering. Tests cover stale sessions, reloads, shared globals, timer cleanup, and refreshed managed extensions. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The titlebar lifetime and timer-cleanup changes are covered without an identified merge-blocking risk. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This PR retires a stale Pi titlebar-extension instance's timers when its pane is replaced or its session context goes stale, so a retired instance can no longer repaint the title or keep its spinner, prompt-reassert, and idle-recheck timers alive.
- Per-pane ownership — a new
titlebar-extension-lifetime-source.tsemits aSymbol.for-keyedglobalThismap with one owner perORCA_PANE_KEY; a replacement factory retires the prior owner'sdispose()before registering. - Inert late handlers — a generated
on()wrapper guards everypi.onregistration with adisposedflag, so late events from a retired generation no-op. - Timer cancellation on stale paint —
paintTitleclears all owned timers when a paint fails, and a failed first frame no longer schedules the interval; the idle-recheck failure path clears animation too. session_startcleanup — clears owned timers even when shutdown was missed, while ordinary shutdown leaves the registration reusable across session switches.- Tests — regression coverage for stale getters/title writers, first-frame failure, all three timers, replacement generations, late events, pane isolation, recovery, and the
.omo/agentinstaller path. Verified:titlebar-extension-source.test.ts(47) andtitlebar-extension-service.test.ts(29) pass locally.
ℹ️ Inert pi.on listeners accumulate across reloads
The on() helper silences a retired generation's pi.on listeners via disposed but never unsubscribes them, so each replacement in a long-lived process leaves a full set of listeners attached to Pi's emitter. Functionally correct — each listener is a one-line early-return guard — but the listener list and per-dispatch work grow without bound across session switches.
Technical details
# Inert `pi.on` listeners accumulate across reloads
## Affected sites
- src/main/pi/titlebar-extension-lifetime-source.ts:23-27 — `on()` calls `pi.on(...)` and discards any unsubscribe handle; `dispose()` never removes the listener.
## Required outcome
- Optional. Confirm whether Pi's API exposes an `off`/unsubscribe; if it does, `dispose()` could hold and invoke it so reloads reclaim listeners rather than merely silencing them.
## Open questions for the human
- Is the extension factory actually re-invoked per session switch (vs once per process)? If reloads are rare in practice, this is a non-issue.DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

ELI5
A Pi extension can be replaced while its old spinner is still scheduled. Catching an expired-session exception prevents a crash, but does not stop the timer from retrying forever. This change cancels the old instance’s work and prevents its delayed events from interfering with the replacement.
What Changed
isIdle()check cancels animation as well as the idle check.session_start, even if shutdown was missed. Ordinary shutdown keeps the registration reusable for runtimes that retain the extension across session switches..omo/agentdirectory.Why
The original report used Orca
2265fce5912. Its unguarded title callback can throw from the raw interval and terminate Pi. Since then, #19533 (bba68b1bddf) added exception containment inpaintTitle; this PR is rebased on2ecde717b456and preserves that fix. The remaining defect is timer lifetime: failed callbacks returnfalsewhile the interval keeps running, and loading a replacement does not explicitly retire the prior instance.The intended invariant is: a retired instance owns no timers and cannot publish another title or restart work through a late event. The current instance must continue to animate and display needs-input correctly.
Linked Issue
Related: #14400 and #14658. These reports identify the shared stale-generation callback. This PR finishes lifecycle cleanup; it does not claim that current
mainstill reproduces their original uncaught exception. No issues have been closed automatically.Visual Proof
Live Pi spinner video — before and after
spinner-reload-2.webm
Watch the actual animated title bars above the two live Pi terminals:
ctx.reload()and the new generation starts animating.mainon the left keeps spinning; this PR on the right returns to an idle title. Both terminals remain live.This is the real Pi0.83 CLI running in isolated macOS PTYs, displayed through xterm. The title bars mirror Pi’s actual OSC title output; animation is generated by the production extension, not a video overlay. A model-free demo command invokes its start/settle handlers. Fault injection skips only the spinner’s shutdown callback during the real reload to exercise the missed-cleanup boundary. No model or credential is used. This is not an Orca app-window recording or a Windows/senpi test.
Three recorded repeats passed. Each verifies at least eight distinct spinner frames before and after reload, both processes remain live, and every captured frame in the final1.5seconds shows the fixed title idle while the baseline keeps spinning. Frame samples, fixture and generated sources: pi-live-proof.zip
Earlier source-runtime diagnostics and historical crash proof
Before/after screenshots render measured results from the real Pi source loader/runner. These are diagnostic evidence screenshots, not an interactive Orca/Pi TUI recording. They compare current
mainwith this PR under the same explicit invalidation-before-cleanup fault injection.pi-spinner-source-proof.zip
The bundle contains the proof script, pinned baseline generators, per-run JSON/logs, aggregate results, and independent source review. All 12 subprocess outcomes were checked; historical generator files were byte-compared with the pinned Git revisions. One branch-run log is rendered from its saved JSON; the other logs are captured stdout/stderr. The screenshots themselves are generated directly from the checked JSON measurements.
2265fce59122ecde717b456The real-source trace activates the spinner interval. Repository regression tests separately activate the spinner, prompt reassertion, and idle-recheck timers together and verify all three are canceled.
Testing
ORCA_BACKGROUND_LAUNCH=1 pnpm test src/main/pi/titlebar-extension-source.test.ts src/main/pi/titlebar-extension-service.test.ts src/main/pi/titlebar-extension-overlay-path.test.ts --maxWorkers 2— 78 tests passed.ORCA_BACKGROUND_LAUNCH=1 pnpm tc:node— passed. Changed-file oxlint, formatting, andgit diff --checkpassed; commit hooks also ran the React doctor lint configuration. Full application build and full repository suites were not run locally.Mandatory independent source verification completed:
~/projects/pi-mono, commite77e2b751cbd28313073ed2de43d4b3294c73dcd.~/projects/oh-my-pi, commit969a94c1eeccb1b7528cd5621934bca1908ab622.core/extensions/loader.ts:178–208,333–335guards captured APIs;runner.ts:543–550,673–745invalidates the runner/runtime and guardsui/isIdle.core/agent-session-runtime.ts:170–223andcore/agent-session.ts:2607–2627show graceful shutdown before invalidation. Fault injection therefore tests the reported stale boundary; it is not presented as a full normal-transition crash on today's Pi.To reproduce locally after extracting the evidence bundle into this checkout:
ORCA_BACKGROUND_LAUNCH=1 ~/projects/pi-mono/node_modules/.bin/tsx \ docs/bug-root-causes/evidence/pi-loader-proof-run.mts branch 1Repeat with
main,original, andcontrol, and runs1through3. Theoriginalvariant intentionally exits 1. The source-only proof imports the local Pi checkout by absolute path; adjust those imports if your checkout is elsewhere. It uses a real in-memory Pi session manager and real runtime liveness guards; the UI title sink collects strings, and no model registry operation is invoked.Review
The independent source review was explicitly performed against the user's local
~/projects/pi-monoand~/projects/oh-my-picheckouts. See proof scope and pinned revisions below. It confirmed that reload factories share a process realm, Pi's stale API guards throw, and OMP may retain its extension registration through a session switch; permanent disposal is therefore limited to replacement ownership, not ordinary shutdown.Agent skill upstream boundary
Notes
.omo/agentinstaller coverage uses an explicitly selected temporary directory; it does not establish automatic omo discovery or an installed Windows build.Checklist