Repository navigation
fix(runtime): a phone reads and saves Markdown tabs on a headless server - #31101
Conversation
With no window to relay through, markdown.readTab and markdown.saveTab answered renderer_unavailable. Main now reads the tab's file (or its saved draft) from disk and saves with a version compare plus the disk write precondition, in the shapes the window's editor relay returns. With a window attached the relay is unchanged.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
8a76f8cd-7141-48bf-9f8f-686e62799eff
📒 Files selected for processing: 7
src/main/runtime/files/file-reads.tssrc/main/runtime/headless-markdown-tab-documents.test.tssrc/main/runtime/headless-markdown-tab-documents.tssrc/main/runtime/mobile-session-editor-projection.tssrc/main/runtime/workspaces/workspace-file-session-targets.tstests/e2e/headless-serve-mobile-markdown.spec.tstests/e2e/helpers/headless-layout-oracle-hosts.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
…nly tabs, re-find the record to clear
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
416de805-a6b6-4d82-908a-5fd95cb1e56d
📒 Files selected for processing: 2
.github/workflows/e2e.ymlsrc/main/runtime/headless-markdown-tab-documents.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
| - name: Phone Markdown on headless orcad serve | ||
| if: >- | ||
| !cancelled() && | ||
| (inputs.test_files == '' || contains(inputs.test_files, 'tests/e2e/headless-serve-mobile-markdown.spec.ts')) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Add the new spec to the job-level if condition.
The step condition accepts tests/e2e/headless-serve-mobile-markdown.spec.ts. The orcad-serve-mode-switch job condition at Lines 443-446 does not accept it. The condition lists only orcad-serve-mode-switch.spec.ts and workspace-layout-oracle-headless.spec.ts. A run whose inputs.test_files contains only the Markdown spec skips the whole job. The orcad case then never runs. The run still reports success.
🐛 Proposed fix (job condition, Lines 443-446)
if: >-
inputs.test_files == '' ||
contains(inputs.test_files, 'tests/e2e/orcad-serve-mode-switch.spec.ts') ||
- contains(inputs.test_files, 'tests/e2e/workspace-layout-oracle-headless.spec.ts')
+ contains(inputs.test_files, 'tests/e2e/workspace-layout-oracle-headless.spec.ts') ||
+ contains(inputs.test_files, 'tests/e2e/headless-serve-mobile-markdown.spec.ts')…s its view state Clearing a saved draft wrote workspace layout from main, which no layout command carries. Main now never shows or edits a draft; the desktop's restore check reports a disk change.
A paired server's workspace is read and saved on that server with files.read / files.writeIfUnchanged, so it answers from its own disk and keeps the precondition. The window relay (ui:mobileMarkdownRequest and the renderer bridge) is removed.
The phone reads the disk with the tab marked dirty; its save lands on disk, and the desktop keeps its draft and shows the changed-on-disk banner.
origin/main's #30417 edited the renderer Markdown bridge this branch removes; with no window relay left, its rollback module and the editor's 'mobile' save trigger have no caller, so they go too.
…cover the untitled tab A server before #30605 has no files.writeIfUnchanged, so the save is refused with the existing update-required message rather than written unchecked.
…; pin the untitled answer
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
1c59ee54-60ee-4e9c-983b-010340e1ab42
📒 Files selected for processing: 31
.github/workflows/e2e.ymlsrc/main/runtime/markdown-tab-disk-documents.test.tssrc/main/runtime/markdown-tab-disk-documents.tssrc/main/runtime/markdown-tab-disk-host.tssrc/main/runtime/orca-runtime-mobile-markdown-tab-routes.test.tssrc/main/runtime/runtime-notifier-contract.tssrc/main/runtime/workspaces/workspace-file-session-targets.tssrc/main/window/mobile-markdown-request-relay.test.tssrc/main/window/mobile-markdown-request-relay.tssrc/main/window/runtime-window-lifecycle-file-open.test.tssrc/main/window/runtime-window-lifecycle.tssrc/main/window/runtime-window-pane-title-notification.test.tssrc/preload/api/ui-bridge-clipboard-and-window-controls.tssrc/preload/api/ui-command-event-api.tssrc/renderer/src/components/editor/editor-autosave-controller.tssrc/renderer/src/components/editor/editor-autosave.tssrc/renderer/src/components/editor/editor-clean-tab-draft-invariant.test.tssrc/renderer/src/components/editor/editor-save-disk-precondition.tssrc/renderer/src/components/editor/editor-save-queue.tssrc/renderer/src/components/editor/editor-save-shared-model-dirty.test.tssrc/renderer/src/components/editor/editor-save-shared-model.test.tssrc/renderer/src/hooks/ipc-events/app-lifetime-ipc-bridge.tssrc/renderer/src/runtime/editor-buffer-dirty-readers.test.tssrc/renderer/src/runtime/mobile-markdown-bridge-save-guards.test.tssrc/renderer/src/runtime/mobile-markdown-bridge-test-harness.tssrc/renderer/src/runtime/mobile-markdown-bridge.test.tssrc/renderer/src/runtime/mobile-markdown-bridge.tssrc/renderer/src/runtime/mobile-markdown-save-rollback.tssrc/renderer/src/web/preload-api/web-ui-api.tssrc/shared/mobile-markdown-document.tstests/e2e/desktop-window-mobile-markdown.spec.ts
💤 Files with no reviewable changes: 20
- src/main/window/mobile-markdown-request-relay.test.ts
- src/main/window/runtime-window-lifecycle-file-open.test.ts
- src/renderer/src/components/editor/editor-autosave.ts
- src/main/window/runtime-window-pane-title-notification.test.ts
- src/renderer/src/hooks/ipc-events/app-lifetime-ipc-bridge.ts
- src/preload/api/ui-command-event-api.ts
- src/shared/mobile-markdown-document.ts
- src/renderer/src/components/editor/editor-save-shared-model-dirty.test.ts
- src/renderer/src/runtime/mobile-markdown-bridge.ts
- src/renderer/src/components/editor/editor-save-shared-model.test.ts
- src/renderer/src/runtime/mobile-markdown-bridge.test.ts
- src/renderer/src/runtime/mobile-markdown-bridge-save-guards.test.ts
- src/main/window/runtime-window-lifecycle.ts
- src/main/runtime/runtime-notifier-contract.ts
- src/main/window/mobile-markdown-request-relay.ts
- src/preload/api/ui-bridge-clipboard-and-window-controls.ts
- src/renderer/src/runtime/mobile-markdown-bridge-test-harness.ts
- src/renderer/src/runtime/mobile-markdown-save-rollback.ts
- src/renderer/src/web/preload-api/web-ui-api.ts
- src/renderer/src/components/editor/editor-clean-tab-draft-invariant.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
| const address = { worktree: `id:${worktreeId}`, relativePath: file.relativePath } | ||
| const read = await callEnvironment(call, environmentId, 'files.read', address) | ||
| if (!isRecord(read) || typeof read.content !== 'string') { | ||
| throw new Error('invalid_runtime_response') | ||
| } | ||
| const cut = utf8ByteLength(read.content) | ||
| if (read.truncated !== true) { | ||
| return { content: read.content, byteLength: cut } | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
# Inspect the files.read result shape for binary or image markers.
fd -t f 'files' src/main/runtime/rpc/methods --exec rg -n -C4 "files\.read|isBinary|binary" {}
rg -nP -C3 '\bisBinary\b' src/main/runtime/files src/shared | head -80Repository: stablyai/orca
Length of output: 13328
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- host implementation ---'
nl -ba src/main/runtime/markdown-tab-disk-host.ts | sed -n '1,190p'
printf '%s\n' '--- readMobileFile bindings ---'
rg -n -F --glob '*.{ts,tsx}' -e 'readMobileFile' -e 'FileOpen' src shared tests || test "$?" -eq 1
printf '%s\n' '--- candidate declarations and implementation context ---'
rg -n -C8 -F --glob '*.{ts,tsx}' 'readMobileFile' src tests || test "$?" -eq 1Repository: stablyai/orca
Length of output: 39944
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- file reads imports, type, and readMobileFile ---'
nl -ba src/main/runtime/files/file-reads.ts | sed -n '1,125p'
printf '%s\n' '--- RuntimeFileReadResult declarations ---'
rg -n -C5 -F --glob '*.{ts,tsx}' -e 'type RuntimeFileReadResult' -e 'interface RuntimeFileReadResult' -e 'RuntimeFileReadResult' src shared tests || test "$?" -eq 1
printf '%s\n' '--- binary_file handling in the bound read path ---'
rg -n -C5 -F --glob '*.{ts,tsx}' -e "binary_file" -e 'isBinaryBuffer' src/main/runtime/files src/shared tests || test "$?" -eq 1Repository: stablyai/orca
Length of output: 21981
🏁 Script executed:
set -o pipefail
printf '%s\n' '--- remaining mobile read implementation ---'
nl -ba src/main/runtime/files/file-reads.ts | sed -n '175,245p'
printf '%s\n' '--- mobile file classification ---'
nl -ba src/main/runtime/files/mobile-file-kind.ts | sed -n '1,180p'
printf '%s\n' '--- local prefix reader ---'
rg -n -C8 -F --glob '*.{ts,tsx}' 'readLocalRuntimeFilePrefix' src/main/runtime
printf '%s\n' '--- shared result contract ---'
nl -ba src/shared/runtime-file-contracts.ts | sed -n '40,58p'Repository: stablyai/orca
Length of output: 9240
Apply the binary-content check in files.read.
readMobileFile rejects only known binary extensions. It converts all other file bytes to UTF-8. A binary file with an unlisted extension can therefore reach the paired-server Markdown path as editable text, while the local path rejects content detected by isBinaryBuffer.
RuntimeFileReadResult has no isBinary field. Add the check before converting the buffer instead of checking read.isBinary in markdown-tab-disk-host.ts.
🛡️ Suggested fix
- const content = await readLocalMobileFile(filePath, store)
- const truncated = truncateMobileFilePreview(content)
+ const content = await readLocalMobileFile(filePath, store)
+ if (isBinaryBuffer(content)) {
+ throw new Error('binary_file')
+ }
+ const truncated = truncateMobileFilePreview(content.toString('utf8'))
...
-async function readLocalMobileFile(filePath: string, store: RuntimeStore): Promise<string> {
+async function readLocalMobileFile(filePath: string, store: RuntimeStore): Promise<Buffer> {
...
- return bytes.toString('utf8')
+ return bytes… the desktop editor; a closed-source preview still reads - The desktop lists an untitled document's tab with isUntitled (optional, additive); main answers it read-only with unsupported_untitled and refuses its save before touching the disk. - A server without the files.write.disk-precondition capability gets the desktop editor's guarded save: compare from here, then a plain files.write, or a conflict. Every call of a save is pinned to the pairing it probed. - A preview whose source tab was closed has no saved record; it reads its own file, read-only.
A save captures the server's pairing before it reads, and every call of the save, the read included, is pinned to it, so a re-pair between the read and the write is refused.
#31196 edited the removed renderer Markdown bridge and moved the editor save queue's precondition check; the bridge stays deleted and the queue keeps main's order without the 'mobile' trigger.
… creates a deleted one
#31313 renamed a flush call inside the removed renderer Markdown bridge; the bridge stays deleted.
nwparker
left a comment
There was a problem hiding this comment.
Cross-reference after comparing the current diff with #31291: both address headless Markdown reads/saves using bounded reads, version checks, and the shared disk-precondition writer. Thank you @Jinwoo-H for this implementation and its stale-save/queued-save coverage.
#31291 fixes the new-note creation/open/read/save reproduction in #22186 and retains the existing desktop relay. Your current diff additionally routes Markdown through disk-backed document handling, covers preview/untitled policy, and changes desktop dirty-buffer/relay behavior. Those differences are not superseded by #31291. I added explicit credit and a link there. This review is limited to overlap and integration scope; I have not run this branch's full acceptance suite.
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.
#31291 added HeadlessMarkdownDocuments for windowless phone Markdown reads and saves, next to the window relay. This branch replaces both with one path through main and the disk, so its read/save wiring and module are dropped; its headless editor-open and session-update changes stay, and its e2e (headless-mobile-markdown.spec.ts) runs against the merged path.
ELI5
When you open a Markdown tab on your phone, the phone now always reads and saves the actual file. Before, what happened depended on whether a desktop window was open. With a window, the phone went through the desktop's editor and could see (and save over) text you hadn't saved yet. Without a window, the phone could only show the file read-only. Now there is one way, and it works the same with or without a window. Unsaved desktop text stays on the desktop. The phone just sees "Changed on desktop", and the desktop warns you when the phone changes the file.
What Changed
What you see
unsupported_untitled). A phone save never creates or changes a file the user didn't name.unsupported_preview). That includes a preview whose source tab was closed.Before / after, by where the workspace runs
executionHost: runtime:<env>)renderer_unavailable(read-only disk fallback on the phone)runtime:<env>)renderer_unavailablefiles.readand saves withfiles.writeIfUnchanged(or the editor's compare-then-write on older servers);isDirtycomes from the desktop's tabssh:hostrenderer_unavailableSshHostNotServedErroron read and saverenderer_unavailable(read-only disk fallback)isDirtycomes from the desktop's tabHow it works
markdown.readTab/markdown.saveTabalways run in main, insrc/main/runtime/markdown-tab-disk-documents.ts.findListedEditorFile). With a window, that is the renderer's published tab list; without one, it is the persisted session.markdown-tab-disk-host.ts:runtime:<env>: the same calls the desktop editor makes, over the existing paired-server transport (callRuntimeEnvironment). If the server advertisesfiles.write.disk-precondition.v1, the save isfiles.writeIfUnchangedwith the disk check. An older server gets the desktop editor's fallback (writeRemoteFileIfUnchanged): read and compare from here, then a plainfiles.write, or report a conflict.remote_runtime_unavailable, never as an empty or missing file.ssh:hosts and files outside the workspace on an SSH host: refused.isUntitled: trueon Markdown tabs. Older hosts and phones ignore it. With no window, nothing records that a document is untitled (the desktop forgets it on restart too), so an existinguntitled.mdis an ordinary file there; a missing one is never created.Deleted (the window relay and what only it used)
src/main/window/mobile-markdown-request-relay.tsand its testreadMobileMarkdownTab/saveMobileMarkdownTab(runtime-notifier-contract.ts,runtime-window-lifecycle.ts)onMobileMarkdownRequest/respondMobileMarkdownRequest, theui:mobileMarkdownRequest/ui:mobileMarkdownResponsechannels, and the web preload stubssrc/renderer/src/runtime/mobile-markdown-bridge.ts, its tests, save-guard tests and test harness, plus the attach inapp-lifetime-ipc-bridge.tsRuntimeMobileMarkdownRequest/RuntimeMobileMarkdownResponsetypessrc/renderer/src/runtime/mobile-markdown-save-rollback.ts(from fix(editor): refuse saves that would overwrite unnoticed disk changes #30417) and the editor's'mobile'save trigger (origin: 'mobile'), which only the bridge set. Their 4 test cases went with them. The desktop's own saves are unchanged.Why
markdown.readTab. The server doesn't know the desktop's tab ids, and this keeps the desktop's session as the single authority on which tab maps to which file.Linked Issue
Terminal-layout final design, track H (H2). No issue.
Visual Proof
The e2e below runs with the desktop window hidden. It asserts the changed-on-disk banner and attaches a screenshot of the desktop after the phone's save (
desktop-after-phone-save).Testing
Unit tests
src/main/runtime/orca-runtime-mobile-markdown-tab-routes.test.tsruns the real runtime, with a second runtime acting as the paired server over a temp disk. It covers:files.writeIfUnchanged, with every call pinned to the pairing;writeIfUnchanged):files.writeafter a compare here;files.writeis never called;remote_runtime_unavailablewith the disk untouched;ssh:and a file outside the workspace on an SSH host:SshHostNotServedErroron read and save;isDirty;These tests fail first: the server-forwarding test and all 6 new cases fail against the code before each change.
Also:
src/main/runtime/markdown-tab-disk-documents.test.ts: truncation, read-only reasons, the version check, a write racing the check, repeated taps, the save queue.src/renderer/src/runtime/sync-runtime-graph/mobile-session-editor-tabs.test.ts: the listing flags untitled documents only.End-to-end tests
tests/e2e/desktop-window-mobile-markdown.spec.ts(desktop window, phone paired):isDirty: trueand saves. The disk changes, the banner shows, and the desktop's draft, dirty flag and editor text are unchanged.unsupported_untitled, and its save is refused with the disk unchanged. After the file is deleted, the read fails with ENOENT and the save still creates nothing.tests/e2e/headless-serve-mobile-markdown.spec.ts: read, save and conflict on headless Electron and orcad servers.Gates:
pnpm tc, changed-code quality, the CI static analysis job locally, and the switch-on (ORCA_LAYOUT_OWNER=main) suites forsrc/main/runtime,src/main/persistence,src/renderer/src/runtimeandsrc/renderer/src/components/terminal-panecompared against the merge base (no file or test fails at head only).Server specs: switch-on builds, at head 86604a5 and at merge-base 379ad0c (rerun after the last main merge, which changed the windowless Markdown path; see Notes).
paired-mobile-desktop-tab-composition: fails at head and at base with the same error (session.tabs.createTerminal: terminal_handle_stale, the known createTerminal regression on main).paired-desktop-server-layout-frames: fails at head and at base with the same error ("Timed out waiting for the Orca runtime to respond").paired-desktop-server-layout-intents: no such spec on main or this branch, so not run. No new failures against base. Phone Markdown e2e at head pass 5/5:headless-mobile-markdown(from #31291),headless-serve-mobile-markdownon Electron and a freshly built orcad, and bothdesktop-window-mobile-markdowncases.Known limit: a Markdown file on a paired server is previewed up to 512 KiB, the server's
files.readreply cap, against 2 MiB locally. Larger files are marked truncated, with their real size.Review
Agent skill upstream boundary
Notes
HeadlessMarkdownDocuments) beside the window relay. This PR replaces both with the one disk path, so that module is removed; its headless open-file and session-update changes stay, and its e2e passes on this path. Unlike fix(mobile): create and edit notes on headless hosts #31291, a windowless read no longer shows a draft the desktop left in the saved session, and a phone save no longer clears that draft; the desktop reports the disk change when it next opens the tab.isUntitledfield is optional and additive.ssh:hosts stay refused. A managed SSH host is reached asruntime:<env>and works through its server.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)