Skip to content

fix(session): defer session writes suppressed by a direct-SSH apply instead of dropping them - #16969

Merged
nwparker merged 1 commit into
mainfrom
nwparker/defer-session-writes-during-ssh-apply
Aug 28, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/defer-session-writes-during-ssh-apply

Conversation

@nwparker

@nwparker nwparker commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​577 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​571
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​117 $\color{#cf222e}{\Huge{\mathbf{−}}}$​38 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​79

Session writes suppressed during an SSH apply were discarded, not deferred

User-visible symptom

Close a terminal tab (or rename one, move one between groups, change the active workspace — any durable session edit) in the ~30 seconds after an SSH workspace connects or reconnects, and the edit could be silently lost. Nothing tells you: the UI shows the tab gone, the session file on disk still has it, and the next launch brings it back.

The worst version is the one PR #16752 just built machinery for. Closing an SSH tab writes two pieces of durable state: the tab's removal and a closed-tab tombstone, which is the client's only record that "the user closed this" for the direct-SSH pull merge. Both live in the same session state. A close made inside the suppression window lost both, so the tab came back on the next reconnect and the tombstone that was supposed to make the close stick was never written. That window is open on every connect and every reconnect — which is precisely when a user is looking at phantom tabs and cleaning them up.

Root cause

src/renderer/src/lib/session-write-subscriber.ts is the debounced Zustand → disk session writer. It tracks which session fields changed in pendingChangedFields, and detects change by object identity against a baseline: prev?.[key] !== next[key].

On origin/main it advanced that baseline before consulting the persist gate:

  • session-write-subscriber.ts:136 — prev = next
  • session-write-subscriber.ts:140-146 — gate closed at change time → pendingChangedFields.clear()
  • session-write-subscriber.ts:162-164 — debounce fired but shouldPersistWorkspaceSession(fresh) false → pendingChangedFields.clear()
  • session-write-subscriber.ts:165-168 — debounce fired but shouldSchedulePersist() false → pendingChangedFields.clear()

Once prev has advanced, the identity comparison for that field will never differ again. Clearing it from the pending set therefore does not delay the write — it destroys it. The only recovery is an unrelated future mutation of the same field, or a clean quit (the shutdown checkpoint writes the whole payload); a crash, kill, or forced update in between loses it for good.

The gate that trips this is shouldSchedulePersist: () => !isDirectSshRemoteWorkspaceApplyInProgress() (src/renderer/src/app-shell/use-app-session-persistence.ts:89), and it is closed for the whole snapshot apply — bounded by SNAPSHOT_TERMINAL_RECONNECT_TIMEOUT_MS (30s) — plus a 1s REMOTE_WORKSPACE_SNAPSHOT_WRITE_SUPPRESS_MS tail (src/renderer/src/hooks/remote-workspace-snapshot-apply.ts:22-27).

Cross-target variant: that flag is a module-level global, not per target. Target A reconnecting suppresses writes for every other target, so a tab closed on target B during A's apply is lost too, even though B was never involved.

The fix

Defer, never discard.

  1. pendingChangedFields is no longer cleared on a closed gate. It is cleared only when a write is actually issued (or on unsubscribe). It is the sole record that a mutation still owes a write, and it is bounded by SESSION_RELEVANT_FIELDS (31 entries).
  2. The store-update early return changed from changedFields.length === 0 to changedFields.length === 0 && pendingChangedFields.size === 0, so any subsequent store notification can wake a deferred write — not just one that touches the same field again.
  3. The gate owner now emits a one-shot wake-up. onDirectSshRemoteWorkspaceApplyWindowClosed (src/renderer/src/hooks/remote-workspace-snapshot-apply.ts) fires a single setTimeout per apply, scheduled at the exact suppression deadline, and use-app-session-persistence.ts wires it into the subscriber as subscribeToPersistGateOpen.

Values are never deferred — only the field selection is. Every flush rebuilds the patch from store.getState(), so a deferred write publishes current post-merge state and can never resurrect a pre-apply value over what the host just sent.

The three hazards, and which choice addresses each

The brief called these out explicitly, so here they are one by one.

1. No unbounded loop if the gate never opens. Nothing in flushPendingWrite re-arms. A timer is armed by exactly two things: a real session-field change, or the one-shot gate-open notice. If shouldPersistWorkspaceSession stays false forever (a hydration failure — issue #1158 says that state must never be written), the pending set just sits there costing nothing: no timer, no poll, no retry budget to get wrong. Locked by the test arms no timer while the gate stays closed, which asserts vi.getTimerCount() === 0 after 10s with the gate shut.

2. No lost wake-up when the gate opens with nothing else happening. The shouldPersistWorkspaceSession gate lives in store state, so its reopening is a store notification and (2) above catches it. The SSH gate does not: its tail expires on a wall clock with no store write behind it. That is why the notice is emitted by the gate owner rather than polled by the subscriber — it fires at the deadline, once, from the code that knows the deadline. Overlapping applies are safe: a notice that finds the window still shut returns without notifying, and the later apply schedules its own.

3. No discarded mutation. The pending set is retired only on the path that calls persist.

Deliberately not built: a retry chain, a backoff ladder, an attempt budget, or a re-armed poll. This subsystem produced twelve defects across five review rounds in exactly that shape earlier today. There is one timer here and it is the pre-existing debounce.

Performance property preserved

The comment at the top of the subscriber documents why unrelated updates (agent status, usage refreshes, title ticks) must not reset the debounce: they used to, and the eventual payload build crossed 70-110ms and tripped setTimeout violations. An unrelated update can now arm a flush when work is owed, but if (timer !== null && changedFields.length === 0) return stops it from ever resetting one. Covered by does not let an unrelated update reset the debounce of a deferred write.

ELI5

Think of the app as a person writing your notes into a notebook.

Every time you change something, they jot the change on a sticky note ("tab closed"), and a moment later copy it into the notebook. But while the app is syncing with an SSH machine, the notebook is held shut for up to half a minute.

The old behavior: they'd look at the shut notebook, throw the sticky note in the bin, and — this is the bad part — also tick the change off their checklist as handled. So when the notebook opened again, nobody remembered anything was owed. Your closed tab came back the next time you launched the app, as if you had never closed it.

The new behavior: they keep the sticky note. When the notebook opens, they write it in. And because the notebook can open on a timer with nothing else happening to remind them, the sync itself now taps them on the shoulder when it's done.

Two things it deliberately does not do: it doesn't keep knocking on a notebook that stays shut (no spinning retry loop), and it doesn't write down the old value — it looks at what's true now, so a note written before the sync can't undo what the sync brought in.

Fix evidence — the tests bite

Reverting session-write-subscriber.ts and remote-workspace-snapshot-apply.ts to origin/main and re-running the new specs, unchanged:

 ❯ src/renderer/src/lib/session-write-subscriber-deferred-persist.test.ts (6 tests | 5 failed) 12ms
     × writes a mutation made while the gate was closed once a later mutation reopens it 6ms
     × writes a mutation whose debounce expired inside the apply window 1ms
     × keeps an unrelated target’s tab close across another target’s apply 1ms
     × writes on the gate-open wake-up when no further store update follows 1ms
     × does not let an unrelated update reset a debounce armed by the gate-open wake-up 1ms
 ❯ src/renderer/src/lib/session-write-subscriber.test.ts (24 tests | 3 failed) 24ms
     × defers rather than drops a change made while shouldSchedulePersist returns false 2ms
     × holds a write whose change arrived while shouldSchedulePersist returned false 2ms
     × re-checks shouldSchedulePersist when a pending debounce fires 1ms
 ❯ src/renderer/src/hooks/remote-workspace-snapshot-apply-deferred-session-write.test.ts (2 tests | 2 failed) 25ms
     × lands an unrelated target’s tab close once the suppression tail expires 21ms
     × still wakes the deferred write when the wall clock steps back during the tail 3ms

⎯⎯⎯⎯⎯⎯ Failed Tests 10 ⎯⎯⎯⎯⎯⎯⎯

 FAIL  src/renderer/src/hooks/remote-workspace-snapshot-apply-deferred-session-write.test.ts > session writes deferred by a direct-SSH apply > lands an unrelated target’s tab close once the suppression tail expires
AssertionError: the close made during the apply never reached disk: expected "vi.fn()" to be called 1 times, but got 0 times
 ❯ src/renderer/src/hooks/remote-workspace-snapshot-apply-deferred-session-write.test.ts:206:77
    204|       vi.advanceTimersByTime(1_200)
    205|
    206|       expect(persist, 'the close made during the apply never reached d…
       |                                                                             ^
    207|       const patch = persist.mock.calls[0][0].patch
    208|       expect(patch.closedTerminalTabTombstonesByTabId?.['tab-b']?.work…

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/10]⎯

 FAIL  src/renderer/src/hooks/remote-workspace-snapshot-apply-deferred-session-write.test.ts > session writes deferred by a direct-SSH apply > still wakes the deferred write when the wall clock steps back during the tail
AssertionError: a clock step back stranded the deferred write: expected "vi.fn()" to be called 1 times, but got 0 times
 ❯ src/renderer/src/hooks/remote-workspace-snapshot-apply-deferred-session-write.test.ts:243:72
    241|       vi.advanceTimersByTime(5_200)
    242|
    243|       expect(persist, 'a clock step back stranded the deferred write')…
       |                                                                        ^
    244|       expect(
    245|         persist.mock.calls[0][0].patch.closedTerminalTabTombstonesByTa…

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/10]⎯

 FAIL  src/renderer/src/lib/session-write-subscriber-deferred-persist.test.ts > session write subscriber defers writes across a closed persistence gate > writes a mutation made while the gate was closed once a later mutation reopens it
AssertionError: the tombstone written during the apply window was discarded, not deferred: expected undefined to deeply equal { 'closed-during-apply': { …(2) } }

- Expected:
{
  "closed-during-apply": {
    "closedAt": Any<Number>,
    "worktreeId": "wt-remote",
  },
}

+ Received:
undefined

 ❯ src/renderer/src/lib/session-write-subscriber-deferred-persist.test.ts:110:7
    108|       patch.closedTerminalTabTombstonesByTabId,
    109|       'the tombstone written during the apply window was discarded, no…
    110|     ).toEqual({
       |       ^
    111|       'closed-during-apply': {
    112|         closedAt: expect.any(Number),

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/10]⎯

 FAIL  src/renderer/src/lib/session-write-subscriber-deferred-persist.test.ts > session write subscriber defers writes across a closed persistence gate > writes a mutation whose debounce expired inside the apply window
AssertionError: the debounce fired inside the apply window and threw the mutation away: expected undefined to be 'closed-mid-debounce' // Object.is equality

- Expected:
"closed-mid-debounce"

+ Received:
undefined

 ❯ src/renderer/src/lib/session-write-subscriber-deferred-persist.test.ts:152:7
    150|       persist.mock.calls[0][0].patch.activeTabId,
    151|       'the debounce fired inside the apply window and threw the mutati…
    152|     ).toBe('closed-mid-debounce')
       |       ^
    153|     cleanup()
    154|   })

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[4/10]⎯

 FAIL  src/renderer/src/lib/session-write-subscriber-deferred-persist.test.ts > session write subscriber defers writes across a closed persistence gate > keeps an unrelated target’s tab close across another target’s apply
AssertionError: target B lost a tab close because target A was mid-apply: expected undefined to deeply equal []

- Expected:
[]

+ Received:
undefined

 ❯ src/renderer/src/lib/session-write-subscriber-deferred-persist.test.ts:199:7
    197|       patch.tabsByWorktree?.['wt-target-b'],
    198|       'target B lost a tab close because target A was mid-apply'
    199|     ).toEqual([])
       |       ^
    200|     expect(patch.tabsByWorktree?.['wt-target-a']).toHaveLength(1)
    201|     expect(patch.closedTerminalTabTombstonesByTabId?.['tab-b']?.worktr…

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[5/10]⎯

 FAIL  src/renderer/src/lib/session-write-subscriber-deferred-persist.test.ts > session write subscriber defers writes across a closed persistence gate > writes on the gate-open wake-up when no further store update follows
AssertionError: the subscriber never registered for the gate-open wake-up: expected +0 to be 1 // Object.is equality

- Expected
+ Received

- 1
+ 0

 ❯ src/renderer/src/lib/session-write-subscriber-deferred-persist.test.ts:229:95
    227|     // The suppression tail expires on a wall clock, so nothing touche…
    228|     gateOpen = true
    229|     expect(gate.listenerCount(), 'the subscriber never registered for …
       |                                                                                               ^
    230|       1
    231|     )

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[6/10]⎯

 FAIL  src/renderer/src/lib/session-write-subscriber-deferred-persist.test.ts > session write subscriber defers writes across a closed persistence gate > does not let an unrelated update reset a debounce armed by the gate-open wake-up
AssertionError: an unrelated update pushed the deferred write past its debounce: expected "vi.fn()" to be called 1 times, but got 0 times
 ❯ src/renderer/src/lib/session-write-subscriber-deferred-persist.test.ts:295:7
    293|       persist,
    294|       'an unrelated update pushed the deferred write past its debounce'
    295|     ).toHaveBeenCalledTimes(1)
       |       ^
    296|     expect(persist.mock.calls[0][0].patch.activeTabId).toBe('closed-du…
    297|     cleanup()

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[7/10]⎯

 FAIL  src/renderer/src/lib/session-write-subscriber.test.ts > createSessionWriteSubscriber > defers rather than drops a change made while shouldSchedulePersist returns false
AssertionError: expected undefined to be defined
 ❯ src/renderer/src/lib/session-write-subscriber.test.ts:596:59
    594|     expect(persist).toHaveBeenCalledTimes(1)
    595|     // The suppressed first pass owed every field; only activeTabId ch…
    596|     expect(persist.mock.calls[0][0].patch.tabsByWorktree).toBeDefined()
       |                                                           ^
    597|     cleanup()
    598|   })

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[8/10]⎯

 FAIL  src/renderer/src/lib/session-write-subscriber.test.ts > createSessionWriteSubscriber > holds a write whose change arrived while shouldSchedulePersist returned false
