Repository navigation
fix(ssh): keep the generation floor when a target is removed and recreated - #22146
Conversation
…eated A removed SSH target released its connection-generation entry, so a target recreated under the same id (runtime-owned VM targets derive it from the runtime id) restarted at the session base and reissued the generations the discarded incarnation had already handed out. A delayed write or delete from the old VM then matched the replacement's fence. Keep a scope-wide floor of the highest forgotten generation so a recreated target always starts above it, and make authority rotation detect a scope roll by scope membership rather than by a +1 step so the skip does not revoke every other target's requests.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe SSH generation state now records the highest generation issued by forgotten targets. Recreated targets receive generations above that floor. Session initialization, rollover, and reset update the floor. A reusable session-membership predicate now supports authority rotation. Tests cover recreated targets, repeated forgetting, session rollover, provider authority, and persistence lifecycle behavior. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to Recreated SSH targets reject stale mutations while genuine session changes still revoke affected requests. No actionable merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Scope-wide forgotten-generation floor (
ssh-connection-generation.ts):forgetSshConnectionGenerationnow raises a single module-levelforgottenGenerationFloorto the highest forgotten generation before dropping the per-target entry (so the #21734 memory fix is preserved), andadvanceSshConnectionGenerationstarts fromMath.max(current, floor) + 1. A recreated deterministicruntime-ssh-<runtimeId>target therefore skips past every generation its prior incarnation issued. - Floor lifecycle: the floor resets to
sessionGenerationBaseon session init,resetSshConnectionGenerations, and every scope roll — a fresh scope already invalidates all prior generations, so dropping the floor is safe. - Scope-roll detection rewritten (
ssh-provider-authority.ts):rotateSshProviderAuthorityno longer infers a roll fromnextGeneration !== previousGeneration + 1(a recreated target legitimately jumps by more than one). It now uses the newisSshConnectionGenerationInCurrentSession(previousGeneration). Only a genuine roll clearsauthorityByTargetand aborts every target; a recreated target aborts only its own prior authority. - Tests: unit coverage for recreation, repeated recreation across a lower forgotten target, floor drop on scope roll, and authority rotation not revoking other targets; plus a real
Storeremove/re-add integration test inpersistence-repo-lifecycle.test.ts.
I verified the rewritten guard myself: a real scope roll always advances sessionGenerationBase by exactly one stride (or wraps to 0), and previousGeneration is captured before advance from the old scope, so it can never land inside the new range — making the new check equivalent to the old one for real rolls while correctly classifying the recreation jump. Each new test asserts an exact value or an exact throw and fails with the old behavior.
Also ran the touched suites locally: ssh-connection-generation, ssh-provider-authority, persistence-repo-lifecycle, filesystem-mutations, filesystem-import-ssh, and orca-runtime-files-rename-authority all pass; oxlint clean on both changed source files. No wire change — the generation remains an opaque safe integer and renderer/web clients echo it rather than doing arithmetic on it.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
Every SSH connection carries a ticket number. When the connection is replaced, the number goes up, and any late file change that still shows the old number is refused. Removing a target threw away its counter, so a target created again under the same name started counting from the beginning and handed out the same numbers twice. A slow file change from the old machine could then show a number that looked current. Now the counter never goes back down within a session.
What Changed
Before: Remove a default ephemeral VM target and recreate it. The new target's connection reused the generation numbers the old one had issued. A delayed write or delete that the old VM's session had stamped with its generation passed the stale-host fence and ran against the replacement.
After: The same delayed mutation is rejected with "SSH connection changed; refresh and try again", and the replacement connection keeps working normally.
Mechanism:
forgetSshConnectionGenerationstill drops the per-target map entry (the memory fix from #21734 stays), but it now raises a single scope-wide floor to the highest forgotten generation.advanceSshConnectionGenerationstarts from the max of the target's current value and that floor, so a recreated target skips past everything its prior incarnation issued. The floor resets whenever the session scope rolls, because a new scope already invalidates every prior generation.Because a recreated target now jumps by more than one,
rotateSshProviderAuthorityno longer infers a scope roll fromnext !== previous + 1. It asks the generation module whether the previous generation is still inside the current scope. Only a real scope roll revokes every target's in-flight requests; a recreated target aborts only its own.Why
Runtime-owned target ids are deterministic (
runtime-ssh-<runtimeId>), so remove-and-recreate is a normal path for ephemeral VMs, not an edge case. Alternatives considered:Linked Issue
Fixes STA-8011 (https://linear.app/stably/issue/STA-8011)
Visual Proof
N/A. Main-process fencing logic with no UI change.
Testing
pnpm test src/main/ssh/ src/main/persistence-repo-lifecycle.test.ts src/main/ipc/filesystem-mutations.test.ts src/main/ipc/filesystem-import-ssh-ops.test.ts src/main/ipc/filesystem-import-ssh.test.ts src/main/runtime/orca-runtime-files-rename-authority.test.tspasses (167 files, 2333 tests).pnpm tc:nodepasses;pnpm run check:code-quality:changedandoxlintare clean on the changed files.New tests: recreated target starts above every generation its removed incarnation issued; floor holds across repeated recreation and across a lower forgotten target; floor drops on scope roll; authority rotation for a recreated target does not abort other targets; real
Storeremove-and-recreate of a runtime-owned VM target rejects the stale expectation while the replacement passes.Tested on macOS; the code is platform-independent main-process logic.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
No wire change: the generation is still an opaque safe integer on both sides. Old clients holding a stale generation get the same "refresh and try again" error they already handle.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)