Skip to content

fix(runtime): a phone reads and saves Markdown tabs on a headless server - #31101

Merged
Jinwoo-H merged 22 commits into
mainfrom
fd/h2-headless-markdown
Oct 21, 2026
Merged

Jinwoo-H merged 22 commits into
mainfrom
fd/h2-headless-markdown

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1284 $\color{#cf222e}{\Huge{\mathbf{−}}}$​989 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​295
Prod 24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​546 $\color{#cf222e}{\Huge{\mathbf{−}}}$​936 $\color{#cf222e}{\Huge{\mathbf{−}}}$​390

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

  • Phone, tab with unsaved desktop edits: the phone shows the file as it is on disk, marked "Changed on desktop". It no longer shows the desktop's unsaved text.
  • Phone save: the file on disk changes only if it still holds the version the phone read. Otherwise the phone gets a conflict.
  • Desktop with unsaved edits, after a phone save: your unsaved text is kept. The tab stays dirty, and the existing "This file changed on disk while you have unsaved edits…" banner appears with Compare / Reload from Disk / Keep My Edits.
  • No window open (headless server, or a desktop with its window closed): Markdown tabs can now be edited and saved from the phone. Before, they were a read-only disk preview with "Editing needs Orca desktop running".
  • Untitled desktop document ("New Markdown", never named):
    • Before, the phone showed the unsaved draft, marked "Read only", and refused saves.
    • Now it shows the untitled file's disk content (usually empty), still "Read only", and still refuses saves (unsupported_untitled). A phone save never creates or changes a file the user didn't name.
    • If the untitled file is also gone from disk, the phone shows "Couldn't load markdown" with Retry.
  • Preview tab: still read-only (unsupported_preview). That includes a preview whose source tab was closed.

Before / after, by where the workspace runs

Phone call Before, window open Before, no window After, window open or not
Targeted at a paired server (executionHost: runtime:<env>) Relayed to that server, which answered as below for its own state Relayed; a windowless server answered renderer_unavailable (read-only disk fallback on the phone) Relayed; the server answers from its own disk (read and guarded save)
Untargeted, on a workspace a paired server runs (runtime:<env>) The desktop editor answered, including its unsaved draft; the save went through the editor renderer_unavailable Main reads the server's file with files.read and saves with files.writeIfUnchanged (or the editor's compare-then-write on older servers); isDirty comes from the desktop's tab
Raw ssh: host Desktop editor (fails on the unserved SSH target) renderer_unavailable Refused with the same SshHostNotServedError on read and save
Local workspace The desktop editor answered, including its unsaved draft; the save went through the editor renderer_unavailable (read-only disk fallback) This machine's disk; the save checks the disk first; isDirty comes from the desktop's tab

How it works

  • markdown.readTab / markdown.saveTab always run in main, in src/main/runtime/markdown-tab-disk-documents.ts.
  • Main maps the phone's tab id to a file through the desktop's saved session (findListedEditorFile). With a window, that is the renderer's published tab list; without one, it is the persisted session.
  • It reads the file, marks the tab read-only for a preview, an untitled document, a read-only tab or a too-large file, and saves only when the disk still matches the version the phone read.
  • Saves to one file run one at a time.
  • Where the file lives is decided in markdown-tab-disk-host.ts:
    • Local: this process's disk.
    • runtime:<env>: the same calls the desktop editor makes, over the existing paired-server transport (callRuntimeEnvironment). If the server advertises files.write.disk-precondition.v1, the save is files.writeIfUnchanged with the disk check. An older server gets the desktop editor's fallback (writeRemoteFileIfUnchanged): read and compare from here, then a plain files.write, or report a conflict.
    • Pairing pin: a save captures the server's pairing before its first read, and every call of the save is pinned to it, so a server re-paired mid-save never receives the write.
    • Lost contact: reported as remote_runtime_unavailable, never as an empty or missing file.
    • ssh: hosts and files outside the workspace on an SSH host: refused.
  • To keep untitled documents read-only with a window open, the desktop's tab listing gains an optional, additive isUntitled: true on 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 existing untitled.md is 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.ts and its test
  • the notifier methods readMobileMarkdownTab / saveMobileMarkdownTab (runtime-notifier-contract.ts, runtime-window-lifecycle.ts)
  • preload onMobileMarkdownRequest / respondMobileMarkdownRequest, the ui:mobileMarkdownRequest / ui:mobileMarkdownResponse channels, and the web preload stubs
  • src/renderer/src/runtime/mobile-markdown-bridge.ts, its tests, save-guard tests and test harness, plus the attach in app-lifetime-ipc-bridge.ts
  • the shared RuntimeMobileMarkdownRequest / RuntimeMobileMarkdownResponse types
  • src/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

  • The relay ran a phone save through the desktop's editor. That mixed the desktop's unsaved text into what the phone saw and saved. It also only worked when a window was open, which left headless servers read-only.
  • Working on the file directly gives one behaviour with or without a window. It keeps unsaved desktop text on the desktop, and it reuses the desktop's existing changed-on-disk handling instead of a second conflict system.
  • For paired servers we forward the editor's own file calls rather than the server's 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

  • I manually tested these changes locally (macOS, hidden windows)
  • Automated tests added/updated

Unit tests

src/main/runtime/orca-runtime-mobile-markdown-tab-routes.test.ts runs the real runtime, with a second runtime acting as the paired server over a temp disk. It covers:

  • a forwarded read, answered from the server's own disk;
  • a forwarded save on a current server: files.writeIfUnchanged, with every call pinned to the pairing;
  • a server re-paired after the save's first read: refused, nothing written;
  • a save the server's disk moved under: conflict;
  • an older server (no disk-check capability, no writeIfUnchanged):
    • an unchanged file saves through files.write after a compare here;
    • a changed file conflicts and files.write is never called;
  • a server that doesn't run the workspace itself refuses and forwards no further;
  • lost contact: remote_runtime_unavailable with the disk untouched;
  • raw ssh: and a file outside the workspace on an SSH host: SshHostNotServedError on read and save;
  • with a window:
    • a dirty tab reads the disk with isDirty;
    • a preview is read-only;
    • a preview whose source tab was closed still reads, read-only;
    • an untitled tab is read-only and its save writes nothing;
    • an untitled tab with no file on disk: the read fails, and the save makes no file;
  • without a window: an existing untitled file saves as an ordinary file; a missing one fails and is never created.

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):
    • A tab with unsaved desktop edits: the desktop types into a Markdown file without saving. The phone reads the disk with isDirty: true and saves. The disk changes, the banner shows, and the desktop's draft, dirty flag and editor text are unchanged.
    • An untitled document: the phone reads it read-only with 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 for src/main/runtime, src/main/persistence, src/renderer/src/runtime and src/renderer/src/components/terminal-pane compared 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-markdown on Electron and a freshly built orcad, and both desktop-window-mobile-markdown cases.