AssertionError: expected undefined to be 'remote-tab' // Object.is equality

- Expected:
"remote-tab"

+ Received:
undefined

 ❯ src/renderer/src/lib/session-write-subscriber.test.ts:622:56
    620|     vi.advanceTimersByTime(200)
    621|     expect(persist).toHaveBeenCalledTimes(1)
    622|     expect(persist.mock.calls[0][0].patch.activeTabId).toBe('remote-ta…
       |                                                        ^
    623|     cleanup()
    624|   })

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[9/10]⎯

 FAIL  src/renderer/src/lib/session-write-subscriber.test.ts > createSessionWriteSubscriber > re-checks shouldSchedulePersist when a pending debounce fires
AssertionError: expected undefined to be 'wt-before-remote-pull' // Object.is equality

- Expected:
"wt-before-remote-pull"

+ Received:
undefined

 ❯ src/renderer/src/lib/session-write-subscriber.test.ts:652:61
    650|     vi.advanceTimersByTime(200)
    651|     expect(persist).toHaveBeenCalledTimes(1)
    652|     expect(persist.mock.calls[0][0].patch.activeWorktreeId).toBe('wt-b…
       |                                                             ^
    653|     cleanup()
    654|   })

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[10/10]⎯


 Test Files  3 failed (3)
      Tests  10 failed | 22 passed (32)
   Start at  22:12:26

