Skip to content

fix(pi): show input modals as waiting instead of working - #18836

Merged
nwparker merged 2 commits into
stablyai:mainfrom
mmarabel:gatsby74/pi-input-modal-status-fix
Sep 8, 2026
Merged

nwparker merged 2 commits into
stablyai:mainfrom
mmarabel:gatsby74/pi-input-modal-status-fix

Conversation

@mmarabel

@mmarabel mmarabel commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When Pi opens a dialog that needs an answer, Orca now shows the same orange waiting-for-input icon as Claude and Codex instead of looking busy. The icon stays until the dialog closes, then returns to working or done according to Pi's actual state.

What Changed

  • Observe Pi's real ui_prompt_start / ui_prompt_end events for select, confirm, input, editor, and custom dialogs, including extension tools such as ask_user.
  • Include the active-modal bit in every outgoing Pi snapshot so concurrent tool/completion events and latest-only transport coalescing cannot overwrite the wait.
  • Reuse the existing waiting state and orange question glyph. Clear stale tool/question-card details; do not publish dialog titles or answers.
  • Keep OMP's approval events, Prime, and legacy Pi question handling unchanged.
  • Add a real-Pi CDP smoke check and dialog extension; assert the terminal tab's actual Needs attention label separately from backend waiting.

Why

