Repository navigation
perf(main): drop localhost label routes when a worktree is removed - #7557
Conversation
LocalhostWorktreeLabelProxy.registerRoute added a permanent entry to routes and routeKeys per (worktreeId, targetUrl) label, but the class had no removal path and no worktree-teardown code touched the singleton — so routes for deleted worktrees accumulated in both maps for the whole app session. Add unregisterWorktree(worktreeId) and call it from removeWorktreeMetadataAndTransientState (the single per-worktree main-process teardown choke point, 8 call sites). The shared http.Server stays up. Co-authored-by: Orca <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis change adds an Changes
Related PRs: None identified. Suggested labels: bug, enhancement Suggested reviewers: None identified. Poem 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 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 |
…tablyai#7557) Co-authored-by: Orca <[email protected]>
Part of a full-codebase memory-leak audit — one never-purged per-entity structure per PR.
Description
The
localhostWorktreeLabelProxysingleton (used by the opt-in "labeled localhost" feature that gives a dev server a stable*.orca.localhosthostname) keeps two module-levelMaps:routes(label → route) androuteKeys(routeKey → label).registerRoute()was the only mutator — it only ever.set()s. There was no removal method on the class, and no worktree-teardown path touched the singleton, so a label route for a deleted worktree (or a since-changed dev-server port) survived in both maps for the entire app session.Fix: add
unregisterWorktree(worktreeId)and call it fromremoveWorktreeMetadataAndTransientState()— the single per-worktree main-process teardown function (8 call sites, right next to the existingadvertisedUrlWatcher.forgetWorktree(...)).Evidence
src/main/localhost-worktree-label-proxy.ts:routes/routeKeysmutated only via.set()inregisterRoute(lines 44–45); grep of the whole class/file showed nodelete/clear/unregister.ipc/localhost-worktree-labels.ts) exposedregister→registerRoutewith no unregister counterpart.worktree:{worktreeId}:{targetUrl}(shared/localhost-worktree-labels.ts), unique per worktree+URL, so a new worktree or a changed port permanently adds 2 entries that outlive worktree teardown.localhostWorktreeLabelsEnabledsetting on): opening a labeled loopback dev-server link for a not-yet-seen worktree/port; creating and removing many worktrees over a long session accumulates entries.Proof of fix
New test in
localhost-worktree-label-proxy.test.ts: register routes forwt-aandwt-b, confirm both proxy through (200);unregisterWorktree('wt-a'); thenwt-a's label returns 404 whilewt-bstill returns 200.Typecheck (
tsconfig.node.json) + oxlint clean.ELI5
When you open a dev server with a friendly name, the app remembers "this friendly name points to that server." It remembered forever, even after you deleted the workspace that owned it. Now, when a workspace is removed, its friendly-name entries are thrown away too. The little name-forwarding server itself keeps running for everyone else.
Trade-offs
worktreeIdmatches the removed worktree are dropped; routes registered without aworktreeId(legacy repo/project-name keys) are untouched — the renderer always suppliesworktreeId. Target: 0 regression.Made with Orca 🐋