With the fix, all green:

 RUN  v4.1.5 /Users/nwparker/projects/orca/.claude/worktrees/agent-ae4988a06f7aa66c2


 Test Files  3 passed (3)
      Tests  32 passed (32)
   Start at  22:12:18

Only one case in the whole change — arms no timer while the gate stays closed — passes with and without the fix, by design: it is the guard rail on hazard 1 (no polling loop), not proof of the fix. The other ten bite.

The integration spec drives the real applyDirectSshRemoteWorkspaceSnapshot path with the real subscriber wired exactly as use-app-session-persistence wires it — real gate, real 1s suppression tail, real wake-up — and closes a tab on an unrelated target from inside the apply. That is requirement 3 (cross-target) end to end; the unit suite covers it at patch level too.

Review round 1 (independent adversarial review)

An independent reviewer traced the overlapping-apply depth math, the +1ms tail arithmetic, re-entrancy of persist() into the subscriber, listener-set mutation during notification, staleness, cleanup, and StrictMode, and found no P0/P1. Two P2s, both fixed in this branch:

  1. The gate and its wake-up were independently optional, so a future call site could supply shouldSchedulePersist without subscribeToPersistGateOpen and silently strand deferred writes again. They are now a single discriminated union (SessionWritePersistGate), so the unsafe combination does not typecheck. Call sites that reopen the gate through a store update pass an explicit no-op wake-up, which documents the choice at each site.
  2. One new test did not bite. The debounce-reset guard never closed the gate, so it only re-exercised a pre-existing early return. It now defers a write through a closed gate, arms the flush via the gate-open wake-up, and then fires an unrelated update — proving the reset guard holds on the new arming path too. It fails against origin/main.

