Skip to content

Fix serve-created mobile terminals on desktop - #4843

Merged
Jinwoo-H merged 3 commits into
mainfrom
Jinwoo-H/issue-4760-terminals-created-mobile
Jun 8, 2026
Merged

Jinwoo-H merged 3 commits into
mainfrom
Jinwoo-H/issue-4760-terminals-created-mobile

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Preserve headless/mobile-created serve-* terminal session tabs when an attached desktop renderer publishes its tab graph.
  • Hydrate persisted serve-owned terminal bindings even while a renderer is attached, so desktop/web clients can mirror them from session.tabs.
  • Materialize pending serve-owned terminals on activation instead of silently focusing a tab the renderer has never adopted.

Fixes #4760

Context

PR #4825 improved paired web session-tab mirroring, but it did not touch the host runtime path that was replacing/deleting headless serve-owned session snapshots. This fix keeps the host-created terminal visible in the authoritative session-tab snapshot so desktop clients can discover it.

Test plan

  • pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/orca-runtime.test.ts src/main/runtime/rpc/methods/session-tabs.test.ts src/main/runtime/rpc/methods/session-tabs-move-validation.test.ts
  • pnpm run typecheck:node
  • pnpm exec oxlint src/main/runtime/orca-runtime.ts src/main/runtime/orca-runtime.test.ts
  • git diff --check

Made with Orca 🐋

Summary by CodeRabbit

  • New Tests

    • Added end-to-end coverage for mobile headless terminal hydration and renderer attach/sync flows.
  • Bug Fixes

    • Fixed lost or duplicated mobile headless terminals during renderer syncs and attachments.
    • Ensured publication/merge handling is idempotent across repeated renderer updates.
  • Improvements

    • Preserves and restores owned headless mobile tabs across renderer updates; pending tabs become active using stored session identity without requiring manual focus.

@coderabbitai

coderabbitai Bot commented Jun 8, 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 00fe5382-b7c9-4b9c-8da4-4ab824e172d4

📥 Commits

Reviewing files that changed from the base of the PR and between d0debb4 and ab06221.

📒 Files selected for processing (1)
  • src/main/runtime/orca-runtime.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/runtime/orca-runtime.ts

Walkthrough

Adds conditional headless mobile-session hydration, serve-owned PTY filtering and identity-based merging, a predicate to materialize preserved headless tabs, and renderer-sync logic that preserves and merges serve-owned headless tabs; includes E2E tests covering preservation, split-sibling behavior, epoch idempotency, and in-attach hydration activation.

Changes

Serve-owned mobile terminal persistence

Layer / File(s) Summary
Headless terminal hydration foundation
src/main/runtime/orca-runtime.ts
hydrateHeadlessMobileSessionTabsFromWorkspaceSession gains force, allowAttachedWindow, and onlyServeOwnedTerminals options; skips rebuilding when snapshots already have tabs unless forced; filters hydrated tabs to serve-owned PTY bindings when requested; merges hydrated tabs/tab-groups with existing snapshot using identity de-duplication and reconciles active state.
Tab materialization predicate for headless terminals
src/main/runtime/orca-runtime.ts
Adds shouldMaterializeHeadlessMobileSessionTab and uses it in activateMobileSessionTab so pending headless tabs are materialized when the snapshot is headless/publication-derived or the tab is backed by a serve-owned PTY, even if a renderer focus notifier exists.
Renderer sync with preserved-headless merge
src/main/runtime/orca-runtime.ts
syncMobileSessionTabs runs a headless hydration pass (allowAttachedWindow: true, onlyServeOwnedTerminals: true), collects preserved headless tabs excluded from incoming snapshots, merges them into renderer-provided snapshots, computes a merged publicationEpoch signature from preserved identities, normalizes active/tab-group fields, and prunes worktree snapshots only when no preserved headless snapshot remains.
End-to-end hydration tests
src/main/runtime/orca-runtime.test.ts
Four E2E tests: headless mobile terminal persists and becomes ready when desktop publishes empty mobileSessionTabs; split-sibling headless terminals preserve both leaves and correct active selection; publicationEpoch merge is idempotent across repeated empty-syncs; persisted serve-owned terminal hydrates while renderer attached, activation uses stored sessionId, tab becomes ready, and focusTerminal is not invoked.
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR comprehensively addresses all key objectives from issue #4760: preserves serve-owned terminal tabs during renderer publishes, hydrates persisted bindings while renderer attached, materializes pending serve-owned tabs on activation, implements identity-based merging with de-duplication, and handles active tab selection correctly.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing serve-owned mobile terminal visibility and merging: test coverage for hydration/merging flows, hydration predicate logic, snapshot preservation during renderer syncs, and publication epoch handling for stable identifiers.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/runtime/orca-runtime.ts`:
- Around line 12570-12587: getMergedMobileSessionPublicationEpoch currently
appends ":headless-merge:<signature>" onto snapshot.publicationEpoch every call,
causing non-idempotent growth; change it to first normalize
snapshot.publicationEpoch by removing any existing trailing
":headless-merge:<...>" segment (e.g. via regex strip) before computing the new
signature and returning
`${normalizedPublicationEpoch}:headless-merge:${signature}` so repeated merges
are idempotent; update references in getMergedMobileSessionPublicationEpoch to
use normalizedPublicationEpoch instead of snapshot.publicationEpoch when
building the returned epoch.
- Around line 2246-2249: The terminal identity key currently returns [tab.id,
tab.parentTabId], which causes sibling split leaves to collide; in
getMobileSessionSnapshotTabIdentityKeys change the identity to include a
split-specific identifier instead of parentTabId (e.g., tab.splitLeafId or
tab.splitIndex) so each split leaf is unique—use [tab.id, tab.splitLeafId] when
splitLeafId exists, otherwise fall back to [tab.id]; update
RuntimeMobileSessionSnapshotTab usages to read the split identifier property.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 170ab79e-c74d-4fe3-abf1-367984e9f209

