Skip to content

fix(agents): keep Pi status through session_shutdown; open browser in Agents View - #7838

Closed
bbingz wants to merge 4 commits into
stablyai:mainfrom
bbingz:fix/7791-7813-pi-status-agents-browser
Closed

bbingz wants to merge 4 commits into
stablyai:mainfrom
bbingz:fix/7791-7813-pi-status-agents-browser

Conversation

@bbingz

@bbingz bbingz commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • [Bug]: Orca keeps disconnecting from running Pi agents #7791: Pi/OMP hook normalization no longer maps session_shutdown to done (only agent_end does). This prevents mid-work status drop / “disconnect” UI while the PTY is still running; Pi can emit session_shutdown on internal session boundaries during long work.
  • [Bug] Orca Browser not opening from Agent View #7813: HTTP links opened from Agents View (activeView === 'activity') create browser tabs on the floating workspace and request the floating panel open. Pure open/force-close policy allows the panel to show when floating tabs exist even if floatingTerminalEnabled is off. App handles the open event with live store reads so open=true after tab creation.

Root causes (brief)

Issue Cause Fix
#7791 normalizePiCompatibleEvent treated session_shutdown like agent_end → done Only agent_end → done; shutdown returns null
#7813 Main browser chrome is terminal-view-only; activity links created tabs that were not visible without leaving the view Floating target + requestOpenFloatingTerminal + open/force policy

Screenshots

No UI chrome redesign. Behavior change: browser overlay usable while staying in Agents View; Pi status stays working across session_shutdown.

Testing

  • pnpm run typecheck:node (clean)
  • oxlint on changed files (0 errors)
  • Focused unit tests (246 passed):
    • src/main/agent-hooks/server.test.ts — session_shutdown does not map to done (#7791)
    • src/renderer/src/lib/http-link-routing.test.ts — activity routes to floating + requestOpenFloatingTerminal
    • src/renderer/src/lib/floating-terminal.test.ts — open/force-close policy table (incl. enabled=false, count>0)

AI Review Report

  • [Bug]: Orca keeps disconnecting from running Pi agents #7791: Decision point is shared normalize path (local HTTP + relay ingest). Confirmed other agents use different terminal events; Pi titlebar animation still stops on shutdown (cosmetic only). Risk: if any flow relied on shutdown-as-done without agent_end, status may stay working until end/PTY teardown — matches reported symptom.
  • [Bug] Orca Browser not opening from Agent View #7813: Two-hop chain (routing creates floating tab + dispatches open; App sets open via policy). Live getState() in open handler avoids stale count after createBrowserTab. Main terminal chrome gates unchanged; floating is the within-activity surface. Does not enable floating feature for unrelated empty opens when pref is off and count is 0.
  • Cross-platform: no OS-specific paths/shortcuts. SSH/remote: openLinksInApp + remote runtime still force system browser as before.
  • No secrets/IPC surface changes beyond existing store accessors and custom events.

Security Audit

  • No new network endpoints, auth, or command execution.
  • Custom event is same-origin renderer only (orca-open-floating-terminal).
  • Link routing still respects openLinksInApp, remote runtime, and forceSystemBrowser.
  • Risk: low. Policy can surface floating panel when activity created tabs while pref is off; intentional for Agents View browser availability.

Notes

Fixes #7791
Fixes #7813

@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change updates floating-terminal opening and force-close policies, adds event-driven overlay opening, and routes activity-view HTTP links to floating terminal tabs without changing the active worktree. Main-surface resolution now controls activity, landing, and creation rendering. Tests cover floating-terminal policies, activity-view link routing, and activity surface resolution. PI hook normalization now ignores session_shutdown instead of mapping it to done.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title concisely captures both main changes: Pi status handling and Agents View floating-browser behavior.
Description check ✅ Passed The description includes all required sections and gives sufficient summary, testing, review, security, and notes details.
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.

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/renderer/src/lib/floating-terminal.ts (1)

36-60: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Derive shouldForceCloseFloatingTerminal from shouldOpenFloatingTerminalOnRequest to avoid divergence.

The two predicates are exact logical negations of each other (!enabled && count===0 ≡ !(enabled || count>0)). Keeping them as independently-written booleans risks one being tweaked later without updating the other, silently breaking the open/close policy contract.

♻️ Proposed refactor
 export function shouldOpenFloatingTerminalOnRequest({
   enabled,
   visibleTabCount
 }: {
   enabled: boolean
   visibleTabCount: number
 }): boolean {
   return enabled || visibleTabCount > 0
 }

 export function shouldForceCloseFloatingTerminal({
   enabled,
   visibleTabCount
 }: {
   enabled: boolean
   visibleTabCount: number
 }): boolean {
-  return !enabled && visibleTabCount === 0
+  return !shouldOpenFloatingTerminalOnRequest({ enabled, visibleTabCount })
 }
src/renderer/src/App.tsx (1)

610-629: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Drop floatingVisibleTabCount from this effect's dependency array.

Neither toggleFloatingTerminal (only reads floatingTerminalEnabled) nor openFloatingTerminal (intentionally reads live store state, per the comment) closes over floatingVisibleTabCount. Keeping it in the deps array causes the listeners to be removed and re-added on every floating-tab count change for no functional benefit.

⚡ Proposed fix
-  }, [floatingTerminalEnabled, floatingVisibleTabCount, setFloatingTerminalOpenWithFocus])
+  }, [floatingTerminalEnabled, setFloatingTerminalOpenWithFocus])
src/renderer/src/lib/http-link-routing.ts (1)

