Skip to content

fix(ssh): recover abandoned caches without deleting live dependencies - #23281

Merged
OrcaWin merged 1 commit into
mainfrom
OrcaWin/np-ssh-cache-recovery
Sep 27, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
OrcaWin/np-ssh-cache-recovery

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

An interrupted cache deletion can leave the only copy of a running SSH relay’s dependencies in a renamed directory. Orca now checks who still needs that copy and lets only one cleanup pass recover or delete it.

What Changed

  • Preserve cache identity when parsing a listing, so a clock adjustment cannot make a live reference disappear from the cleanup decision.
  • Claim abandoned native-dependency and ripgrep directories with a fresh rename before restoring or deleting them. Competing passes leave the winner alone.
  • Remove native completion markers before deletion; never restore a partially deleted tree as complete.
  • Check cache references before deletion; unreadable or unattributable references preserve the files.
  • Keep new native recovery directories outside older clients’ blind deletion sweep. Legacy native trees are unmarked before claiming, so later passes cannot mistake potentially partial contents for verified dependencies.

Why

Age alone does not establish that a cache is unused or intact. Reference checks, a claim rename, and completion markers address those separate facts without introducing a cache database or global scheduler.

This is 2 of 2. #23273 is merged; this PR is rebased onto main and contains only the seven-file cache-recovery change. The patch is byte-for-byte identical to the reviewed stack delta.

Linked Issue

No existing issue. Cache-recovery portion split from #23273, following #23128.

Visual Proof

N/A — remote cache cleanup and recovery; no rendered UI changes.

Testing

  • The combined source tree exactly matches the previously reviewed head 3544e8f675, which passed full CI and 2,742 local SSH tests (22 skipped).
  • Real-shell regressions cover competing cleanup passes, clock changes, partial deletion, legacy recovery over multiple passes, missing markers, unreadable references, and recreated destinations.
  • Independent Codex review of this exact split found no blockers or missing dependencies. Dedicated Claude Opus review found no P0/P1; final split-head CI passed, including Docker SSH E2E.
  • I manually tested these changes locally
  • Automated tests added/updated

Review

Fresh reviews inspect this seven-file delta separately from installation/retry behavior. No new behavior was added while splitting. Both Codex and Claude Opus independently reviewed this split; no blockers found.

Agent skill upstream boundary

  • Not applicable; no upstream skill source or instructions copied.

Notes

Referenced legacy native leftovers are retained but not automatically restored as complete; reconnect may need to reinstall dependencies. A replacement at the original path can leave an extra recovery copy. These conservative choices preserve files under uncertainty. Bounded listings and future-dated names can delay cleanup; a concurrent claim can also make a removal log overcount without deleting the other pass’s files. POSIX shell paths run locally; Windows paths receive generated-command and fault-injection coverage plus CI. No tracking/design documents included.

Checklist

  • Focused on abandoned cache recovery
  • Explained behavior, mechanism, and approach
  • Cross-platform and mixed-client behavior considered
  • No rendered UI change
  • Rebased-head CI passed, including all four Docker SSH E2E shards, all unit shards, typecheck, static analysis, and packaging.

@OrcaWin
OrcaWin force-pushed the OrcaWin/np-ssh-cache-recovery branch from 34ec82f to fab1e57 Compare September 27, 2026 00:25
@OrcaWin
OrcaWin force-pushed the OrcaWin/np-ssh-interrupted-install-cleanup branch from 310fa67 to 9eeef0a Compare September 27, 2026 00:25

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

This reviews the seven-file delta against the installation/retry branch: the native-deps and ripgrep cache GC now recover an abandoned tombstone by claiming it with a fresh rename, and only restore or delete it after a reference recheck.

  • Native tombstone recovery (ssh-relay-native-deps-cache-gc.ts): the listing yields {name, key} for complete entries and stale tombstones, and each abandoned tombstone is claimed by a randomized rename before the recheck decides restore vs. delete.
  • New native tombstone namespace (ssh-relay-native-deps-cache.ts, -commands.ts): the prefix moves to .native-gc- so an older client's mtime-only .gc-tombstone.* sweep can no longer blind-delete a live tree; the listing-time sweep is dropped and tombstones are recovered instead.
  • Marker-gated restore (-commands.ts): restore requires .deps-complete and an absent destination, and deletion drops the marker before rm -rf, so a partially deleted tree can never be restored as complete.
  • Reference-scan hardening (-commands.ts): the reference listing answers REFS_ERR when the install root or any child directory is unreadable, closing a hole where a narrowed reference set could authorise a deletion.
  • Ripgrep parity (ssh-relay-ripgrep-cache-gc.ts): abandoned ripgrep tombstones are claimed and restored the same way, with timestamps validated as safe integers.
  • Tests (*-gc-real.test.ts, native-deps-cache.test.ts): real-shell regressions for competing passes, clock movement, partial deletion, legacy recovery, unreadable references, and recreated destinations.

