Skip to content

fix(mobile): keep file edits safe when previews load or refresh slowly - #31696

Merged
AmoabaKelvin merged 3 commits into
stablyai:mainfrom
nwparker:nwparker/mobile-monkey-file-preview-owner
Oct 28, 2026
Merged

AmoabaKelvin merged 3 commits into
stablyai:mainfrom
nwparker:nwparker/mobile-monkey-file-preview-owner

Conversation

@nwparker

@nwparker nwparker commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​153 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​153
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​46 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​37

ELI5

Open a file, edit it, and tap Save twice quickly. Before this follow-up, both taps could write the file. Now one save runs at a time, and text you type while it is saving stays available to save afterward. Slow preview replies also cannot replace edits belonging to another file or desktop.

What Changed

  • Allow only one file save at a time, including two taps before the screen rerenders.
  • Only let the latest preview load update the file on screen.
  • Keep unsaved text editable when the same file's details refresh.
  • Treat a different file or computer as a separate document, even if the path looks the same.

Why

A slow file read or background refresh should not undo your work or mix up files from different computers.

Linked Issue

Maintainer-discovered regression. Bounded GitHub symptom and exact-file searches found no exact duplicate. Related #24469 and #29096 concern rendering/navigation; this fixes load and draft ownership.

Visual Proof

Captured with the visual-proof skill. Before uses base 15246eb4a45; after uses this PR's standalone commit fce94316866. The scenario passed asserted capture runs 3 times per version before representative screenshots were selected. The captures were visually inspected.

Evidence scope: Actual production RN Web screen; truncated reconnect preserves draft. Other race cases in mounted tests.

01-before-preview-3.png 02-after-preview-3.png
(screenshot removed: contained real product data) (screenshot removed: contained real product data)

The hook/transport boundary harnesses are labeled in the captures. These are browser evidence where stated; they do not establish native keyboard, gesture, permission dialog, safe-area or real-network behavior. Full code regressions cover additional cases described above.

Follow-up before/after proof

Created with the visual-proof skill. Before source 3b987331c83e; after source 9622c261ab7e, included in the current head. Captured through headless Chromium CDP, with asserted outcomes in three runs per version. Representative screenshots were visually inspected.

Evidence scope: Production React Native Web file-preview screen with scripted read/write responses. The capture invokes the real Save handler twice before React rerenders; the diagnostic counter shows two desktop writes before and one after. This deliberately scripts same-frame taps and does not establish native touch behavior.

before.png after.png
(screenshot removed: contained real product data) (screenshot removed: contained real product data)

Testing

The combined review checkout aa6fe5dae109 contains this PR at 9622c261ab7e and the other mobile PRs reviewed together. Validation ran with ORCA_BACKGROUND_LAUNCH=1 on macOS.

  • Full mobile run: 11,493 passed, 2 failed, 6 skipped. Both failures were recording checks for the intentional new uncertain-paste warning. After updating only that golden, the affected two recording suites passed 1,197 tests, including both previously failing checks. This accounts for all 11,495 non-skipped tests; it is not a claim of a second clean full-suite invocation.
  • Production mobile typecheck and the test-typecheck ratchet passed (1,111 test files; 116 grandfathered).
  • Changed-code quality gate passed with zero new findings across eight code files, including React Doctor and design-system checks. Follow-up code formatting and lint checks passed.
  • Mobile web build and packaged asset verification passed. The package manager warned that its pre-script dependency refresh could not replace the shared node_modules symlink; the build and both asset verifiers nevertheless completed successfully.

An earlier attempt using the shared checkout’s newer Vitest crashed. The reported full run and recording recheck used the mobile package’s pinned Vitest 4.1.12 with four workers. These are combined-checkout results; separate CI must validate each PR against current main. Native-device coverage remains limited as described in Visual Proof and Review.

Rebase and review (2026-10-28)