24-24: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use the store’s activeView union here.
src/renderer/src/lib/http-link-routing.ts:24 should use UISlice['activeView'] (or AppState['activeView']) instead of string so the 'activity' check stays type-safe.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a0c045b3-14cb-49f9-976a-afca94da1e3b

📥 Commits

Reviewing files that changed from the base of the PR and between e218bf8 and c6cdf10e5fdc20dd305c0bf5a3263a1950489b80.

📒 Files selected for processing (7)
  • src/main/agent-hooks/server.test.ts
  • src/renderer/src/App.tsx
  • src/renderer/src/lib/floating-terminal.test.ts
  • src/renderer/src/lib/floating-terminal.ts
  • src/renderer/src/lib/http-link-routing.test.ts
  • src/renderer/src/lib/http-link-routing.ts
  • src/shared/agent-hook-listener.ts

Comment thread src/renderer/src/App.tsx Resolved
@AmethystLiang AmethystLiang self-assigned this Jul 8, 2026
bbingz and others added 4 commits July 10, 2026 18:06
… Agents View

stablyai#7791: Pi/OMP normalize no longer maps session_shutdown to done (only agent_end).
Prevents mid-work status drop while the PTY is still running.

stablyai#7813: From Agents View (activity), http links create floating browser tabs and
request the floating panel open. Pure open/force-close policy allows visibility
when tabs exist even if floatingTerminalEnabled is off. App listens for open
with live store reads.

Tests: normalize session_shutdown null; activity routing + requestOpen spy;
policy table for enabled/count cases.

Fixes stablyai#7791
Fixes stablyai#7813
CodeRabbit on stablyai#7838: ActivityPrototypePage could mount alongside
WorktreeCreationPanel or Landing when activeView is activity. Gate it on
activeWorktreeId and !creationLayoutActive so those surfaces own the slot.
@bbingz
bbingz force-pushed the fix/7791-7813-pi-status-agents-browser branch from 5f5470b to 6035f52 Compare July 10, 2026 10:13
@bbingz

bbingz commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@bbingz

bbingz commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/renderer/src/app-main-surface.test.ts (1)

1-14: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for the remaining branches of resolveMainSurface.

Only the "activity, no worktree" case is tested. resolveMainSurface has 4 branches (creation-wins-over-terminal, creation-wins-over-activity, landing, and the null fallback), and this exact function is what fixed a previously-reported bug (activity page rendering alongside the creation/landing fallback). Given its importance to preventing surface-overlap regressions, it's worth locking down each branch with a test case.

✅ Suggested additional test cases
 describe('resolveMainSurface', () => {
   it('keeps activity available without an active worktree', () => {
     expect(
       resolveMainSurface({
         activeView: 'activity',
         activeWorktreeId: null,
         creationLayoutActive: false
       })
     ).toBe('activity')
   })
+
+  it('prefers creation over activity when creation layout is active', () => {
+    expect(
+      resolveMainSurface({
+        activeView: 'activity',
+        activeWorktreeId: null,
+        creationLayoutActive: true
+      })
+    ).toBe('creation')
+  })
+
+  it('prefers creation over terminal when creation layout is active', () => {
+    expect(
+      resolveMainSurface({
+        activeView: 'terminal',
+        activeWorktreeId: null,
+        creationLayoutActive: true
+      })
+    ).toBe('creation')
+  })
+
+  it('resolves landing when terminal view has no active worktree', () => {
+    expect(
+      resolveMainSurface({
+        activeView: 'terminal',
+        activeWorktreeId: null,
+        creationLayoutActive: false
+      })
+    ).toBe('landing')
+  })
+
+  it('returns null for terminal view with an active worktree', () => {
+    expect(
+      resolveMainSurface({
+        activeView: 'terminal',
+        activeWorktreeId: 'wt-1',
+        creationLayoutActive: false
+      })
+    ).toBe(null)
+  })
 })

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0ea7df70-b5d9-487d-bfa8-3107c24a8f94

📥 Commits

Reviewing files that changed from the base of the PR and between c5669cc and ba2ad6f.

📒 Files selected for processing (9)
  • src/main/agent-hooks/server.test.ts
  • src/renderer/src/App.tsx
  • src/renderer/src/app-main-surface.test.ts
  • src/renderer/src/app-main-surface.ts
  • src/renderer/src/lib/floating-terminal.test.ts
  • src/renderer/src/lib/floating-terminal.ts
  • src/renderer/src/lib/http-link-routing.test.ts
  • src/renderer/src/lib/http-link-routing.ts
  • src/shared/agent-hook-listener.ts

@bbingz

bbingz commented Jul 11, 2026

Copy link
Copy Markdown
Contributor Author

@Jinwoo-H When you have capacity, could you review this focused Pi status / Agents View routing PR? Its current head is mergeable and CodeRabbit is green.

@AmethystLiang

Copy link
Copy Markdown
Contributor

reviewing it now

@AmethystLiang

Copy link
Copy Markdown
Contributor

Correction: closing this PR because its #7791 portion is superseded by merged PR #8355 and the remaining #7813 browser change should be submitted as a focused PR rather than keeping this mixed PR open. #7813 remains open and tracked.

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.

[Bug] Orca Browser not opening from Agent View [Bug]: Orca keeps disconnecting from running Pi agents

2 participants