Known limit: a Markdown file on a paired server is previewed up to 512 KiB, the server's files.read reply cap, against 2 MiB locally. Larger files are marked truncated, with their real size.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • fix(mobile): create and edit notes on headless hosts #31291 (merged to main meanwhile): it added a separate windowless Markdown read/save (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.
  • Mixed versions: the phone's request and reply shapes are unchanged. The listing's new isUntitled field is optional and additive.
  • Older paired servers: they keep working through the same compare-then-write fallback the desktop editor uses.
  • SSH: raw ssh: hosts stay refused. A managed SSH host is reached as runtime:<env> and works through its server.
  • Folder workspaces: these go through the same file path.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • 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)

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

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 770ec11d-1d6a-469f-bc04-b491a9ad56c5
📥 Commits

Reviewing files that changed from the base of the PR and between 148c6b5 and 0078844.

📒 Files selected for processing: 9
  • src/main/runtime/markdown-tab-disk-documents.test.ts
  • src/main/runtime/markdown-tab-disk-documents.ts
  • src/main/runtime/markdown-tab-disk-host.ts
  • src/main/runtime/orca-runtime-mobile-markdown-tab-routes.test.ts
  • src/main/runtime/workspaces/workspace-file-session-targets.ts
  • src/renderer/src/runtime/sync-runtime-graph/mobile-session-editor-tabs.test.ts
  • src/renderer/src/runtime/sync-runtime-graph/mobile-session-editor-tabs.ts
  • src/shared/runtime-mobile-session-tab-contracts.ts
  • tests/e2e/desktop-window-mobile-markdown.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

📝 Walkthrough

Mobile Markdown reads and saves now use main-runtime disk operations instead of renderer request relays. The runtime routes local and paired-runtime file operations, validates listed tabs, enforces size and version checks, and supports conditional writes. Renderer relay APIs and mobile-specific editor rollback handling were removed. Tests cover disk conflicts, desktop drafts, untitled tabs, paired runtimes, and headless Electron and Orcad operation.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 00788

Phones can now read and save Markdown tabs on headless servers, with stale saves rejected as conflicts. Two small gaps remain open. Workflow runs that target only the new headless spec may skip its orcad case. A binary file with an unusual extension on a paired server may also be offered to the phone as editable text. Both are limited in scope and suit owner follow-up or a quick fix before merge.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 29.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 44 functions across 19 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Warning The description is detailed and covers the required change, rationale, testing, visual proof, review notes, and checklist. However, the required Linked Issue section states “No issue” and does not pro… Add a valid linked issue in the Linked Issue section using the required Fixes #<issue-number> format. If the author is a maintainer, reference the applicable pre-existing issue instead of stating that no issue exists.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: enabling phones to read and save Markdown tabs on headless servers.
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.
Full details: Description check