Also fixed: cancels a pending debounce when shouldSchedulePersist returns false had a stale title and was silently inert — it left hydrationSucceeded false, so the outer hydration gate short-circuited before the schedule gate was ever consulted. It now opens both flags, exercises the change-time gate for real, and asserts the deferred write lands.

Review round 2 (second independent reviewer)

A second reviewer independently cleared backward compatibility, the remote-push path, concurrency, the SSH execution boundary, and code organization, and found no P0/P1. It did find a real hole in my hazard-2 claim, now fixed:

The gate-open notice could still be dropped. The callback skipped when isDirectSshRemoteWorkspaceApplyInProgress() was true, and my comment justified that with "an overlapping apply owns its own notice". That reasoning only covers snapshotApplyDepth > 0. The other half of the predicate is the wall-clock tail — and delayMs is wall-clock arithmetic handed to a monotonic timer, so a clock step back (NTP) can leave the deadline in the future when the timer fires. In that case the notice returned, nothing rescheduled, and the deferred write was stranded until the next store update: exactly the hole this PR exists to close.

The two halves are now separated. depth > 0 still returns (that apply's finally schedules the next notice); an outstanding tail re-arms for the time still left on it instead of giving up. This does not reintroduce hazard 1: the deadline only moves forward and each re-arm waits the exact remainder, so the wait converges rather than polling.

still wakes the deferred write when the wall clock steps back during the tail covers it, and it is targeted — it fails against the previous revision of this branch, not just against main:

     × still wakes the deferred write when the wall clock steps back during the tail 5ms
AssertionError: a clock step back stranded the deferred write: expected "vi.fn()" to be called 1 times, but got 0 times

The same reviewer flagged the integration spec's ~1.2s of real-clock waiting as load-sensitive. It now runs on fake timers (vitest fakes Date too, so the Date.now() < suppressUntil comparison stays coherent): the file's test time went from ~1.4s of wall-clock waiting to 22ms, and the vi.waitFor timeout race is gone entirely.

Backward compatibility

  • No wire change. No RPC params, no stream opcodes, no schema fields added or altered. docs/reference/remote-wire-compatibility.md third case (what the host is published) does apply in one narrow sense and it is the point of the change: a tab close made during the apply window now reaches the host on the next debounced push, where it previously vanished. The payload shape is identical, it is scoped per target by the existing exportSessionForTarget, and an older host sees an ordinary session patch.
  • No persisted-schema change. closedTerminalTabTombstonesByTabId and every other field keep their shapes; the fix only changes when a patch is emitted.
  • Rollback is safe. Downgrading to a build without this change reverts to the old drop-on-suppression behavior; nothing new is written to disk that an older client cannot read.
  • New optional dep only. subscribeToPersistGateOpen is optional on SessionWriteSubscriberDeps; existing call sites and tests that omit it behave exactly as before.
  • No mobile-facing surface touched. Renderer session persistence only.
  • No platform-dependent code. No paths, shells, processes, or native modules involved.

Verification

  • pnpm tc — clean
  • oxlint + oxfmt --check on all six changed files — clean
  • pnpm run check:code-quality:changed — 0 new finding(s) across 6 changed file(s), React Doctor clean
  • pnpm test src/renderer/src/lib src/renderer/src/app-shell src/renderer/src/hooks — 610 files, 5404 passed
  • pnpm test src/renderer/src/store — 304 files, 2983 passed
  • No max-lines disable added; session-write-subscriber.ts stays well inside the 300-line budget.

On e2e

tests/e2e/ssh-cold-hydration-gap-tab-seeding.spec.ts was evaluated and deliberately not extended. Hitting this bug e2e requires closing a tab inside the suppression window, and the window's state is renderer-module-internal — a spec cannot observe it without a new test hook, so the timing would be a guess. The neighbouring remote-workspace-snapshot-local-tab-survival.test.ts documents the same trade for a sibling bug ("the end-to-end version of the same scenario only reproduces about one run in three"). The new integration spec drives the real apply path deterministically instead.

@nwparker
nwparker force-pushed the nwparker/defer-session-writes-during-ssh-apply branch from 00cbe46 to 348a086 Compare August 28, 2026 05:07
@coderabbitai

coderabbitai Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 25b6b240-7caf-43e8-8150-b7b4f2cd009e

📥 Commits

Reviewing files that changed from the base of the PR and between 6e28d699f1b950790919173d3e881ff20dfbfe91 and 7a5f1a8.

📒 Files selected for processing (1)
  • src/renderer/src/hooks/remote-workspace-snapshot-apply.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The session write subscriber now retains pending changes while persistence is gated. It can re-arm its debounce timer when the gate opens. Direct SSH snapshot application now emits a one-shot notification after its write-suppression window ends. Application session persistence uses this notification. Tests cover deferred mutations, tombstones, debounce timing, gate wake-ups, timer behavior, unrelated worktrees, and the complete snapshot apply flow.

Merge Risk: ⚪ Minimal · up to 7a5f1

This change defers session writes during SSH applies without introducing an actionable merge-blocking risk; it is merge-ready after normal checks and review.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed and relevant. It explains the problem, cause, fix, testing, compatibility, and review findings. However, it omits the required Linked Issue entry, Visual Proof section with… Add a linked issue using Fixes #..., add the Visual Proof section with N/A and a reason if no UI change exists, and complete the required Review, Agent skill upstream boundary, Notes, and Checklist sections.
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: deferred session writes during direct-SSH applies instead of dropping them.
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 relevant. It explains the problem, cause, fix, testing, compatibility, and review findings. However, it omits the required Linked Issue entry, Visual Proof section with an explicit N/A justification, and the required checklist sections.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@nwparker
nwparker force-pushed the nwparker/defer-session-writes-during-ssh-apply branch from 348a086 to 6e28d69 Compare August 28, 2026 05:13

@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)
src/renderer/src/lib/session-write-subscriber.ts (1)