Rebased onto current main (one mechanical conflict: main's new useMobileColorScheme() call moved into the inner document component). A Codex + Claude review round found no P0/P1. The one P3 was taken: the new early return for a dirty draft left an always-true if (!preserveDirtyDraft) guard, now removed. The added tests share one route and mount helper instead of repeating it (276 → 153 lines, same cases). Focused mobile suites pass: src/files (260 tests) and the RPC recording goldens (1,695 tests).

Risk-reduction checks

Second pass: Fixed two Save taps in the same frame sending two file writes. A synchronous save latch now permits one write. The regression also checks that typing during an earlier save remains unsaved and editable.

Current PR head: 9622c261ab7e. Combined review head: aa6fe5dae109.

CI status: the earlier locale issue #31747 has merged. This PR remains a draft; skipped draft workflows do not count as a fresh passing full CI run.

The new duplicate-Save regression failed before the fix (two actual writes) and passes afterward (one). The file suites passed 271 tests. Typing during a clean refresh did not reproduce a defect because that editor is hidden while the refresh loads.

AI Disclosure

Review

Merge risk: Medium. The editor handles unsaved work. Two clients saving the same file at the same moment could both pass the desktop's "file unchanged" check before either committed. That is a host-side race that already existed on main, fixed separately in #35418 (per-file write queue on the desktop, no wire change).

Previously reviewed by a separate agent team; this pass traced the production paths again and added failing-before regressions for the three newly reproduced defects.

Agent skill upstream boundary

  • Not applicable; this change copies no upstream skill-installer implementation.

Notes

Existing RPC methods and wire compatibility are retained. Review considered desktop host changes, remote execution authority, folder workspaces, and native/web consumers. Native simulator follow-up was limited after the three owned simulators became stuck shutting down; no unrelated simulator/process was reset.

Checklist

  • Focused change with a root-cause explanation.
  • Automated regression coverage and independent review.
  • Before/after proof attached with exact evidence scope.
  • Cross-platform and remote compatibility considered.
  • Required PR CI checks have passed.

@nwparker nwparker changed the title fix(mobile): preserve file drafts across refresh and reject stale reads fix(mobile): keep file edits safe when previews load or refresh slowly Oct 22, 2026
nwparker and others added 3 commits October 28, 2026 22:18
Overlapping preview reads overwrite current content, and refreshed metadata or equivalent route objects revoke dirty editor state. Keep document-owned drafts editable and accept only the current load.
@AmoabaKelvin
AmoabaKelvin force-pushed the nwparker/mobile-monkey-file-preview-owner branch from 9622c26 to b14c4b6 Compare October 28, 2026 22:19
@AmoabaKelvin
AmoabaKelvin marked this pull request as ready for review October 28, 2026 22:24
@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Keeps mobile file drafts separate by file and computer, ignores older preview replies, and blocks overlapping saves.

  • Only the newest file read can update the preview.
  • Unsaved file edits stay with their document.
  • The artifact editor starts only one save at a time.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Open or update preview] --> B{Same host and file?}
  B -- No --> C[Mount a separate document]
  B -- Yes --> D[Keep current draft]
  C --> E[Start preview read]
  D --> E
  E --> F{Latest read?}
  F -- No --> G[Ignore reply]
  F -- Yes --> H{Unsaved edits?}
  H -- Yes --> I[Keep editable draft]
  H -- No --> J[Show loaded file]
  K[Tap Save] --> L{Save already running?}
  L -- Yes --> M[Ignore extra tap]
  L -- No --> N[Check saved file and write]
  N --> O[Mark submitted text as saved]
Loading

Reviews (1) · Last reviewed commit: "refactor(mobile): drop the dead dirty-dr..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The preview document is keyed by host, execution host, and preview source. Preview loads use revision and source-key checks to ignore stale results. Dirty drafts remain unchanged for the tested refresh and route cases. Artifact saves use a ref to prevent concurrent writes. Tests cover load ordering, draft preservation, authority changes, and save behavior.

Priority: Normal

Merge Risk: Minimal · up to b14c4

No merge-blocking code defect was established. Required CI has not yet passed.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: protecting mobile file edits during slow preview loads or refreshes.
Description check Passed The description is detailed and covers the user impact, implementation, rationale, visual proof, testing, risks, compatibility, and review status. The linked issue section lists related issues but doe…
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 user impact, implementation, rationale, visual proof, testing, risks, compatibility, and review status. The linked issue section lists related issues but does not provide a direct Fixes # issue link, and required CI checks remain pending; these omissions do not make the otherwise complete description largely incomplete.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

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

Nitpick comments: 1
mobile/src/files/mobile-file-preview-retry.test.tsx: 1

262-280: Trivial · Maintainability & Code Quality · Quick win

Add a second save after the first write resolves.

The current test does not verify the conflict-check baseline used by the next save. Model the desktop content as First edit after the first write, then save Newer edit and assert that the second write occurs.

Suggested fix
   const pendingWrite = Promise.withResolvers<unknown>()
   const write = vi.fn(() => pendingWrite.promise)
+  let desktopContent = 'Original'
   serveReads((method) =>
-    method === 'files.writeTerminalArtifact' ? write() : Promise.resolve(previewReply('Original'))
+    method === 'files.writeTerminalArtifact'
+      ? write()
+      : Promise.resolve(previewReply(desktopContent))
   )
@@
   await act(async () => pendingWrite.resolve({ ok: true, id: 'save', result: { written: true } }))
+  desktopContent = 'First edit'
   expect(editor().props.value).toBe('Newer edit')
   expect(save().props.disabled).toBe(false)
+  await act(async () => save().props.onPress())
+  expect(write).toHaveBeenCalledTimes(2)

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8acf4642-6527-4cb4-a7c2-4746e34e80f6
Commits

Reviewing files that changed from the base of the PR and between 95a83cc and b14c4b6.

Files selected for processing: 2
  • mobile/src/files/MobileFilePreviewScreen.tsx
  • mobile/src/files/mobile-file-preview-retry.test.tsx

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

@AmoabaKelvin
AmoabaKelvin merged commit 8761934 into stablyai:main Oct 28, 2026
47 of 48 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