Pi already exposes this lifecycle (added in 0.84.4, earendil-works/pi#8355). The proposed tool_approval_requested integration is an OMP contract, not the signal emitted by real Pi dialogs. A tool-name whitelist also misses arbitrary extension modals; elapsed-time heuristics confuse long tools with input waits.

Linked Issue

Related: #15145

Related: #17236

This is a new implementation using Pi's shipped prompt events, not a continuation of the proposed approval-event branch. See the startup-dialog boundary in Notes before treating the broader issue as fully closed.

Visual Proof

No visual change to the existing indicator design; Pi now reaches the existing orange waiting state.

Linux Electron/CDP screenshots from the new end-to-end test: the same pane before and after delivering the modal-start hook. These show the real Orca UI; the test injects hook payloads rather than running an LLM. The separate runtime smoke check verifies that real Pi emits those hooks.

Before: working After: waiting for input
Working Waiting for input

Testing

Maintainer takeover verification on macOS, using the PR worktree:

  • Pi source inspected: local ~/projects/pi-mono 0.83.0, packages/coding-agent/src/core/extensions/runner.ts (no prompt lifecycle), and installed Pi 0.85.1, dist/core/extensions/runner.js:269–308 (five wrapped UI methods, outermost depth accounting, finally/error cleanup, microtask event emission).
  • 472 focused tests passed across 25 files: Pi extension/transport and hook normalization (298), status mapping/dashboard/interrupt consumers (174).
  • Real Pi runner: 31 scenarios / 92 snapshots passed, including active/idle close, answer/cancel/error, unrelated tool output, and overlapping dialogs.
  • Real Pi TUI → generated Orca extension → hook listener → rendered Orca: six flows passed through Playwright CDP in a folder workspace: selector answer and cancellation; confirm/input/editor/custom cancellation. Each asserts backend waiting and the orange Needs attention icon, then done and the green completion icon. Repeated after restarting Pi. No model response is needed for these dialog flows.
  • Electron E2E passed in a git worktree: ORCA_BACKGROUND_LAUNCH=1 pnpm test:e2e tests/e2e/pi-ui-prompt-status.spec.ts --workers=1. Its Electron and CLI builds passed. Covers working → waiting, unrelated output while waiting, close → working → done.
  • pnpm tc, changed-file oxlint, formatting, git diff --check, and pnpm run check:code-quality:changed passed (zero new native/type-aware/React Doctor findings).
  • The separate repository-wide typecheck:e2e has 195 diagnostics in other existing E2E files; none remain in this PR's test. The full unit suite and full lint suite were not rerun during takeover.

Reproduction: real-Pi verification instructions.

Real Pi visual proof (macOS)

These screenshots show actual Pi 0.85.1 dialogs in Orca, not injected hook payloads. The original Linux before/after evidence above remains for the working → waiting transition.

Dialog open: waiting / orange question Answered: done / green check
Real Pi waiting Real Pi done

Readiness review

PASS for the scoped change; zero unresolved P0/P1/P2 candidates. All eight checklist areas reviewed. Counsel skipped because no candidate findings remain. This is not a claim that every supported topology was exercised.

Area Evidence / result
SSH / network Execution-host extension retains existing authenticated transport; every coalesced snapshot carries the active-modal bit. Stalled/coalesced sender coverage passes. No liveness or disconnect verdict changed. Live SSH/network-failure testing remains unverified.
Crash / retry / growth Dedicated changed-code scan: one process-local boolean, no new queue, retries, timer, unchecked parse, or production cast. Real runner error/cancel/overlap and unmatched-end tests pass.
Security / supply chain No dependency, lockfile, binary, install hook, credential, or network-destination changes. Modal titles and answers are not forwarded; privacy assertion passes. New tools are opt-in verification scripts.
Performance Constant-size modal state; existing one-active/one-pending transport and timeout reused. No additional polling or subprocesses. Coalescing regression passes.
Functionality Pi source checked; actual five-kind TUI verification, runtime matrix, renderer consumers, and Electron E2E pass. Corrected the E2E's visible-label assertion. No provider-specific review logic changed.
Compatibility / data Existing waiting projection and optional hook fields; no schema, persistence, pairing, route, opcode, or migration changes. Mobile receives the existing normalized state; no new mobile-facing contract touched.
Platforms / remoting No production shell/path/native/keyboard changes; Pi-only guards retain OMP/Prime behavior. Git-worktree E2E and real folder-workspace checks pass on macOS. Live Windows, WSL, SSH, relay, and mobile checks remain unverified.
Organization Production logic stays in Pi and existing provider normalization modules. Opt-in runtime/CDP tools and reproduction instructions live together under tests/tools.

No change-specific release fix remains. Coverage limits: live active-model modal turn (active state covered by actual-runner smoke and injected-hook E2E), remote failure matrix, other operating systems, paired/mobile rendering, and full repository tests.

AI Disclosure

Original implementation assisted by OpenAI in Pi; maintainer takeover review, real-Pi validation, and test updates assisted by Codex.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Requires Pi's prompt lifecycle events (0.84.4+). Older Pi retains its existing status behavior; restart/reload Pi to pick up Orca's regenerated extension after updating.
  • Covers runtime ctx.ui dialogs, including arbitrary extension modals. Pre-runtime startup selectors (for example initial project trust before the extension runner exists) do not emit these events and remain an upstream observability boundary. This change does not infer their state or alter trust/approval policy.
  • Mobile/paired clients consume the existing normalized waiting state. Real cross-host validation remains a limitation, not a claimed pass.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Regular typechecks, Electron/CLI builds, changed-code quality, focused unit suites, and the E2E pass during takeover. The combined item stays unchecked because the full suite was not rerun and the separate E2E typecheck has unrelated baseline errors.

@coderabbitai

coderabbitai Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 7da3444d-7238-4cc1-b27b-3f81d067a84d

📥 Commits

Reviewing files that changed from the base of the PR and between 17799e4 and 5928d72.

📒 Files selected for processing (4)
  • tests/e2e/pi-ui-prompt-status.spec.ts
  • tests/tools/pi-ui-prompt-cdp-smoke.mjs
  • tests/tools/pi-ui-prompt-extension.mjs
  • tests/tools/pi-ui-prompt-verification.md

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


📝 Walkthrough

Walkthrough

The Pi status extension now tracks nested UI prompts and posts prompt lifecycle events. Active prompts add ui_prompt_active to status snapshots outside the OMP runtime. Agent-hook normalization maps active prompts to waiting and prompt completion to working or done. Modal events clear stale tool fields. Unit, end-to-end, and runtime smoke tests cover prompt types, outcomes, overlapping prompts, delivery behavior, and non-Pi runtimes.

Merge Risk: ⚪ Minimal · up to 5928d

Pi dialogs now show the existing action-required state while open and return to working or done when closed, with coverage for supported prompt types and modal outcomes. No concrete merge-blocking risk is identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 10 files. (1 skipped:… 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: Pi input modals now show the waiting state instead of the working state.
Description check ✅ Passed The description is detailed and covers the change, rationale, linked issues, visual proof, testing, limitations, AI disclosure, and checklist. It does not use the exact Fixes # format and leaves the…
Full details: Docstring Coverage

Explanation

Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 10 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI

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

  • Observe Pi's real modal lifecycle — a new generated handler (agent-status-ui-prompt-source.ts) listens to pi.on('ui_prompt_start'/'ui_prompt_end') and maps an open modal to the existing waiting state (orange question glyph), with ctx.isIdle() at close deciding done vs working.
  • Preserve the wait through coalescing — the generated post() tags every outgoing Pi snapshot with ui_prompt_active: true while a modal is open, so concurrent tool/completion events and latest-only transport coalescing can't overwrite waiting.
  • Normalizer plumbing — pi-family-events.ts forces waiting for ui_prompt_start/ui_prompt_active, maps ui_prompt_end through is_idle, and keeps a session-switching modal waiting; pi-family-tool-fields.ts clears stale tool/question fields on modal events.
  • Gating — OMP, prime-agent, and legacy Pi are all left unchanged (isOmpRuntime() guards + kind === 'pi' scoping + a runtime-routed-OMP test).
  • Tests — meaningful unit tests (coalescing, nested/overlapping prompts, session switch, unmatched end, process isolation), a CDP E2E, and a real-Pi ExtensionRunner smoke test; the smoke test is intentionally not in CI.

The implementation is correct and well-tested. The waiting state is already supported by the renderer for Pi (e.g. synthetic-agent-title maps it to "Pi - action required"), so no new wire opcode or renderer state is introduced, and the two documented residual limitations (manual-only runtime smoke check; reliance on Pi's outer lifecycle pair) are called out in the PR body rather than hidden.

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

@nwparker

nwparker commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Reviewing this one

@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

  • Fixed the E2E status-label assertion — the terminal tab renders waiting (and blocked) as the collapsed permission dot labeled Needs attention, not the dashboard's Waiting for input, so the spec now targets the correct label and additionally polls agentStatusByPaneKey[paneKey].state === 'waiting' to disambiguate from blocked, which collapses to the same dot.
  • Added real-Pi CDP verification tooling — a pi-ui-prompt-cdp-smoke.mjs script plus a pi-ui-prompt-extension.mjs (/orca-modal) drive all five real Pi dialogs through Electron CDP and assert backend waiting → done alongside the visible icon; pi-ui-prompt-verification.md documents the manual reproduction.

The delta is test/tooling only — no production code changed. The label fix is correct (verified via terminal-tab-activity-status.ts collapsing waiting/blocked → hasPermission → AgentStateDot permission → Needs attention), and the store poll correctly uses the store to reach the state while the final assertions prove it in the DOM. The new .mjs tools are intentionally not in CI and require a real Pi (≥ 0.84.4), matching the previously documented verification boundary.

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

@nwparker
nwparker merged commit a278d84 into stablyai:main Sep 8, 2026
1 check passed
nwparker added a commit that referenced this pull request Sep 8, 2026
* fix(pi): carry modal waits to mobile and stop losing the dialog close

Follow-ups to #18836, from its readiness review.

- Paint pi's `!` needs-input state marker while a dialog is open, so the
  80ms spinner frame stops repainting a working title over a mid-turn
  wait. Mobile and the CLI read the title, so they saw `working` where
  the desktop already showed `waiting`.
- Keep the assistant reply that lands while a dialog is open. The modal
  guard cleared tool fields and the `message_end` capture with them, so
  a turn ending under a dialog left the preview on the previous message.
- Report `ui_prompt_end` even when `ctx.isIdle()` throws on a runner the
  modal itself invalidated; the lost post stranded the pane on `waiting`.
- Declare the `esbuild` the runtime smoke tool imports.

* fix(pi): hold the needs-input marker until the dialog actually closes

From review of the previous commit.

- Settling under an open dialog no longer retires the marker. stopAnimation
  painted the plain title unconditionally, so agent_settled, a resolved
  agent_end, or an idle auto_compaction_end erased it mid-dialog — and
  because that also cleared the timer, the close then painted the plain
  title again and the wait was lost for good.
- Track the dialog as a boolean, not a depth counter. Pi does its own
  nesting accounting and emits one pair per stack, which is what the status
  extension already assumes; two files disagreeing on that would have let an
  inner close release the outer wait.
- Reset the flag on agent_start in both extensions. A turn cannot begin under
  a dialog holding input focus, so it is the one boundary that can recover a
  close that never arrived instead of pinning the pane forever.
- Leave OMP to its approval events: it reports waits through those already,
  and painting the marker there too would put title and hook in disagreement.

* fix(pi): do not ring the completion bell for a dialog that lost its close

From review of the previous commit.

- Report working, not done, when ui_prompt_end's isIdle() throws. done is
  not cosmetic: it reaches dispatchCompletion and fires the pane's finished
  notification, so a turn that is still running would announce itself. The
  real done still arrives from agent_end/agent_settled.
- Keep the idle-maintenance frame cap accruing while a dialog holds the
  title, so a dialog left open cannot suspend the guard that stops a
  compaction spinner whose end event never came.
- Guard the dialog handlers against a ctx without ui. The source is
  generated and untypechecked, and pi does not document the ctx it passes
  these two events; a TypeError there would surface on every dialog.

* fix(pi): let a turn still complete after a dialog loses its runner

From review of the previous commit.

- Re-arm the completion report when ui_prompt_end's isIdle() throws. The
  fallback posts working, but the finished turn had already reported its
  end, so nothing further would ever fire and an idle pane sat spinning.
- Count dialog depth in both extensions instead of trusting pi to emit one
  pair per stack. The guarantee is undocumented, and if it ever does emit a
  pair per dialog, an inner close would release the wait the outer dialog
  still holds. A counter costs nothing and drops the dependency.

* fix(pi): decide a dialog close from turn state, not from a guess

From review of the previous commit.

- Fall back to agentEndReported when ctx.isIdle is unavailable or throws.
  The previous guess of working stranded the common case — a dialog opened
  at idle — because no later event was coming to correct it, and the
  agentEndReported re-arm it relied on could not fire either. A turn that
  already reported its end is not still running, and that is knowledge this
  process holds without needing ctx at all.
- Only suppress spinner frames once the marker is actually painted. Pi may
  pass a ctx with no ui, and freezing the title on its last working frame
  is the opposite of what the marker is for.
- Gate the titlebar dialog handlers on the OMP runtime too, not just the
  installed kind: a bare-shell OMP launch runs inside a pi-kind pane, and
  the status extension already defers there. Extracted that check so both
  extensions share it rather than carrying two copies.

* fix(pi): treat a pane that never ran a turn as idle, not busy

From review of the previous commit.

- Track turn-in-flight separately from agentEndReported. That flag also
  dedupes the completion post, so it starts false on a pane that has not
  run a turn — which read as still-running and left a dialog opened before
  the first prompt spinning forever.
- Retry the marker paint on each dialog open instead of only the outermost,
  so an outer ctx without ui cannot decide the whole nested stack goes
  unmarked.
- Fall back to the opening ctx when the close carries no ui. Nothing else
  clears the needs-input marker, so the pane would have kept asking for
  attention until the next turn.

* fix(pi): keep a dying dialog ctx from stranding the needs-input marker

The close path paints through the ctx captured at open time, which is the
one a session-switching modal is most likely to have invalidated. Guard
both paint sites so a throw cannot reject the handler and leave the title
on the needs-input marker, and make local turn state the floor for the
status extension's idleness verdict instead of a fallback.

* fix(pi): hold the dialog wait against pi's own title writes and lost closes

Reviewed against real Pi 0.85.1 source rather than inference:

- ctx.ui is a getter that calls assertActive() and throws once a session-
  replacing dialog invalidates the runner, so optional chaining never
  screened it out and the probe sat outside the try. A throw landed after
  the depth decrement but before markerPainted cleared, stranding the
  needs-input marker until the next turn.
- Pi writes the same terminal title from its own writers with no event we
  observe, so the marker is now re-asserted rather than merely not
  overwritten, on a slow timer that outlives the spinner and its cap.
- resetExtensionUI drops an open dialog without resolving its promise, so
  a replaced or reloaded session never emits the matching ui_prompt_end.
  Both extensions now release the wait on session_start and shutdown.

* fix(pi): build the title inside the guard, not as an argument to it

paintTitle caught the setTitle throw but not the two calls one argument to
its left: pi.getSessionName() asserts runner liveness the same way ctx.ui
does, and process.cwd() throws ENOENT once the worktree is unlinked under a
live pane. Four of the six call sites are timer callbacks, where an escape
is an uncaught exception and pi exits(1) through its own handler — so the
cwd route was reachable today. paintTitle now takes a builder and runs it
inside the existing try.

* fix(pi): let only the pane-owning process assert the needs-input marker

The spinner is harmlessly per-process, but the marker is status the pane
reports, and child agents inherit ORCA_PANE_KEY. Gate the two dialog
handlers on a PID claim, mirroring ORCA_PI_STATUS_OWNED in the status hook.
@Jomik Jomik mentioned this pull request Sep 10, 2026
7 of 9 tasks
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.

2 participants