Repository navigation
fix(mobile): open Markdown, file and diff tabs on hosts with no desktop window - #25436
brennanb2025 wants to merge 28 commits into
Conversation
…detection with main A host with no desktop window has to name, label and project editor tabs exactly as the window does. Move the window's owned/diff editor file id rules, the Markdown/file tab projection, the Markdown read-only rules and language detection (with the Monaco filename map) into src/shared; the renderer modules re-export or call them, so window behaviour is unchanged.
When a desktop window's promotion times out or fails, the host takes the
editor tabs back while that window's document may still be alive with an
older session read. Track window documents by webContents id and committed
main-frame generation; every host editor commit marks live documents
obsolete. An obsolete document's graph is refused (with one reload) and
its session set/patch/set-sync/checkpoint writes are not staged: only its
unsaved drafts are merged onto matching current rows, and a checkpoint
whose draft row is gone answers { ok: false } so unload keeps the text.
Senders that saw no host commit are admitted exactly as before.
…ith no window On a serve host (or a desktop with no window) the phone could not open a file, Markdown or diff tab: every editor RPC needed the window and failed with renderer_unavailable. Editor authority is now derived on every call: the window while an authoritative window with the editor methods exists, otherwise the host. The host writes edit tabs into the workspace session in the window's own formats (one session write per operation, re-checking authority right before the commit), keeps diff tabs in memory, overlays both onto the headless snapshot, and refuses to close a tab holding unsaved drafts. An open that crosses a window attach fails with a retryable error instead of writing. Host diffs need a Git target, so a plain folder gets a clear refusal. Advertised as session-tabs.host-editor-tabs.v1.
markdown.readTab and markdown.saveTab also needed the window. With host editor authority the host answers them from its session rows: a bounded 2 MiB UTF-8-safe read (SSH: whole file up to 2 MiB, ranged reads above, a plain refusal on relays without them), version = hash of the returned content, and oversized, truncated, read-only, draft or outside-workspace rows are not editable. A save captures the execution host and SSH generation before any await, runs in a per-file lane, compares the current hash, re-checks ownership right before the write through a new optional beforeWrite hook, and verifies the result. Includes a contract test that the host's rows and replies decode with what released phones read.
…t open tabs An older host with no desktop window refuses editor tabs with renderer_unavailable. The phone now recognises exactly that refusal: a Changes tap opens the device review, a file tap the device preview, and Open in Session explains "Update Orca on this computer to open this as a tab." on each try without latching it off. Markdown Note checks this tap's own status read: a host advertising host editor tabs creates the note; a known window-less host without it gets one toast and nothing is created; an unknown status makes the legacy attempt and, if refused after creating the file, opens it in the device preview. desktopWindowStatus is an optional validated field. Three RPC goldens re-recorded for the copy change. Co-authored-by: Meapri <[email protected]>
…ting instead of fencing its document The host took editor tabs back whenever no window was authoritative, including while a promoted window's hand-over had timed out or failed and its document was still alive. That document could later persist the session it read, so a fence marked it obsolete, refused its graph, forced a reload and dropped its session writes, which could leave a live window silently disconnected. Editor authority is now three-valued and derived per call: 'window' when an authoritative window owns editors, 'host' when no live window document exists (no window registered, or its renderer crashed or was destroyed), and 'unavailable' when a registered window is alive but not authoritative. In that last state editor opens, diffs, Markdown reads and saves, and editor close, activate and move refuse with a retryable "still starting" error and nothing is written; the late graph attaches as before and the window takes over. With no host commit possible under a live document, the fence and its session-write, checkpoint and graph-refusal plumbing are removed.
…and keep diff focus live-only On a desktop whose window was closed, the phone saw the session's terminals in a synthetic group and its editors in the window's group, a split the desktop never had; a phone reorder then wrote that split into the session and the reopened window restored it. When the session is unified, every tab (terminals, browsers, editors, live diffs) is now placed through the window's persisted groups and layout, so the phone's groups are the session's groups. Legacy sessions and worktrees with no editor tabs keep today's projection, and persisting a layout never writes the synthetic group into a unified session. A focused diff was persisted as the worktree's active editor file and group focus, outliving the diff and leaving the phone with no active tab after it closed. Diff focus now lives only in the snapshot (with the tab it replaced), a persisted layout leaves diff ids out, and closing a diff returns to that tab. When the focused tab is gone, the published active tab falls back to the group's most recent tab, terminals included, instead of none.
A host-created editor wrapper took sortOrder = tabOrder.length, so a gap left by an earlier close could give two wrappers one sortOrder; the host now appends to the deduped order and renumbers siblings, as the window does for an unpinned, unanchored open. An explicit open of a row restored as a preview now clears the preview flag on the row and its wrapper, so a window restore cannot replace the tab the user opened. A read-only row's leftover draft, which no surface shows, no longer makes its tab impossible to close from the phone.
…ssion partition The phone's full tab list hydrates against the local session partition, but it also visited every workspace with a live host diff. For an SSH workspace, whose rows live in the SSH partition, that reconcile found no edit rows and dropped its Markdown and file tabs, so they vanished from the full list while a diff was open and came back in the per-workspace list. Workspaces with live diffs or editor-only rows outside the local partition are now hydrated through their own scoped hydrate. The test store now answers a missing host id with the local partition, as production does, so this cannot be masked again.
… that landed With no window, a Markdown tab whose file sits outside the workspace (opened from a terminal link, on another SSH target, or under another root) was listed to the phone, but every read of it was refused, so tapping it showed "Couldn't load markdown" with a Retry that could never work. The host now lists only rows a phone may read, as a host with no window did before; the rows stay in the session for the window. The same rule applies to non-Markdown file rows. A save re-checked tab ownership after the write, so closing the tab while the bytes were landing reported a failed save for text that was on disk; the write is fenced by its pre-write check and the verify read is the post-condition. An SSH relay without ranged reads now answers the too-large code phones already explain instead of an English sentence they show as a generic failure.
…t open as a tab Markdown Note creates untitled.md and then asks the host to open it. When that open failed for any reason other than the host having no editor window (for example a desktop window that is still starting, or a dropped connection), the phone showed the error and left the created file invisible; tapping again made untitled-2.md. The phone now opens the note it just created in the device preview and shows the reason once as a toast, so the user has the note and no stray file. The host's new "still starting" refusal is pinned as not matching the exact renderer_unavailable fallback predicate.
…t of the projection The projection grew past the file-size limit with the unified group placement and the active-tab fallback; each now lives in its own module. The tab-state owner is typed as an editor-authority host instead of a bare object.
…ktop window closed A closed window leaves the terminal graph unavailable for good, and the close path asserted a ready graph for every paired-client close before it knew which tab was addressed. Host-owned Markdown, file and diff closes never touch the graph, so they no longer wait on it; terminal and other graph-backed closes still refuse as before.
…e the way the window does The host compared paths with only separators folded, so on Windows a row opened from a terminal link with other letter case (or under a root stored with a lowercase drive) was hidden from the phone while the window listed it. Compare with the shared runtime path key instead, which folds case for Windows drive and UNC roots only and treats a backslash on a POSIX root as a filename character.
…thout asking them to tap Note again When the computer could not open a just-created note as a tab, the phone showed the note and repeated the host's reason, which for a window that is still starting ends in "Try again". The only way to try again is another Note tap, which creates untitled-2.md and leaves the first note behind. Say what happened instead: the note is open on this phone and the computer could not open it as a tab.
…preview The content-create recording mounted the hook without the router and host id the screen always passes, so a Note whose tab open failed crashed on the preview navigation and the golden recorded that crash as the error. Inject both, and re-record the one affected golden: each failure now shows the created note on the device and one Note message, with no inline error.
Editor file ids depend on every row in the partition, and each hydrate pass asked for them once per worktree, so a pass cost O(worktrees x rows): about 110 ms at 100 workspaces x 20 rows and 1 s at 200 x 30. Assign them once per openFilesByWorktree object and index by worktree (4 ms and 8 ms). The cache re-derives when a worktree's row array or length changes, since a worktree rename re-keys the stored map in place.
…b list after its window closes The unscoped hydrate reconciles editor tabs against the local partition only, and its second pass covered just worktrees with live diffs or no snapshot. An SSH workspace whose closed window had last published editor tabs kept those stale tabs in the full list (and lost its own Markdown tab there) while its own list was right. Reconcile every workspace whose snapshot holds editor tabs or whose own partition has edit rows against that partition.
…isted groups With the desktop window closed, a remote client's reorder, split or move in a workspace with a host editor tab wrote the headless snapshot's groups back as the whole group model. The snapshot shows only what the host can render, so a group holding an agent chat, a closed browser page or a hidden editor row disappeared, and the window reopened without its split. It also stored snapshot-only ids such as agent-session:<id> in tab orders. A move now edits the unified session's persisted groups: visible tabs take the order and group the move gave them, every member the snapshot could not show keeps its group and neighbour, a group goes only when it is truly empty, and the persisted layout is kept with a new split grafted beside the group it came from. Snapshot ids are translated to wrapper ids for terminals, browsers, chats and editors (both when projecting and when persisting), and every member's sortOrder follows its group order. A session that already holds the synthetic headless terminal group from an earlier terminal split is edited like any other, so an editor moved out of it lands where clients see it; the guard that refused those writes is gone. The host still never adds that group to a unified session, and terminal-only worktrees keep origin/main's behaviour.
…t editor close The graph check for a paired client's close now lives in one helper next to closeHostEditorTab: it skips the terminal graph for a host-owned editor close while the window is closed, and otherwise captures the ready graph and asserts it stayed stable, exactly as before. This keeps the close mixin within its line limit.
…tes it A phone activating an agent chat tab fell into the editor branch, so with host-owned editors it ran the host editor activation, which threw workspace_session_unavailable instead of focusing the chat. Chat tabs are renderer-owned unified tabs like browser tabs and now take that path. Recording an editor tab's focus is bookkeeping, so a host with no owned session partition still completes the activation instead of throwing.
…a remote move edits the groups With the window closed, a chat replaced by /clear kept a wrapper naming the session it replaced, so the host could not translate the new chat's id. A remote move of that chat was dropped from the saved groups, and a rebuilt snapshot placed it in the active group. Fall back to the replaced session's wrapper, as the window's own mirror does.
…a group the session cannot keep With the window closed, splitting a diff into its own group showed the new group once, then the next list folded the diff back, because diffs are never saved and the saved groups had nowhere to hold that group. The host now refuses that split as a no-op, the same way it treats a drop the window cannot split. Legacy sessions are unchanged. The move persistence moves out of the editor command module to keep it under the line limit.
…2025/mobile-serve-render-8165 # Conflicts: # src/renderer/src/lib/language-detect.ts
…s the window route does
📝 WalkthroughWalkthroughThe runtime can own file and Markdown editor tabs when no desktop window owns them. It publishes those tabs to mobile session snapshots and persists editor groups, focus, and Markdown changes. Shared modules provide editor identity, language detection, and tab projections. Mobile flows handle renderer-unavailable responses with device previews or host-update messages. Monaco language-association files and related configuration now use the shared directory. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to Phones can now open file, Markdown, and diff tabs on hosts without a desktop window. Two small issues remain. Stored phone snapshots can still point to a removed diff tab after a desktop window takes over. One host check on Markdown saves is skipped for older tab records. Neither issue is likely to cause serious failures, but both should be fixed in a follow-up. 🚥 Pre-merge checks | ✅ 3 | ❌ 1 | ❓ 1❌ Failed checks (1 warning, 1 inconclusive)✅ Passed checks (3 passed)Full details: Out of Scope Changes checkExplanation The PR also adds unrelated mobile chat work. Full details: Docstring CoverageExplanation Docstring coverage is 39.84% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 128 functions across 50 files. (33 skipped: 5 unsupported, 28 over the file limit.)
✨ 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.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
90a0de18-a596-4caa-aa10-43fa5b2f0a07
📒 Files selected for processing (85)
config/scripts/generate-monaco-associations.mjsconfig/tsconfig.cli.jsonmobile/rpc-foundation/goldens/matrix-session.content-create-files.open-1.jsonmobile/rpc-foundation/goldens/matrix-session.markdown-disk-fallback-files.read-1.jsonmobile/rpc-foundation/goldens/session-markdown-disk-read.jsonmobile/rpc-foundation/goldens/session-markdown-tab-disk-fallback.jsonmobile/src/files/mobile-file-mutation-ownership.tsmobile/src/session/host-editor-tab-release-contract.test.tsmobile/src/session/markdown-note-host-editor-tabs.tsmobile/src/session/mobile-file-tap-open.test.tsmobile/src/session/mobile-file-tap-open.tsmobile/src/session/mobile-markdown-disk-fallback.test.tsmobile/src/session/mobile-markdown-disk-fallback.tsmobile/src/session/use-mobile-diff-review-interactions.tsmobile/src/session/use-mobile-diff-review-open-in-session.test.tsmobile/src/session/use-mobile-session-content-create-actions.tsmobile/src/session/use-mobile-session-content-create-markdown-note.test.tsmobile/src/source-control/session-changed-file-open.test.tsmobile/src/source-control/session-changed-file-open.tsmobile/src/source-control/use-mobile-source-control-openers.tsmobile/src/tasks/task-runtime-reply-schema.test.tsmobile/src/tasks/task-runtime-reply-schema.tsmobile/src/test-support/rpc-recording/adapters/session-screen-tab-mount-adapters.tsmobile/src/transport/renderer-unavailable-refusal.test.tsmobile/src/transport/renderer-unavailable-refusal.tssrc/main/persistence/terminal-topology/terminal-topology-boundary-ratchet.test.tssrc/main/runtime/editor-authority.tssrc/main/runtime/headless-tab-group-split-layout.tssrc/main/runtime/host-editor-file-id-assignments.tssrc/main/runtime/host-editor-session-layout.tssrc/main/runtime/host-editor-session-model.test.tssrc/main/runtime/host-editor-session-model.tssrc/main/runtime/host-editor-tab-commands.tssrc/main/runtime/host-editor-tab-focus.tssrc/main/runtime/host-editor-tab-group-edit.test.tssrc/main/runtime/host-editor-tab-group-edit.tssrc/main/runtime/host-editor-tab-group-placement.tssrc/main/runtime/host-editor-tab-groups.test.tssrc/main/runtime/host-editor-tab-move-persistence.tssrc/main/runtime/host-editor-tab-projection.test.tssrc/main/runtime/host-editor-tab-projection.tssrc/main/runtime/host-editor-tab-publication.tssrc/main/runtime/host-editor-tab-state.tssrc/main/runtime/host-editor-tabs-folder.test.tssrc/main/runtime/host-editor-tabs-lifecycle.test.tssrc/main/runtime/host-editor-tabs-open.test.tssrc/main/runtime/host-editor-tabs-test-harness.spec.tssrc/main/runtime/host-editor-window-recovery.test.tssrc/main/runtime/host-markdown-document-reader.tssrc/main/runtime/host-markdown-documents-ssh.test.tssrc/main/runtime/host-markdown-documents.test.tssrc/main/runtime/orca-runtime-apply-mobile-session-tab-navigation.tssrc/main/runtime/orca-runtime-close-headless-mobile-terminal-tab.tssrc/main/runtime/orca-runtime-close-mobile-session-tab.tssrc/main/runtime/orca-runtime-file-commands.tssrc/main/runtime/orca-runtime-files-mobile-explorer-reads.test.tssrc/main/runtime/orca-runtime-hydrate-headless-mobile-session-tabs-from-workspace-session.tssrc/main/runtime/orca-runtime-move-headless-mobile-session-tab.tssrc/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.tssrc/main/runtime/orca-runtime-persist-headless-terminal-title.tssrc/main/runtime/orca-runtime-preserved-branch-cleanup.tssrc/main/runtime/orca-runtime-stored-mobile-snapshot-has-stale-preserved-tab.tssrc/main/runtime/orca-runtime-sync-window-graph.tssrc/main/runtime/orca-runtime-test-fixtures.spec.tssrc/main/runtime/runtime-file-command-host.tssrc/main/runtime/runtime-file-commands-constructor.tssrc/main/runtime/runtime-file-commands-write-file-explorer-file.tssrc/main/runtime/runtime-mobile-markdown-documents.tssrc/main/runtime/runtime-workspace-session-controller.tssrc/renderer/src/lib/language-detect.tssrc/renderer/src/runtime/mobile-markdown-bridge.tssrc/renderer/src/runtime/sync-runtime-graph/mobile-session-editor-tabs.tssrc/renderer/src/store/slices/editor/actions/hydrate-editor-session.tssrc/renderer/src/store/slices/editor/file-ids/editor-file-ids.tssrc/renderer/src/store/slices/editor/file-ids/hydrated-editor-file-ids.tssrc/renderer/src/store/slices/store-session-host-editor-tabs-hydration.test.tssrc/shared/editor-file-identity.tssrc/shared/language-detect.test.tssrc/shared/language-detect.tssrc/shared/mobile-markdown-document.tssrc/shared/mobile-session-editor-tab-projection.tssrc/shared/monaco-filename-language.test.tssrc/shared/monaco-filename-language.tssrc/shared/monaco-language-associations.jsonsrc/shared/protocol-version.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| // Why: diffs are never persisted, so a window taking editor authority starts without them. | ||
| protected retireHostEditorDiffTabsForWindowTakeover(): void { | ||
| for (const worktreeId of getHostEditorTabState(this).clearAllDiffs()) { | ||
| const snapshot = this.mobileSessionTabsByWorktree.get(worktreeId) | ||
| if (snapshot) { | ||
| this.storeMobileSessionSnapshot(worktreeId, { | ||
| ...snapshot, | ||
| snapshotVersion: snapshot.snapshotVersion + 1, | ||
| tabs: snapshot.tabs.filter((tab) => tab.type !== 'file' || tab.mode !== 'diff') | ||
| }) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Also remove retired diff ids from tabGroups and activeTabId.
This method filters diff tabs out of snapshot.tabs. It keeps activeTabId, activeTabType, activeGroupId and every tabGroups[].tabOrder/activeTabId unchanged. If a phone opened a diff and the diff was active, the stored snapshot then names an active tab that is no longer in tabs. The renderer's next publication overwrites this snapshot only for the worktrees it actually publishes. A worktree it does not publish keeps the dangling ids until a later rebuild. Rebuild the editor overlay for the remaining tabs, or strip the retired ids explicitly.
🐛 Proposed fix
protected retireHostEditorDiffTabsForWindowTakeover(): void {
for (const worktreeId of getHostEditorTabState(this).clearAllDiffs()) {
const snapshot = this.mobileSessionTabsByWorktree.get(worktreeId)
if (snapshot) {
+ const retired = new Set(
+ snapshot.tabs
+ .filter((tab) => tab.type === 'file' && tab.mode === 'diff')
+ .map((tab) => tab.id)
+ )
+ const tabs = snapshot.tabs.filter((tab) => !retired.has(tab.id))
+ const active = retired.has(snapshot.activeTabId ?? '')
+ ? (tabs[0] ?? null)
+ : (tabs.find((tab) => tab.id === snapshot.activeTabId) ?? null)
this.storeMobileSessionSnapshot(worktreeId, {
...snapshot,
snapshotVersion: snapshot.snapshotVersion + 1,
- tabs: snapshot.tabs.filter((tab) => tab.type !== 'file' || tab.mode !== 'diff')
+ activeTabId: active?.id ?? null,
+ activeTabType: active?.type ?? null,
+ tabGroups: snapshot.tabGroups?.map((group) => {
+ const tabOrder = group.tabOrder.filter((id) => !retired.has(id))
+ return {
+ ...group,
+ tabOrder,
+ activeTabId: retired.has(group.activeTabId ?? '')
+ ? (tabOrder[0] ?? null)
+ : group.activeTabId
+ }
+ }),
+ tabs: tabs.map((tab) => ({ ...tab, isActive: tab.id === active?.id }))
})
}
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Why: diffs are never persisted, so a window taking editor authority starts without them. | |
| protected retireHostEditorDiffTabsForWindowTakeover(): void { | |
| for (const worktreeId of getHostEditorTabState(this).clearAllDiffs()) { | |
| const snapshot = this.mobileSessionTabsByWorktree.get(worktreeId) | |
| if (snapshot) { | |
| this.storeMobileSessionSnapshot(worktreeId, { | |
| ...snapshot, | |
| snapshotVersion: snapshot.snapshotVersion + 1, | |
| tabs: snapshot.tabs.filter((tab) => tab.type !== 'file' || tab.mode !== 'diff') | |
| }) | |
| } | |
| } | |
| } | |
| // Why: diffs are never persisted, so a window taking editor authority starts without them. | |
| protected retireHostEditorDiffTabsForWindowTakeover(): void { | |
| for (const worktreeId of getHostEditorTabState(this).clearAllDiffs()) { | |
| const snapshot = this.mobileSessionTabsByWorktree.get(worktreeId) | |
| if (snapshot) { | |
| const retired = new Set( | |
| snapshot.tabs | |
| .filter((tab) => tab.type === 'file' && tab.mode === 'diff') | |
| .map((tab) => tab.id) | |
| ) | |
| const tabs = snapshot.tabs.filter((tab) => !retired.has(tab.id)) | |
| const active = retired.has(snapshot.activeTabId ?? '') | |
| ? (tabs[0] ?? null) | |
| : (tabs.find((tab) => tab.id === snapshot.activeTabId) ?? null) | |
| this.storeMobileSessionSnapshot(worktreeId, { | |
| ...snapshot, | |
| snapshotVersion: snapshot.snapshotVersion + 1, | |
| activeTabId: active?.id ?? null, | |
| activeTabType: active?.type ?? null, | |
| tabGroups: snapshot.tabGroups?.map((group) => { | |
| const tabOrder = group.tabOrder.filter((id) => !retired.has(id)) | |
| return { | |
| ...group, | |
| tabOrder, | |
| activeTabId: retired.has(group.activeTabId ?? '') | |
| ? (tabOrder[0] ?? null) | |
| : group.activeTabId | |
| } | |
| }), | |
| tabs: tabs.map((tab) => ({ ...tab, isActive: tab.id === active?.id })) | |
| }) | |
| } | |
| } | |
| } |
| function recordedWrapperHost( | ||
| runtime: HostMarkdownRuntime, | ||
| worktreeId: string, | ||
| record: HostEditTabRecord | ||
| ): ExecutionHostId | null { | ||
| const wrapper = runtime | ||
| .getOwnWorkspaceSessionForWorktree(worktreeId) | ||
| ?.unifiedTabs?.[worktreeId]?.find((tab) => tab.id === record.tabId) | ||
| return wrapper?.executionHostId ?? null | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Look up the persisted wrapper by record.wrapperId, not record.tabId.
listHostEditTabs sets tabId to the restored file id when the wrapper's own id equals the legacy file id (tabId: wrapper.id === legacyId ? id : wrapper.id). In that case record.tabId does not equal any unifiedTabs entry id. The find then returns undefined, recordedWrapperHost returns null, and resolveHostMarkdownTab silently skips the recorded-host check at Line 122. The HostEditTabRecord.wrapperId field exists for this lookup. Its documentation says it is "The persisted wrapper's own id".
🐛 Proposed fix
function recordedWrapperHost(
runtime: HostMarkdownRuntime,
worktreeId: string,
record: HostEditTabRecord
): ExecutionHostId | null {
+ if (record.wrapperId === null) {
+ return null
+ }
const wrapper = runtime
.getOwnWorkspaceSessionForWorktree(worktreeId)
- ?.unifiedTabs?.[worktreeId]?.find((tab) => tab.id === record.tabId)
+ ?.unifiedTabs?.[worktreeId]?.find((tab) => tab.id === record.wrapperId)
return wrapper?.executionHostId ?? null
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function recordedWrapperHost( | |
| runtime: HostMarkdownRuntime, | |
| worktreeId: string, | |
| record: HostEditTabRecord | |
| ): ExecutionHostId | null { | |
| const wrapper = runtime | |
| .getOwnWorkspaceSessionForWorktree(worktreeId) | |
| ?.unifiedTabs?.[worktreeId]?.find((tab) => tab.id === record.tabId) | |
| return wrapper?.executionHostId ?? null | |
| } | |
| function recordedWrapperHost( | |
| runtime: HostMarkdownRuntime, | |
| worktreeId: string, | |
| record: HostEditTabRecord | |
| ): ExecutionHostId | null { | |
| if (record.wrapperId === null) { | |
| return null | |
| } | |
| const wrapper = runtime | |
| .getOwnWorkspaceSessionForWorktree(worktreeId) | |
| ?.unifiedTabs?.[worktreeId]?.find((tab) => tab.id === record.wrapperId) | |
| return wrapper?.executionHostId ?? null | |
| } |
…erve-render-8165 Keeps one mechanism for editor tabs on a host with no window: main's headless editor projection (mobile-session-editor-projection.ts) is removed in favour of this branch's host editor tabs, which already list and close the rows a converted SSH host's migration carries in. closeHostEditorTab now honours force, as main's contract did. Main's specs expect this branch's plain draft-refusal message and seed the README row inside the workspace the projection lists.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
mobile/src/session/use-mobile-session-content-create-actions.ts (1)
108-129: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDo not run
router.pushinside thetryblock that catches open failures.
previewCreatedNote()on Line 117 runs inside thetryblock. Ifrouter.pushthrows there, thecatchblock on Line 121 callspreviewCreatedNote()a second time and shows the device-opened toast. Store the refusal result in a variable and callpreviewCreatedNote()after thetryblock. Thetryblock then covers only the RPC.♻️ Proposed restructure
- try { - const openResponse = await sourceFileOpenRun.request( - client, - { worktree, relativePath }, - { timeoutMs: 15_000 } - ) - if (isRendererUnavailableRefusal(openResponse)) { - previewCreatedNote() - return - } - interpretOrThrowRefusalMessage(() => sourceFileOpenRun.interpret(openResponse), '') - } catch { + let refused = false + try { + const openResponse = await sourceFileOpenRun.request( + client, + { worktree, relativePath }, + { timeoutMs: 15_000 } + ) + refused = isRendererUnavailableRefusal(openResponse) + if (!refused) { + interpretOrThrowRefusalMessage(() => sourceFileOpenRun.interpret(openResponse), '') + } + } catch { previewCreatedNote() showToast(...) return } + if (refused) { + previewCreatedNote() + return + }
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
3a9a33e6-8b62-4b4a-8613-16de6770c5fc
📒 Files selected for processing (88)
config/scripts/generate-monaco-associations.mjsconfig/tsconfig.cli.jsonmobile/rpc-foundation/goldens/matrix-session.content-create-files.open-1.jsonmobile/rpc-foundation/goldens/matrix-session.markdown-disk-fallback-files.read-1.jsonmobile/rpc-foundation/goldens/session-markdown-disk-read.jsonmobile/rpc-foundation/goldens/session-markdown-tab-disk-fallback.jsonmobile/src/files/mobile-file-mutation-ownership.tsmobile/src/session/host-editor-tab-release-contract.test.tsmobile/src/session/markdown-note-host-editor-tabs.tsmobile/src/session/mobile-file-tap-open.test.tsmobile/src/session/mobile-file-tap-open.tsmobile/src/session/mobile-markdown-disk-fallback.test.tsmobile/src/session/mobile-markdown-disk-fallback.tsmobile/src/session/use-mobile-diff-review-interactions.tsmobile/src/session/use-mobile-diff-review-open-in-session.test.tsmobile/src/session/use-mobile-session-content-create-actions.tsmobile/src/session/use-mobile-session-content-create-markdown-note.test.tsmobile/src/source-control/session-changed-file-open.test.tsmobile/src/source-control/session-changed-file-open.tsmobile/src/source-control/use-mobile-source-control-openers.tsmobile/src/tasks/task-runtime-reply-schema.test.tsmobile/src/tasks/task-runtime-reply-schema.tsmobile/src/test-support/rpc-recording/adapters/session-screen-tab-mount-adapters.tsmobile/src/transport/renderer-unavailable-refusal.test.tsmobile/src/transport/renderer-unavailable-refusal.tssrc/main/persistence/terminal-topology/terminal-topology-boundary-ratchet.test.tssrc/main/runtime/editor-authority.tssrc/main/runtime/headless-tab-group-split-layout.tssrc/main/runtime/host-editor-file-id-assignments.tssrc/main/runtime/host-editor-session-layout.tssrc/main/runtime/host-editor-session-model.test.tssrc/main/runtime/host-editor-session-model.tssrc/main/runtime/host-editor-tab-commands.tssrc/main/runtime/host-editor-tab-focus.tssrc/main/runtime/host-editor-tab-group-edit.test.tssrc/main/runtime/host-editor-tab-group-edit.tssrc/main/runtime/host-editor-tab-group-placement.tssrc/main/runtime/host-editor-tab-groups.test.tssrc/main/runtime/host-editor-tab-move-persistence.tssrc/main/runtime/host-editor-tab-projection.test.tssrc/main/runtime/host-editor-tab-projection.tssrc/main/runtime/host-editor-tab-publication.tssrc/main/runtime/host-editor-tab-state.tssrc/main/runtime/host-editor-tabs-folder.test.tssrc/main/runtime/host-editor-tabs-lifecycle.test.tssrc/main/runtime/host-editor-tabs-open.test.tssrc/main/runtime/host-editor-tabs-test-harness.spec.tssrc/main/runtime/host-editor-window-recovery.test.tssrc/main/runtime/host-markdown-document-reader.tssrc/main/runtime/host-markdown-documents-ssh.test.tssrc/main/runtime/host-markdown-documents.test.tssrc/main/runtime/mobile-session-editor-projection.tssrc/main/runtime/orca-runtime-apply-mobile-session-tab-navigation.tssrc/main/runtime/orca-runtime-close-headless-mobile-terminal-tab.tssrc/main/runtime/orca-runtime-close-mobile-session-tab.tssrc/main/runtime/orca-runtime-file-commands.tssrc/main/runtime/orca-runtime-files-mobile-explorer-reads.test.tssrc/main/runtime/orca-runtime-hydrate-headless-mobile-session-tabs-from-workspace-session.tssrc/main/runtime/orca-runtime-move-headless-mobile-session-tab.tssrc/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.tssrc/main/runtime/orca-runtime-persist-headless-terminal-title.tssrc/main/runtime/orca-runtime-preserved-branch-cleanup.tssrc/main/runtime/orca-runtime-stored-mobile-snapshot-has-stale-preserved-tab.tssrc/main/runtime/orca-runtime-sync-window-graph.tssrc/main/runtime/orca-runtime-test-fixtures.spec.tssrc/main/runtime/orca-runtime-tests/mobile-session-tabs-cold-serve-hydrate.spec.tssrc/main/runtime/orca-runtime-tests/mobile-session-tabs-part-14.spec.tssrc/main/runtime/runtime-file-command-host.tssrc/main/runtime/runtime-file-commands-constructor.tssrc/main/runtime/runtime-file-commands-write-file-explorer-file.tssrc/main/runtime/runtime-mobile-markdown-documents.tssrc/main/runtime/runtime-workspace-session-controller.tssrc/renderer/src/lib/language-detect.tssrc/renderer/src/runtime/mobile-markdown-bridge.tssrc/renderer/src/runtime/sync-runtime-graph/mobile-session-editor-tabs.tssrc/renderer/src/store/slices/editor/actions/hydrate-editor-session.tssrc/renderer/src/store/slices/editor/file-ids/editor-file-ids.tssrc/renderer/src/store/slices/editor/file-ids/hydrated-editor-file-ids.tssrc/renderer/src/store/slices/store-session-host-editor-tabs-hydration.test.tssrc/shared/editor-file-identity.tssrc/shared/language-detect.test.tssrc/shared/language-detect.tssrc/shared/mobile-markdown-document.tssrc/shared/mobile-session-editor-tab-projection.tssrc/shared/monaco-filename-language.test.tssrc/shared/monaco-filename-language.tssrc/shared/monaco-language-associations.jsonsrc/shared/protocol-version.ts
💤 Files with no reviewable changes (5)
- src/shared/monaco-filename-language.test.ts
- src/shared/monaco-language-associations.json
- src/shared/monaco-filename-language.ts
- src/shared/language-detect.test.ts
- src/main/runtime/mobile-session-editor-projection.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- mobile/rpc-foundation/goldens/session-markdown-tab-disk-fallback.json
- mobile/rpc-foundation/goldens/session-markdown-disk-read.json
- mobile/rpc-foundation/goldens/matrix-session.markdown-disk-fallback-files.read-1.json
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
nwparker
left a comment
There was a problem hiding this comment.
Cross-reference for #22186 after reviewing the host Markdown reader/save path and note-creation scope: thank you @brennanb2025 for the broader headless-tab implementation, SSH ownership/reconnect checks, and Android evidence.
#31291 addresses the narrower new Markdown note creation/open/read/save reproduction and credits this PR. It does not replace your broader host-owned editor model, SSH-backed document flow, diff tabs, or older-host fallback. #22186 remains linked as an addressed reproduction rather than automatically closed. This is an overlap/integration review, not a blanket approval or a claim that I reran this branch's tests.
Create, read, and save Markdown notes on headless hosts through authorized file operations and persisted editor tabs. Addresses the Markdown-note reproduction in #22186, reported by @shota46. Thanks to @Jinwoo-H (#31101), @brennanb2025 (#25436), and @Meapri (#23357) for related community implementations and regression coverage. Those PRs retain broader/distinct scope. Validation: focused tests, paired-headless E2E, iPhone simulator proof, and all CI checks passed.
ELI5
When your phone talks to an Orca computer that has no desktop window open (a headless
orca servehost on Linux or macOS, or a Mac whose Orca window is closed), opening a Markdown file, a code file, or a diff as a tab failed with the raw errorrenderer_unavailable, and New tab → Markdown Note left a strayuntitled.mdbehind. The cause: only the desktop window knew how to open those tabs, and on these hosts there is no window. Now the host itself opens, saves and closes those tabs, so the phone works the same with or without a window. Phones paired to an older host that still refuses show the file or diff on the phone instead of an error.What Changed
The problem
renderer_unavailable([Bug] ADE mobile: diff viewer fails with renderer_unavailable when opening a changed file for review #14315). Tapping a file path in a terminal did nothing; in a chat it said "Couldn't open …". "Open in Session" on the phone's review screen showedrenderer_unavailable.untitled.mdon disk and then failed withrenderer_unavailable, leaving the file behind ([bug] Mobile markdown tabs show renderer_unavailable onorca servehosts (works via desktop host) #22186).files.open,files.openDiff,markdown.readTabandmarkdown.saveTabto the window and answeredrenderer_unavailablewhen there was none. Terminal, browser and chat tabs did not have this problem because the host already owns them.What this changes for you
renderer_unavailableuntitled.md, thenrenderer_unavailablerenderer_unavailableEvery mobile request that answered
renderer_unavailablewas checked. Covered:files.open,files.openDiff,markdown.readTab,markdown.saveTab, andsession.tabs.close/closeLifecycle/activate/movefor editor tabs. Not covered: closing a browser tab that a since-closed desktop window hosted (browser engine scope; other browser tabs already work headless). Two window-dependent bugs found along the way are notrenderer_unavailableand are left for separate fixes: headlessworktree.sleepreports success without sleeping, and the empty Switch Branch sheet on serve (STA-9443).How it works
resolveEditorAuthority(src/main/runtime/editor-authority.ts) is derived on every call, never stored, and has three answers: "window" when an authoritative desktop window is attached (every path exactly as before); "host" when no live window document exists (no window, or its renderer is gone), so nothing can later write back a stale view; "unavailable" when a desktop window is open but still taking over (for example a serve host whose window promotion is slow or failed). In that last state the phone gets "The computer's Orca window is still starting. Try again." and the host changes nothing, so the window can never miss a host change; once the window finishes taking over, the window route works.src/shared/, and both the window and the host use them.host-markdown-document-reader.ts,runtime-mobile-markdown-documents.ts): bounded 2 MiB UTF-8-safe reads, binary refused, version = the existing content hash. Save runs one at a time per file, re-reads and compares the hash (identical re-save succeeds, anything else is aconflict), re-checks ownership right before the write, then verifies by reading back. Files with an unsaved desktop draft, over the edit limit, or outside the workspace are read-only or refused, never overwritten. SSH goes through the existing provider routing. Rows naming files outside the workspace are not listed on the phone while the host owns the tabs (as before this PR), and stay in the session for the desktop.session-tabs.host-editor-tabs.v1. No new request, parameter or stream message; the host publishes the existingmarkdown/filetab kinds that phones already decode from desktop hosts.Co-authored-bytrailer: one exactrenderer_unavailablecheck (never timeouts, disconnects or browser errors), device review / preview fallbacks, plain copy. The Markdown Note check reads the host's status at tap time: capability → create; host reports no usable window and no capability → one toast, nothing created; unknown → try as before, and if the host refuses after creating the file, open that file in the phone's preview.Why
Differences from the common pattern (host serves file bytes and diffs by request; the client owns its open files):
markdown.*wire token.Linked Issue
Fixes #22186
Fixes #14315
Visual Proof
Android emulator paired directly to a headless
orca servehost on macOS (no desktop window), with a fixture repo holdingnotes/readme.mdand an uncommitted change tosrc/app.txt.src/app.txtThe jumbled note text comes from how the emulator injects typed text into the phone's editor, which this PR does not change; the host saved exactly the bytes the editor showed.
Testing
New host specs: open / openDiff / dedupe / caller navigation, close / activate / move / split, one group model for desktop-written sessions, folder and SSH workspaces, Markdown read / save / conflict / truncation / drafts / SSH provider, session model and placement, window take-over (slow or failed promotion refuses with no write; crashed renderer; window closed and reopened; an open that crosses a take-over), renderer hydration of host-written tabs. Every behavioural test was ablated and fails without its fix.
Regression:
src/main/runtime,src/main/ipc,src/main/window,src/renderer/src/runtime,src/renderer/src/store/slices/editor,src/shared: 30134 passed, 0 failed. Phone suites + RPC recordings pass.tc:node,tc:web,tc:clipass; oxlint, anti-slop, changed-code quality and React Doctor clean.Phone QA (an agent on an Android emulator, 2 rounds, headless
orca serveon macOS, isolated profiles):renderer_unavailableand leavesuntitled.md(twice:untitled-2.md); changed file showsrenderer_unavailable. This is the bug.conflictand leaves the file unchanged; closing a tab from its long-press menu removes it for good; after a host restart the note tab is still there and the diff tab is gone.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Author X/Twitter: @BrennanKB5
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)