Skip to content

fix(mobile): stop review notes from disappearing or coming back after deletion - #31699

Merged
AmoabaKelvin merged 8 commits into
stablyai:mainfrom
nwparker:nwparker/mobile-monkey-review-note-order
Oct 29, 2026
Merged

AmoabaKelvin merged 8 commits into
stablyai:mainfrom
nwparker:nwparker/mobile-monkey-review-note-order

Conversation

@nwparker

@nwparker nwparker commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​395 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​393
Prod 18 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​792 $\color{#cf222e}{\Huge{\mathbf{−}}}$​455 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​337

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.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 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
@AmoabaKelvin
AmoabaKelvin force-pushed the nwparker/mobile-monkey-review-note-order branch from e7e3ebe to c5b7d63 Compare October 28, 2026 22:41
@AmoabaKelvin
AmoabaKelvin marked this pull request as ready for review October 28, 2026 23:16
@coderabbitai

coderabbitai Bot commented Oct 28, 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
  • 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: 8be76cae-d022-456a-9ef1-73740c515990
Commits

Reviewing files that changed from the base of the PR and between 16d1a71 and 8326998.

Files selected for processing: 1
  • mobile/src/session/use-mobile-session-diff-comments.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.

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: 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 describes the main change: preventing mobile review notes from disappearing or reappearing after deletion.
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.
Description check Passed 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The PR changes how review notes are saved across mobile and host workflows.

The PR still needs the earlier review-screen fix before merging because overlapping saves can leave deleted notes visible.

Findings

  1. P1 Deleted notes stay visible ▶

Summary

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]
Loading

Reviews (7) · Last reviewed commit: "fix(mobile): send each review-note save ..." · Reviewed by Greptile

@AmoabaKelvin
AmoabaKelvin force-pushed the nwparker/mobile-monkey-review-note-order branch from ad920c8 to 0fa79ec Compare October 28, 2026 23:26
AmoabaKelvin and others added 4 commits October 28, 2026 23:32
…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.
@AmoabaKelvin
AmoabaKelvin force-pushed the nwparker/mobile-monkey-review-note-order branch from 0fa79ec to efc167b Compare October 28, 2026 23:32

@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: 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: 8a4ca9a7-275e-4987-b919-703e3eb6259f
Commits

Reviewing files that changed from the base of the PR and between cc3b3fb and 0fa79ec.

Files selected for processing: 18
  • mobile/rpc-foundation/goldens/matrix-session.diff-review-actions-worktree.set-1.json
  • mobile/rpc-foundation/goldens/review-mark-reviewed-persists.json
  • mobile/rpc-foundation/goldens/review-mark-reviewed-rolls-back.json
  • mobile/rpc-foundation/pilot-scenarios.json
  • mobile/src/session/mobile-review-notes-host-merge.test.tsx
  • mobile/src/session/mobile-session-diff-notes-new-agent-send.test.ts
  • mobile/src/session/mobile-session-write-operations.ts
  • mobile/src/session/use-mobile-diff-review-comment-actions.ts
  • mobile/src/session/use-mobile-session-diff-comments.ts
  • src/main/persistence/loading-store/metadata-lineage-operations.ts
  • src/main/persistence/loading-store/worktree-identity-metadata.ts
  • src/main/persistence/loading-store/worktree-meta-write-normalization.test.ts
  • src/main/persistence/loading-store/worktree-meta-write-normalization.ts
  • src/main/runtime/rpc/methods/worktree-set-method.test.ts
  • src/main/runtime/rpc/methods/worktree-set-method.ts
  • src/main/runtime/rpc/methods/worktree.ts
  • src/shared/diff-comment-mutation.ts
  • src/shared/rpc-contract/worktree-params.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.