80-85: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Condense the added rationale comments. State each invariant in one short comment.

  • src/renderer/src/lib/session-write-subscriber.ts#L80-L85: reduce the gate-pairing explanation to its invariant.
  • src/renderer/src/lib/session-write-subscriber.ts#L127-L130: reduce the pending-field lifecycle explanation.
  • src/renderer/src/lib/session-write-subscriber.ts#L137-L148: reduce the flush and fresh-state explanation.
  • src/renderer/src/lib/session-write-subscriber-deferred-persist.test.ts#L1-L12: reduce the test preamble.
  • src/renderer/src/hooks/remote-workspace-snapshot-apply-deferred-session-write.test.ts#L1-L8: reduce the test preamble.

As per coding guidelines, “DO NOT: be verbose” and “BE CONCISE. 1 LINE if possible.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 79c71c59-ac74-41fe-9456-861c345a3cd6

📥 Commits

Reviewing files that changed from the base of the PR and between 00cbe46f6c44f26ce357665bcd8b7c7daf44da93 and 6e28d699f1b950790919173d3e881ff20dfbfe91.

📒 Files selected for processing (5)
  • src/renderer/src/hooks/remote-workspace-snapshot-apply-deferred-session-write.test.ts
  • src/renderer/src/hooks/remote-workspace-snapshot-apply.ts
  • src/renderer/src/lib/session-write-subscriber-deferred-persist.test.ts
  • src/renderer/src/lib/session-write-subscriber.test.ts
  • src/renderer/src/lib/session-write-subscriber.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.