Explanation

The description is detailed and covers the required change, rationale, testing, visual proof, review notes, and checklist. However, the required Linked Issue section states “No issue” and does not provide an actual issue link.

Resolution

Add a valid linked issue in the Linked Issue section using the required Fixes #&lt;issue-number&gt; format. If the author is a maintainer, reference the applicable pre-existing issue instead of stating that no issue exists.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8a76f8cd-7141-48bf-9f8f-686e62799eff
📥 Commits

Reviewing files that changed from the base of the PR and between e01a539 and 520ef67.

📒 Files selected for processing: 7
  • src/main/runtime/files/file-reads.ts
  • src/main/runtime/headless-markdown-tab-documents.test.ts
  • src/main/runtime/headless-markdown-tab-documents.ts
  • src/main/runtime/mobile-session-editor-projection.ts
  • src/main/runtime/workspaces/workspace-file-session-targets.ts
  • tests/e2e/headless-serve-mobile-markdown.spec.ts
  • tests/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.

@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


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 416de805-a6b6-4d82-908a-5fd95cb1e56d
📥 Commits

Reviewing files that changed from the base of the PR and between f084719 and b67f0ac.

📒 Files selected for processing: 2
  • .github/workflows/e2e.yml
  • src/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.

Comment thread .github/workflows/e2e.yml
Comment on lines +489 to +492
- name: Phone Markdown on headless orcad serve
if: >-
!cancelled() &&
(inputs.test_files == '' || contains(inputs.test_files, 'tests/e2e/headless-serve-mobile-markdown.spec.ts'))

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.

🎯 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')

E2E Test and others added 8 commits October 20, 2026 07:58
…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.

@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


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1c59ee54-60ee-4e9c-983b-010340e1ab42
📥 Commits

Reviewing files that changed from the base of the PR and between b67f0ac and 148c6b5.

📒 Files selected for processing: 31
  • .github/workflows/e2e.yml
  • src/main/runtime/markdown-tab-disk-documents.test.ts
  • src/main/runtime/markdown-tab-disk-documents.ts
  • src/main/runtime/markdown-tab-disk-host.ts
  • src/main/runtime/orca-runtime-mobile-markdown-tab-routes.test.ts
  • src/main/runtime/runtime-notifier-contract.ts
  • src/main/runtime/workspaces/workspace-file-session-targets.ts
  • src/main/window/mobile-markdown-request-relay.test.ts
  • src/main/window/mobile-markdown-request-relay.ts
  • src/main/window/runtime-window-lifecycle-file-open.test.ts
  • src/main/window/runtime-window-lifecycle.ts
  • src/main/window/runtime-window-pane-title-notification.test.ts
  • src/preload/api/ui-bridge-clipboard-and-window-controls.ts
  • src/preload/api/ui-command-event-api.ts
  • src/renderer/src/components/editor/editor-autosave-controller.ts
  • src/renderer/src/components/editor/editor-autosave.ts
  • src/renderer/src/components/editor/editor-clean-tab-draft-invariant.test.ts
  • src/renderer/src/components/editor/editor-save-disk-precondition.ts
  • src/renderer/src/components/editor/editor-save-queue.ts
  • src/renderer/src/components/editor/editor-save-shared-model-dirty.test.ts
  • src/renderer/src/components/editor/editor-save-shared-model.test.ts
  • src/renderer/src/hooks/ipc-events/app-lifetime-ipc-bridge.ts
  • src/renderer/src/runtime/editor-buffer-dirty-readers.test.ts
  • src/renderer/src/runtime/mobile-markdown-bridge-save-guards.test.ts
  • src/renderer/src/runtime/mobile-markdown-bridge-test-harness.ts
  • src/renderer/src/runtime/mobile-markdown-bridge.test.ts
  • src/renderer/src/runtime/mobile-markdown-bridge.ts
  • src/renderer/src/runtime/mobile-markdown-save-rollback.ts
  • src/renderer/src/web/preload-api/web-ui-api.ts
  • src/shared/mobile-markdown-document.ts
  • tests/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.

Comment on lines +119 to +127
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 }
}

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.

🗄️ 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 -80

Repository: 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 1

Repository: 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 1

Repository: 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

Jinwoo-H and others added 8 commits October 20, 2026 15:52
… 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.
#31313 renamed a flush call inside the removed renderer Markdown bridge; the bridge stays deleted.

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

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.

nwparker added a commit that referenced this pull request Oct 21, 2026
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.
@Jinwoo-H
Jinwoo-H merged commit b99552c into main Oct 21, 2026
54 checks passed
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