Comment on lines 64 to 108
@@ -93,7 +98,11 @@ export function useMobileDiffReviewCommentActions(input: CommentActionsInput) {
const previous = screenState
updateReadyState((state) => ({ ...state, comments, reviewState }))
try {
await persistMetadata(comments, reviewState)
await persistMetadata(
comments,
previous.kind === 'ready' ? previous.comments : comments,
reviewState
)
triggerSuccess()
} catch (err) {
if (previous.kind === 'ready') {

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.

Minor · Data Integrity & Integration · Quick win

Supported by static analysis

Script executed:

sed -n '1,240p' mobile/src/session/use-mobile-diff-review-comment-actions.ts
sed -n '1,150p' src/shared/diff-comment-mutation.ts

Repository: stablyai/orca

Length of output: 9009


Script executed:

set -o pipefail
printf '%s\n' '--- write operation and callers ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'sessionWorktreeNotesWrite' -e 'saveCommentsAndReviewState' -e 'diffCommentsBase' mobile src | head -240
printf '%s\n' '--- write operation definition ---'
rg -n -F --glob '*.ts' --glob '*.tsx' 'sessionWorktreeNotesWrite' mobile/src/session
printf '%s\n' '--- host merge implementation and tests ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'mergeDiffCommentMutation' -e 'mobileDiffReview' -e 'diffCommentsBase' src mobile | head -320
printf '%s\n' '--- relevant file tails ---'
sed -n '200,520p' mobile/src/session/use-mobile-diff-review-comment-actions.ts

Repository: stablyai/orca

Length of output: 18392


Script executed:

set -o pipefail
printf '%s\n' '--- callers and operation definition ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'sessionWorktreeNotesWrite' -e 'saveCommentsAndReviewState' -e 'diffCommentsBase' mobile src | head -260
printf '%s\n' '--- hook remainder ---'
sed -n '200,500p' mobile/src/session/use-mobile-diff-review-comment-actions.ts
printf '%s\n' '--- operation owner candidates ---'
rg -n -F --glob '*.ts' --glob '*.tsx' 'worktree.set' src mobile | head -160

Repository: stablyai/orca

Length of output: 22701


Script executed:

set -o pipefail
printf '%s\n' '--- operation definition and callers ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'sessionWorktreeNotesWrite' -e 'saveCommentsAndReviewState' -e 'diffCommentsBase' mobile src | head -300
printf '%s\n' '--- hook remainder ---'
sed -n '200,520p' mobile/src/session/use-mobile-diff-review-comment-actions.ts
printf '%s\n' '--- worktree set handlers ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'worktree.set' -e 'diffCommentsBase' src mobile | head -220

Repository: stablyai/orca

Length of output: 24766


Script executed:

set -o pipefail
printf '%s\n' '--- deferred operation and note writer ---'
sed -n '1,180p' mobile/src/session/mobile-session-write-operations.ts
sed -n '1,180p' mobile/src/session/use-mobile-session-diff-comments.ts
printf '%s\n' '--- host RPC and normalizer ---'
sed -n '1,110p' src/main/runtime/rpc/methods/worktree-set-method.ts
sed -n '1,110p' src/main/persistence/loading-store/worktree-meta-write-normalization.ts
printf '%s\n' '--- relevant review merge test ---'
sed -n '1,310p' mobile/src/session/mobile-review-notes-host-merge.test.tsx
printf '%s\n' '--- deferred binding definition ---'
rg -n -F --glob '*.ts' -e 'function bindDeferredRpcOperation' -e 'const bindDeferredRpcOperation' -e 'bindDeferredRpcOperation' mobile/src | head -100

Repository: stablyai/orca

Length of output: 38952


Script executed:

set -o pipefail
sed -n '1,180p' mobile/src/session/mobile-session-write-operations.ts
sed -n '1,180p' mobile/src/session/use-mobile-session-diff-comments.ts
sed -n '1,110p' src/main/runtime/rpc/methods/worktree-set-method.ts
sed -n '1,110p' src/main/persistence/loading-store/worktree-meta-write-normalization.ts
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'bindDeferredRpcOperation' -e 'mobileDiffReview' -e 'diffCommentsBase' mobile/src/session src/main/persistence src/main/runtime | head -240

Repository: stablyai/orca

Length of output: 31159


Script executed:

set -o pipefail
printf '%s\n' '--- deferred RPC binding ---'
rg -n -F --glob '*.ts' -e 'export function bindDeferredRpcOperation' -e 'function bindDeferredRpcOperation' -e 'bindDeferredRpcOperation<' mobile/src/transport src | head -80
sed -n '1,280p' mobile/src/transport/rpc-operation.ts
printf '%s\n' '--- managed worktree update ---'
rg -n -F --glob '*.ts' -e 'updateManagedWorktreeMeta' src/main | head -60

Repository: stablyai/orca

Length of output: 15536


Script executed:

set -o pipefail
rg -n -F --glob '*.ts' -e 'bindDeferredRpcOperation' mobile/src/transport src | head -120
sed -n '1,320p' mobile/src/transport/rpc-operation.ts
rg -n -F --glob '*.ts' 'updateManagedWorktreeMeta' src/main | head -80

Repository: stablyai/orca

Length of output: 17559


Script executed:

set -o pipefail
sed -n '90,175p' src/main/runtime/workspaces/workspace-metadata.ts
rg -n -F --glob '*.ts' -e 'mergeWorktreeMetaForWrite' -e 'updateManagedWorktreeMeta(' src/main/runtime/workspaces src/main | head -100

Repository: stablyai/orca

Length of output: 10649


Script executed:

set -o pipefail
rg -n -F --glob '*.ts' -e 'updateRuntimeManagedWorktreeMetadata' src/main

Repository: stablyai/orca

Length of output: 1557


Script executed:

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.

Comment on lines 36 to 140
const [sendingDiffCommentIds, setSendingDiffCommentIds] = useState<ReadonlySet<string>>(
sendingDiffCommentIdsRef.current
)
const loadDiffComments = useCallback(async (): Promise<void> => {
if (!client || connState !== 'connected' || !worktreeId || isFloatingWorkspaceRoute) {
setDiffComments([])
return
}
const response = sessionWorktreeRecordRead.interpret(
await sessionWorktreeRecordRead.request(client, { worktree: `id:${worktreeId}` })
)
if (!response.accepted) {
return
}
setDiffComments(normalizeMobileDiffComments(response.value?.diffComments, worktreeId))
}, [client, connState, worktreeId, isFloatingWorkspaceRoute])
// Why: one notes request at a time, so each reply already holds this phone's earlier saves.
const notesQueueRef = useRef<Promise<unknown>>(Promise.resolve())
const failedSavesRef = useRef(0)
const enqueueNotesRequest = useCallback(function enqueueNotesRequest<T>(
run: () => Promise<T>
): Promise<T> {
const result = notesQueueRef.current.then(run)
notesQueueRef.current = result.catch(() => undefined)
return result
}, [])
const publishDiffComments = useCallback(
(comments: DiffComment[]): void => {
// Why: a second tap in the same frame must build on this list, not the last rendered one.
diffCommentsRef.current = comments
setDiffComments(comments)
},
[diffCommentsRef, setDiffComments]
)
// Shows the host's notes plus whatever the phone changed after `sent` was current.
const adoptHostDiffComments = useCallback(
(sent: readonly DiffComment[], host: unknown): void => {
const hostComments = normalizeMobileDiffComments(host, worktreeId)
publishDiffComments(mergeDiffCommentMutation(sent, hostComments, diffCommentsRef.current))
},
[diffCommentsRef, publishDiffComments, worktreeId]
)

const persistDiffComments = useCallback(
async (comments: readonly DiffComment[]): Promise<void> => {
if (!client || connState !== 'connected') {
throw new Error('Waiting for desktop...')
const loadDiffComments = useCallback(
(): Promise<void> =>
enqueueNotesRequest(async () => {
if (!client || connState !== 'connected' || !worktreeId || isFloatingWorkspaceRoute) {
publishDiffComments([])
return
}
const start = diffCommentsRef.current
const response = sessionWorktreeRecordRead.interpret(
await sessionWorktreeRecordRead.request(client, { worktree: `id:${worktreeId}` })
)
if (response.accepted) {
adoptHostDiffComments(start, response.value?.diffComments)
}
}),
[
client,
connState,
worktreeId,
isFloatingWorkspaceRoute,
diffCommentsRef,
enqueueNotesRequest,
publishDiffComments,
adoptHostDiffComments
]
)

// Shows `next` at once, then the host's merged list; on failure undoes only this change.
const saveDiffComments = useCallback(
async (next: DiffComment[]): Promise<void> => {
const base = diffCommentsRef.current
const failedSaves = failedSavesRef.current
publishDiffComments(next)
try {
await enqueueNotesRequest(async () => {
// Why: this list was built on a change that failed; an older host would store it whole.
if (failedSaves !== failedSavesRef.current) {
throw new Error('Failed to save review notes')
}
if (!client || connState !== 'connected') {
throw new Error('Waiting for desktop...')
}
const response = await sessionWorktreeNotesWrite.request(client, {
worktree: `id:${worktreeId}`,
diffComments: [...next],
diffCommentsBase: [...base]
})
const saved = interpretOrThrowRefusalMessage(
() => sessionWorktreeNotesWrite.interpret(response),
'Failed to save review notes'
)
if (saved?.diffComments !== undefined) {
adoptHostDiffComments(next, saved.diffComments)
}
})
} catch (err) {
if (failedSaves === failedSavesRef.current) {
failedSavesRef.current += 1
}
publishDiffComments(mergeDiffCommentMutation(next, diffCommentsRef.current, base))
throw err
}
const response = await sessionWorktreeNotesWrite.request(client, {
worktree: `id:${worktreeId}`,
diffComments: [...comments]
})
interpretOrThrowRefusalMessage(
() => sessionWorktreeNotesWrite.interpret(response),
'Failed to save review notes'
)
},
[client, connState, worktreeId]
[
client,
connState,
worktreeId,
diffCommentsRef,
enqueueNotesRequest,
publishDiffComments,
adoptHostDiffComments
]
)

useEffect(() => {

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.

Minor · Data Integrity & Integration · Quick win

Supported by static analysis

Script executed:

sed -n '1,310p' mobile/src/session/use-mobile-session-diff-comments.ts

Repository: stablyai/orca

Length of output: 9905


Script executed:

set -o pipefail
rg -n -F --glob '*.{ts,tsx}' \
  -e 'useMobileSessionDiffComments' \
  -e 'MobileSessionDocumentReadersModel' \
  -e 'diffCommentsRef' \
  mobile/src mobile/app | head -240
printf '\n--- related tests/files ---\n'
rg --files mobile/src mobile/app | rg 'mobile-session.*(diff|route|document)|diff-comments|review-notes' | head -160

Repository: stablyai/orca

Length of output: 6079


Script executed:

set -o pipefail
rg -n -F --glob '*.{ts,tsx}' \
  -e 'useMobileSessionDiffComments' \
  -e 'MobileSessionDocumentReadersModel' \
  -e 'diffCommentsRef' \
  mobile/src mobile/app | head -260
printf '\n--- candidate files ---\n'
rg --files mobile/src mobile/app | rg 'mobile-session.*(diff|route|document)|diff-comments|review-notes' | head -180

Repository: stablyai/orca

Length of output: 6075


Script executed:

set -o pipefail
printf '%s\n' '--- controller ---'
sed -n '1,125p' mobile/src/session/use-mobile-session-controller.ts
printf '%s\n' '--- document readers ---'
sed -n '1,235p' mobile/src/session/use-mobile-session-document-readers.ts
printf '%s\n' '--- screen state ---'
sed -n '1,205p' mobile/src/session/use-mobile-session-screen-state.ts
printf '%s\n' '--- review-note tests ---'
sed -n '1,360p' mobile/src/session/mobile-review-notes-host-merge.test.tsx
printf '%s\n' '--- route/controller mounting references ---'
rg -n -F --glob '*.{ts,tsx}' -e 'useMobileSessionController(' -e '<MobileSession' -e 'key={worktreeId}' -e 'key={client' mobile/src mobile/app | head -220

Repository: stablyai/orca

Length of output: 39681


Script executed:

set -o pipefail
printf '%s\n' '--- foundation ---'
sed -n '1,260p' mobile/src/session/use-mobile-session-foundation.ts
printf '%s\n' '--- route screen/route ---'
sed -n '1,220p' mobile/src/session/MobileSessionRouteScreen.tsx
sed -n '1,260p' mobile/src/session/mobile-session-route.ts
printf '%s\n' '--- route entry ---'
sed -n '1,160p' mobile/app/h/'[hostId]'/session/'[worktreeId]'.tsx 2>/dev/null || true
sed -n '1,160p' mobile/app/h/'[hostId]'/session/'[worktreeId]'.web.tsx
printf '%s\n' '--- foundation references ---'
rg -n -F --glob '*.{ts,tsx}' -e 'function useMobileSessionFoundation' -e 'worktreeId:' -e 'router.replace' -e 'router.push' -e 'MobileSessionRouteScreen' mobile/src mobile/app | head -260

Repository: stablyai/orca

Length of output: 38576


Script executed:

set -o pipefail
printf '%s\n' '--- native session route files ---'
rg --files mobile/app | rg '/session/\\[worktreeId\\](\\.|/)' | sort
printf '%s\n' '--- workspace route wrapper ---'
rg -n -F --glob '*.{ts,tsx}' -e 'function withWorkspaceRoute' -e 'const withWorkspaceRoute' -e 'export const withWorkspaceRoute' src mobile | head -40
printf '%s\n' '--- wrapper implementation ---'
file=$(rg -l -F --glob '*.{ts,tsx}' -e 'function withWorkspaceRoute' -e 'const withWorkspaceRoute' -e 'export const withWorkspaceRoute' src mobile | head -1)
if [ -n "$file" ]; then sed -n '1,240p' "$file"; fi
printf '%s\n' '--- native route candidates ---'
find mobile/app -path '*session*' -maxdepth 8 -type f -print | sort | head -80

Repository: stablyai/orca

Length of output: 3061


Script executed:

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.
Comment on lines +110 to +115
if (saved !== undefined) {
// Why: the host kept notes other devices changed; show its list unless a later save moved on.
updateReadyState((state) =>
state.comments === comments
? { ...state, comments: normalizeMobileDiffComments(saved, worktreeId) }
: state

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@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: 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: 7b2c7ab5-47e7-4f4f-9f73-07027afab4ef
Commits

Reviewing files that changed from the base of the PR and between 00aa3bf and 16d1a71.

Files selected for processing: 5
  • mobile/rpc-foundation/goldens/matrix-session.diff-notes-worktree.show-1.json
  • mobile/rpc-foundation/goldens/session-diff-notes-load-refused.json
  • mobile/rpc-foundation/goldens/session-diff-notes-loaded.json
  • mobile/src/session/mobile-session-diff-notes-new-agent-send.test.ts
  • mobile/src/session/use-mobile-session-diff-comments.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.

diffComments: [...save.next],
diffCommentsBase: [...save.base]
},
NOTES_REQUEST_OPTIONS

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.

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.
@AmoabaKelvin
AmoabaKelvin merged commit 5470ff9 into stablyai:main Oct 29, 2026
49 of 51 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