I read the complete seven-file delta, traced the claim/recheck paths and their callers, and ran pnpm tc:node, oxlint on the changed files, and the four touched test files (90 tests) — all green. Two independent sub-reviews found no reachable interleaving of two GC passes, or a GC pass with a deploy/installer, in which the new claim logic deletes the only copy of a live-referenced tree: every deletion routes through a fresh reference scan under the rename, and keep = true never deletes.

ℹ️ Referenced legacy tombstones are preserved but never restored

A legacy .gc-tombstone. tree is unmarked before it is claimed, so the marker-gated restore always answers BUSY and the tree is left under a fresh .native-gc- name; a relay that still references it keeps a dangling node_modules and must reinstall. While the reference persists, each pass past the 30-minute staleness window re-claims that directory under a new random name — bounded to one rename per window, not a growing leak. This matches the conservative choice documented in the PR Notes; no change requested.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

The head moved from 34ec82f to fab1e57c, a rebase onto the updated base (9eeef0a). The generated PR diff is byte-for-byte identical (diff -q on the two revisions), so no source changed since the prior review — its findings stand: no blocking or must-address issues, plus the one informational note about referenced legacy tombstones never being restored. No further comments.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@OrcaWin
OrcaWin changed the base branch from OrcaWin/np-ssh-interrupted-install-cleanup to main September 27, 2026 01:04
@OrcaWin
OrcaWin force-pushed the OrcaWin/np-ssh-cache-recovery branch from fab1e57 to b9759a6 Compare September 27, 2026 01:04
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Walkthrough

Walkthrough

Native-dependency cache garbage collection now lists current and legacy tombstones, claims stale tombstones, and rechecks references before removing or restoring entries. Ripgrep cache garbage collection now uses the same claim-and-recovery pattern. New tests cover recovery, deletion, reference-scan errors, interrupted operations, concurrent passes, and destination changes.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to b9759

Cache recovery is safe for live dependencies. However, some leftover native-dependency directories can stay on remote disks for as long as a relay references that dependency set. This is a bounded disk-usage follow-up, not a merge blocker.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to b9759

Recovery is better protected against competing cleanup passes, but a previously interrupted deletion of the shared search-binary cache can be restored without checking that its contents are complete. The demonstrated scope is relays sharing an affected SSH host; no privilege escalation is established.

Retained concerns

  • Medium · reliability · inferred: A referenced ripgrep tombstone can be restored to the canonical cache path after an interrupted deletion without verifying that its executable tree remains complete. This weakens failure containment for relays sharing that cache.
Security review details

Security Blast Radius

  • inferred — The identified recovery gap affects the shared ripgrep cache and relays referencing an entry on the same SSH host. The inspected paths do not establish cross-host, cross-tenant, or elevated-privilege exposure.

Trust Boundaries and Controls

  • observed — Malformed ripgrep reference names make the scan unreadable and block collection. A fresh installation probes the expected binary before accepting an installed build; that probe is not part of tombstone restoration.

Resilience and Maintainability Implications

  • inferred — The ripgrep restore path can expose an incompletely deleted tree at the canonical path; the available evidence does not show that this grants an attacker control of executable contents.

Hardening Proposals

  • proposed — Require a completeness or binary-integrity check before restoring a ripgrep tombstone, or keep an unverifiable tree quarantined for reinstallation rather than making it canonical.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.42% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 33 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the SSH cache-recovery change and its main safety goal: recovering abandoned caches without deleting live dependencies.
Description check ✅ Passed The description is complete and directly addresses the template. It explains the user impact, changes, rationale, linked issue context, lack of visual changes, testing, review, compatibility considera…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 33629e79-8f82-4f47-9ab1-077bb672578f

📥 Commits

Reviewing files that changed from the base of the PR and between 6433c3c and b9759a6.

📒 Files selected for processing (7)
  • src/main/ssh/ssh-relay-native-deps-cache-commands.ts
  • src/main/ssh/ssh-relay-native-deps-cache-gc-real.test.ts
  • src/main/ssh/ssh-relay-native-deps-cache-gc.ts
  • src/main/ssh/ssh-relay-native-deps-cache.test.ts
  • src/main/ssh/ssh-relay-native-deps-cache.ts
  • src/main/ssh/ssh-relay-ripgrep-cache-gc-real.test.ts
  • src/main/ssh/ssh-relay-ripgrep-cache-gc.ts

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

@OrcaWin
OrcaWin merged commit 46907de into main Sep 27, 2026
42 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.

1 participant