📥 Commits

Reviewing files that changed from the base of the PR and between 401fc1e and a8ca14f.

📒 Files selected for processing (2)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts

Comment thread src/main/runtime/orca-runtime.ts Resolved
Comment thread src/main/runtime/orca-runtime.ts Resolved

@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 — preserves headless-created serve-* terminal session tabs when a desktop renderer publishes its tab graph, and materializes pending serve-owned terminals on activation rather than silently focusing an unknown tab.

  • Preserve serve-owned tabs during syncMobileSessionTabs — hydrates serve-owned terminal bindings from the workspace session before processing the renderer snapshot, then merges preserved tabs into the incoming snapshot. When a worktree is absent from the renderer's snapshots, a preserved snapshot is built from surviving serve-owned terminals instead of deleting the entry.
  • Materialize pending serve-owned terminals on activation — activateMobileSessionTab now spawns the PTY for serve-owned terminals that the renderer has never adopted, instead of calling focusTerminal which would silently no-op.
  • New merge helpers — mergeMobileSessionSnapshotTabs, mergeMobileSessionTabGroups, mergePreservedHeadlessMobileSessionTabs, and buildPreservedHeadlessMobileSessionSnapshot handle deduplication, active-tab selection, and group merging with a deterministic publicationEpoch via SHA1.

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

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

Reviewed changes — addressed CodeRabbit feedback by fixing terminal identity-key collisions for split panes and making publication epoch merges idempotent.

  • Disambiguate terminal identity keys with leafId — getMobileSessionSnapshotTabIdentityKeys now includes leafId in the composite key for terminal tabs so split sibling panes don't collide during preservation dedup.
  • Normalize publication epoch before merge — getMergedMobileSessionPublicationEpoch strips any existing :headless-merge: suffix via split(':headless-merge:')[0] before computing the new signature, keeping repeated merges of the same preserved tabs idempotent.

✅ No new issues found.

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

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/runtime/orca-runtime.ts`:
- Around line 2246-2248: Add brief "why" comments inside
getMobileSessionSnapshotTabIdentityKeys explaining the merge invariants: note
that for terminal tabs we must keep split siblings leaf-scoped (so we return
[tab.id, `${tab.parentTabId}::${tab.leafId}`]) and document that any preserved
headless-merge passes must first normalize prior `:headless-merge:` suffixes
before recomputing epoch; place the comments adjacent to the existing
conditional and the identity key construction so future readers understand these
subtle constraints and won't "simplify" them away.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d1da51c7-4275-4e6d-9a68-c29a860f3246

📥 Commits

Reviewing files that changed from the base of the PR and between a8ca14f and d0debb4.

📒 Files selected for processing (2)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts

Comment thread src/main/runtime/orca-runtime.ts Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant