Skip to content

fix(pi): retire stale spinner and prompt timers across reloads - #20035

Merged
nwparker merged 2 commits into
mainfrom
nwparker/bug-consolidation-thinking-bug-thinking
Sep 11, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/bug-consolidation-thinking-bug-thinking

Conversation

@nwparker

@nwparker nwparker commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​159 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​158
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​63 $\color{#cf222e}{\Huge{\mathbf{−}}}$​28 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​35

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

  • Assign each pane one titlebar-extension owner within the agent process. Loading a replacement cancels the previous owner’s spinner, prompt-marker reassertion interval, and pending idle check; its later lifecycle handlers become inert.
  • Reuse the existing guarded title painter. A failed paint cancels all owned timers; a failed initial frame cannot schedule another interval. A failed isIdle() check cancels animation as well as the idle check.
  • Clear old timer work at session_start, even if shutdown was missed. Ordinary shutdown keeps the registration reusable for runtimes that retain the extension across session switches.
  • Preserve the newer Pi needs-input marker behavior, OMP-specific handling, idle-compaction cap, settlement rules, and safe replacement of Orca-managed extension files.
  • Add regression coverage for stale getters/title writers, first-frame failure, all three timers, replacement generations, late events, pane isolation, recovery, and installation into an explicitly selected .omo/agent directory.

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 in paintTitle; this PR is rebased on 2ecde717b456 and preserves that fix. The remaining defect is timer lifetime: failed callbacks return false while 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 main still 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:

  • 0–3 seconds: both production spinners animate.
  • Reload: the demo invokes Pi’s real ctx.reload() and the new generation starts animating.
  • After settlement (~8 seconds): current main on 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 main with this PR under the same explicit invalidation-before-cleanup fault injection.

Before: current main retains the interval After: this PR retires it
pi-spinner-before.png pi-spinner-after.png

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.

Scenario Runs Process result Extension interval after boundary
Original report revision 2265fce5912 3 Uncaught real Pi stale-context exception, exit 1 1 at exit
Current main 2ecde717b456 3 Exception contained, exit 0 1 still active
This PR 3 Exception contained, exit 0 0
Normal shutdown → invalidation → new factory 3 Replacement produces ≥3 fresh titles, exit 0 0 after final shutdown

The 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

  • Automated regression tests added/updated.
  • Actual Pi source loader/runner exercised independently by a sub-agent.
  • Actual Pi CLI TUI recorded through real reload in isolated macOS PTYs, with three passing frame-checked repeats.
  • Full Orca app window and affected Windows/senpi installation exercised.

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, and git diff --check passed; 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:

  • Pi 0.83.0: ~/projects/pi-mono, commit e77e2b751cbd28313073ed2de43d4b3294c73dcd.
  • OMP 18.0.4: ~/projects/oh-my-pi, commit 969a94c1eeccb1b7528cd5621934bca1908ab622.
  • Pi core/extensions/loader.ts:178–208,333–335 guards captured APIs; runner.ts:543–550,673–745 invalidates the runner/runtime and guards ui/isIdle.
  • Pi core/agent-session-runtime.ts:170–223 and core/agent-session.ts:2607–2627 show 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.
  • OMP's loader and legacy compatibility imports share the process realm; ordinary session switching preserves listeners. The independent review found no blocker in the final owner/cleanup design.

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 1

Repeat with main, original, and control, and runs 1 through 3. The original variant 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-mono and ~/projects/oh-my-pi checkouts. 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

  • Not applicable. No upstream skill source or registry data is copied.

Notes

  • Runtime-local only: no RPC fields, stream opcodes, process verdicts, credentials, or SSH fallback behavior change. Remote hosts must receive the updated managed extension through their normal installation path.
  • Pane ownership is scoped to the agent process; separate processes do not share the registry. Cross-platform code uses no OS-specific path literals.
  • Folder workspaces use the same title generator. Deleted-cwd failures remain contained and now retire timer work.
  • .omo/agent installer coverage uses an explicitly selected temporary directory; it does not establish automatic omo discovery or an installed Windows build.
  • No model calls, credentials, or user agent sessions were used in proof runs. No visible desktop window was activated. Live Pi CLI proof uses hidden browser terminals, which were closed along with the proof server and all owned PTYs after recording.

Checklist

  • Small, focused lifecycle change.
  • ELI5, cause, scope and existing upstream fix explained.
  • Before/after measured proof and raw evidence attached.
  • Self-reviewed for correctness, security, and performance.
  • Platform, SSH/remote, folder-workspace, and compatibility impact considered.
  • Full lint/typecheck/test/build matrix passes — targeted checks passed locally; CI covers the remaining matrix.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: d0aaed25-0ffe-4e12-90c5-0f0db55989d7

📥 Commits

Reviewing files that changed from the base of the PR and between 2ecde71 and 1610dbe.

📒 Files selected for processing (4)
  • src/main/pi/titlebar-extension-lifetime-source.ts
  • src/main/pi/titlebar-extension-service.test.ts
  • src/main/pi/titlebar-extension-source.test.ts
  • src/main/pi/titlebar-extension-source.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The 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 1610d

The titlebar lifetime and timer-cleanup changes are covered without an identified merge-blocking risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the main change: retiring stale Pi spinner and prompt timers across reloads.
Description check ✅ Passed The description is complete and focused. It explains the problem, changes, rationale, linked issues, visual proof, testing, review scope, compatibility considerations, and checklist status. It also cl…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ 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.ts emits a Symbol.for-keyed globalThis map with one owner per ORCA_PANE_KEY; a replacement factory retires the prior owner's dispose() before registering.
  • Inert late handlers — a generated on() wrapper guards every pi.on registration with a disposed flag, so late events from a retired generation no-op.
  • Timer cancellation on stale paint — paintTitle clears 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_start cleanup — 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/agent installer path. Verified: titlebar-extension-source.test.ts (47) and titlebar-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.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

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.

1 participant