The debounced session writer cleared its pending changed-field set whenever the
persist gate was shut, after it had already advanced its identity-based
detection baseline. Because detection is `prev[key] !== next[key]`, a field
dropped there could never be re-detected, so a mutation made during an SSH
apply (up to 30s plus a 1s tail, on every connect and reconnect) was lost for
good — including a closed-tab tombstone, which is exactly the state that stops
the host from resurrecting the tab.

Keep the pending set instead, and add a one-shot wake-up from the gate owner so
a deferred write is not stranded when the suppression tail expires with no
store update behind it.
@nwparker
nwparker force-pushed the nwparker/defer-session-writes-during-ssh-apply branch from 6e28d69 to 7a5f1a8 Compare August 28, 2026 05:37
@nwparker
nwparker merged commit 6c58038 into main Aug 28, 2026
28 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 30, 2026
…tablyai#16969)

The debounced session writer cleared its pending changed-field set whenever the
persist gate was shut, after it had already advanced its identity-based
detection baseline. Because detection is `prev[key] !== next[key]`, a field
dropped there could never be re-detected, so a mutation made during an SSH
apply (up to 30s plus a 1s tail, on every connect and reconnect) was lost for
good — including a closed-tab tombstone, which is exactly the state that stops
the host from resurrecting the tab.

Keep the pending set instead, and add a one-shot wake-up from the gate owner so
a deferred write is not stranded when the suppression tail expires with no
store update behind it.

(cherry picked from commit 6c58038)
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#16969)

The debounced session writer cleared its pending changed-field set whenever the
persist gate was shut, after it had already advanced its identity-based
detection baseline. Because detection is `prev[key] !== next[key]`, a field
dropped there could never be re-detected, so a mutation made during an SSH
apply (up to 30s plus a 1s tail, on every connect and reconnect) was lost for
good — including a closed-tab tombstone, which is exactly the state that stops
the host from resurrecting the tab.

Keep the pending set instead, and add a one-shot wake-up from the gate owner so
a deferred write is not stranded when the suppression tail expires with no
store update behind it.
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.

1 participant