You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(mobile): stop review notes from disappearing or coming back after deletion - #31699
Review notes you add or delete on your phone could disappear or come back. The phone sent its whole notes list on every change, so anything it hadn't seen yet (like a note added on desktop) got overwritten. Now the phone says what it changed, and the desktop applies just that change to the notes it already has.
What Changed
The approach changed from the first version of this PR. That version serialized the phone's own writes with a queue and a load baseline, but two devices still overwrote each other's notes, which was the main way notes vanished. This version fixes it where the notes are stored.
worktree.set takes an optional diffCommentsBase: the list the writer started from. The host applies only the writer's own adds, edits and removals to the notes it has stored, inside the synchronous store write (mergeDiffCommentMutation in src/shared/diff-comment-mutation.ts, applied in mergeWorktreeMetaForWrite). This is the same pattern the host already uses for linkedItemsBase.
The phone's session notes send that base and send one request at a time, like desktop's per-worktree save queue. The phone keeps the host's last list and its own unanswered saves, and shows the two combined (same merge). So a reply never hides a pending phone change or brings back a note desktop deleted. Each save is built when it is sent, as the host's last list plus only its own change. An older host that stores the whole list therefore never gets a failed save's change, and never loses the loaded notes when you add one before loading finishes. A failed save drops only its own change. Loads and saves fail at once while disconnected instead of stalling the queue, but delivered-note cleanup waits for the reconnect, so those notes aren't sent twice. All of this is per workspace and connection, so a late reply for another workspace is ignored.
The review screen's note and "mark reviewed" saves also send their base, so marking a file reviewed no longer wipes notes added elsewhere. After a save it shows the host's list, so an edit to a note desktop deleted doesn't look saved.
worktree.set moved unchanged into worktree-set-method.ts to keep worktree.ts under the line cap.
Before: add a note on desktop, then add or delete one on the phone, and the desktop note is gone. After: both stay.
Why
Notes you added should stay saved, and notes you deleted should stay deleted, whichever device made the change.
Mixed versions keep working. An older desktop drops the unknown field and replaces the list exactly as it does today. An older phone sends no base and gets the same whole-list replace. The new field is optional and never stored. A host-side merge covers every writer that sends a base. New per-note RPC methods would have needed a method-not-found fallback on the phone.
Linked Issue
Maintainer-discovered regression; no issue. Related #31291 (headless review-note support).
Visual Proof
N/A: no UI change. The notes list looks the same; what changes is which notes survive. Proof is the tests below and the real-host RPC check.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
mobile/src/session/mobile-review-notes-host-merge.test.tsx: drives the real notes hook against a fake host. It covers a desktop note surviving a later phone add and delete, two adds in the same frame, a save after a failed one sending only its own change, a note added before the first load on an older host, a slow first load not replacing a newer save, a save that failed before the first load returned not hiding the loaded notes, a delivered-note cleanup overlapping an add's save, a note desktop deleted while a phone save was queued, and the review screen showing the host's list after a save. These fail on main. Another shows that a host without the merge still gets the full list and replaces it as before.
worktree-meta-write-normalization.test.ts: the host merge keeps another device's note and never stores the base. A write with no base (an older phone) still replaces the list.
worktree-set-method.test.ts: worktree.set forwards the base.
RPC recordings updated for the review screen's new request param. Outcomes are unchanged.
Real hosts on macOS, raw RPC against a scratch repo. The installed 1.4.243 release played the old host and a serve built from this branch played the new one. Stored [A, D], then the phone sent [A, P] with base [A]:
Old host (1.4.243)
This branch
After the phone's add
[A, P]: D wiped, no error (same as today)
[A, D, P]
Phone deletes A (base [A, D, P])
[D, P]
[D, P]
AI Disclosure
Review
Carries Neil's PR forward with a different approach, chosen by Kelvin's coordinator after the risk review found that two clients still raced over the whole list. Neil is co-author on the commit.
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
Remote/SSH: the merge runs in the host's store write, so it's the same for local, SSH and headless hosts. Folder-repo workspaces go through the same worktree.set path.
The desktop app's own note writes still send whole lists through its per-worktree queue. Their only gap is a desktop write still in flight, which is left for a separate change.
No platform-specific code.
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)
nwparker
changed the title
fix(mobile): serialize review note mutations and reject stale snapshots
fix(mobile): stop review notes from disappearing or coming back after deletion
Oct 22, 2026
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
Walkthrough
The change adds diffCommentsBase to worktree writes and merges comment mutations with current worktree comments. The mobile comment hook queues reads and writes, publishes optimistic updates, and reconciles successful saves or removes failed mutations. The worktree.set handler moves to a dedicated module. Tests and recorded fixtures cover comment merging, mobile save behavior, and RPC settlement cases.
Priority: Normal
Merge Risk: Moderate · up to 83269
Resolve the legacy-host note loss and disconnected cleanup issues before merging to avoid disappearing or duplicate review notes.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
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 checks: 4 passed
Check name
Status
Explanation
Title check
The title clearly describes the main change: preventing mobile review notes from disappearing or reappearing after deletion.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description follows the repository template closely. It has an ELI5, a What Changed section with the mechanism, a Why section that compares alternatives, a Testing section with specific tests and …
Full details: Description check
Explanation
The description follows the repository template closely. It has an ELI5, a What Changed section with the mechanism, a Why section that compares alternatives, a Testing section with specific tests and a real-host RPC comparison, and Notes and Checklist sections. Two items need attention. The Linked Issue section has no Fixes # issue. It says the regression was maintainer-discovered and cites related #31291 only as related, so the template's issue requirement is not fully met. The AI Disclosure section is blank. The template says to fill it in unless the author is a StablyAI team member, and the author's status is not stated. The lint, typecheck, test, and build checkbox is unchecked, so those checks are not confirmed locally, though CI may cover them.
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 3 functions across 15 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.
The PR moves review-note merging into the host so phone changes preserve notes from other devices.
The host applies note changes to its current saved list.
Mobile session notes stay visible while saves finish.
Review-screen saves keep notes changed on another device.
No new findings were accepted in this review.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Phone changes notes] --> B[Show pending changes]
B --> C[Wait for earlier requests]
C --> D[Apply this change to last host list]
D --> E[Host merges with stored notes]
E --> F[Show returned notes plus pending changes]
…tion
The phone sent its whole notes list on every add or delete, and the host
stored it as is. A note added on desktop after the phone loaded was wiped
by the phone's next edit, two quick taps could overwrite each other, and a
failed save rolled back to an old snapshot.
worktree.set now takes an optional diffCommentsBase, like linkedItemsBase:
the host applies only the writer's own adds, edits and removals to the
stored notes. The phone sends the list it started from, shows the host's
merged list from the reply, and undoes only its own change on failure.
Older hosts drop the field and replace the list as before; older phones
send no base and get the same.
Co-authored-by: Neil <[email protected]>
The first load was discarded once any save started, so a save that failed
before it landed left the host's notes hidden. The load now applies the
phone's changes made during the read onto the host's list instead.
Two in-flight saves could reach the host in either order, so adopting the
later reply hid a note the earlier save had stored. Session notes now send
one request at a time and reconcile every reply with the phone's changes
made since it was sent, replacing the sequence counters.
A save queued behind one that failed still sent the list built on the
failed change, and an older host stores that list whole. Those saves now
undo their own change instead of sending. Also renames the shared base
type so it no longer shares a name with the renderer's mutation record.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
set -o pipefail
sed -n '1,190p' src/main/runtime/runtime-managed-worktree-metadata.ts
sed -n '1,150p' src/main/runtime/runtime-managed-worktree-metadata.test.ts
Repository: stablyai/orca
Length of output: 11254
Serialize review-screen metadata saves.
saveCommentsAndReviewState sends note and mark-reviewed updates directly. These requests can overlap. The host merges diffComments, but it replaces mobileDiffReview with the value from each request. If the note request is applied after the mark-reviewed request, its stale review state restores the previous state. Serialize both operations in one review-screen queue and build each queued request from the latest state.
set -o pipefail
printf'%s\n''--- matching route files ---'
find mobile/app -type f -path '*/session/*' -print | sort
printf'%s\n''--- wrapper locations ---'
rg -l -F --glob '*.{ts,tsx}''withWorkspaceRoute' src mobile | head -30
printf'%s\n''--- wrapper definitions ---'
rg -n -F --glob '*.{ts,tsx}' \
-e 'function withWorkspaceRoute' \
-e 'const withWorkspaceRoute' \
-e 'export function withWorkspaceRoute' \
-e 'export const withWorkspaceRoute' \
src mobile | head -80
Repository: stablyai/orca
Length of output: 1118
Guard queued note work against the current session target.
The native session route keeps MobileSessionRouteScreen mounted while useLocalSearchParams changes worktreeId. The notes queue survives that change. A callback created for the former worktree can therefore send its queued save to the former target, or publish its response through the new worktree's shared diffCommentsRef.
Capture the target for each queued operation. Skip the operation when the captured client or worktree is no longer current. Apply the same guard before publishing success or failure results.
A queued reply was reconciled against the list captured at tap time, so a
note desktop deleted meanwhile came back on the phone. The phone now keeps
the host's last list and its unanswered saves per workspace and shows the
two combined; a reply for another workspace is ignored. The review screen
also shows the host's list after a save, so an edit to a note desktop
deleted no longer looks saved.
The reason will be displayed to describe this comment to others. Learn more.
Deleted notes stay visible
Two overlapping review saves can share the same comments array. For example, tap “Mark Reviewed,” then “Mark Unreviewed” before the first save replies. The first reply replaces that array, so state.comments === comments rejects the second reply even though no later note edit happened.
If desktop deletes a note between those requests, the phone can keep showing, copying, or sending the deleted note. Track each pending save separately instead of using the array reference to decide which reply to accept.
A notes request queued behind a pending load waited for a reconnect with
no timeout, holding every later save. Notes requests now fail at once when
the connection is down, like terminal input.
… one
A save made while a dropped save was still pending carried its change,
so an older host could store it. Each failed or dropped save now moves
the failure count.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Data Integrity & Integration · Heavy lift
Retain delivered-note cleanup across disconnects.
If prompt delivery succeeds while a notes read is queued, a disconnect can make this cleanup request reject immediately. clearDeliveredDiffComments swallows the error, so the delivered notes remain stored and can be sent again without warning. The send action invokes cleanup after confirmed delivery. (raw.githubusercontent.com)
Retain the cleanup for reconciliation after reconnect, without blocking the request queue, or report the failure to the user.
…hange
Each queued save now builds its payload when it is sent, from the host's
last list plus only its own change. A note added before the first load
no longer replaces the loaded notes on an older host, and a failed save's
change never rides along, so later saves no longer need dropping.
Delivered-note cleanup waits for a reconnect again so those notes are not
sent twice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
Review notes you add or delete on your phone could disappear or come back. The phone sent its whole notes list on every change, so anything it hadn't seen yet (like a note added on desktop) got overwritten. Now the phone says what it changed, and the desktop applies just that change to the notes it already has.
What Changed
The approach changed from the first version of this PR. That version serialized the phone's own writes with a queue and a load baseline, but two devices still overwrote each other's notes, which was the main way notes vanished. This version fixes it where the notes are stored.
worktree.settakes an optionaldiffCommentsBase: the list the writer started from. The host applies only the writer's own adds, edits and removals to the notes it has stored, inside the synchronous store write (mergeDiffCommentMutationinsrc/shared/diff-comment-mutation.ts, applied inmergeWorktreeMetaForWrite). This is the same pattern the host already uses forlinkedItemsBase.worktree.setmoved unchanged intoworktree-set-method.tsto keepworktree.tsunder the line cap.Before: add a note on desktop, then add or delete one on the phone, and the desktop note is gone. After: both stay.
Why
Notes you added should stay saved, and notes you deleted should stay deleted, whichever device made the change.
Mixed versions keep working. An older desktop drops the unknown field and replaces the list exactly as it does today. An older phone sends no base and gets the same whole-list replace. The new field is optional and never stored. A host-side merge covers every writer that sends a base. New per-note RPC methods would have needed a method-not-found fallback on the phone.
Linked Issue
Maintainer-discovered regression; no issue. Related #31291 (headless review-note support).
Visual Proof
N/A: no UI change. The notes list looks the same; what changes is which notes survive. Proof is the tests below and the real-host RPC check.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
mobile/src/session/mobile-review-notes-host-merge.test.tsx: drives the real notes hook against a fake host. It covers a desktop note surviving a later phone add and delete, two adds in the same frame, a save after a failed one sending only its own change, a note added before the first load on an older host, a slow first load not replacing a newer save, a save that failed before the first load returned not hiding the loaded notes, a delivered-note cleanup overlapping an add's save, a note desktop deleted while a phone save was queued, and the review screen showing the host's list after a save. These fail on main. Another shows that a host without the merge still gets the full list and replaces it as before.worktree-meta-write-normalization.test.ts: the host merge keeps another device's note and never stores the base. A write with no base (an older phone) still replaces the list.worktree-set-method.test.ts:worktree.setforwards the base.RPC recordings updated for the review screen's new request param. Outcomes are unchanged.
Real hosts on macOS, raw RPC against a scratch repo. The installed 1.4.243 release played the old host and a serve built from this branch played the new one. Stored
[A, D], then the phone sent[A, P]with base[A]:[A, P]: D wiped, no error (same as today)[A, D, P][A, D, P])[D, P][D, P]AI Disclosure
Review
Carries Neil's PR forward with a different approach, chosen by Kelvin's coordinator after the risk review found that two clients still raced over the whole list. Neil is co-author on the commit.
Agent skill upstream boundary
Notes
worktree.setpath.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)