Skip to content

Prevent deleted workspace browser snapshot resurrection - #17779

Merged
Jinwoo-H merged 13 commits into
mainfrom
aug31-workspace-delete-browser-cleanup-audit
Sep 2, 2026
Merged

Jinwoo-H merged 13 commits into
mainfrom
aug31-workspace-delete-browser-cleanup-audit

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​373 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​357
Prod 19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​257 $\color{#cf222e}{\Huge{\mathbf{−}}}$​41 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​216

Summary

  • Fence late mobile/browser session snapshots at the main-process deletion boundary.
  • Carry the worktree incarnation ID in renderer snapshots so same-path recreation cannot accept predecessor state.
  • Keep the fence persistent across replacement snapshots and handle legacy clients by renderer publication epoch.
  • Ensure renderer cache publishes an identity-only recreation even when tab content is unchanged.

Evidence

Current origin/main reproduced a red oracle: after renderer teardown, a late host graph snapshot recreated the deleted worktree's browser rows/pages. Real Electron right-click deletion also confirmed browser teardown itself is ordered and clean; a separate successor sleeping-workspace terminal wake remains tracked by open PR #14705 and is out of scope.

Tests

  • pnpm test src/main/runtime/orca-runtime.test.ts (1223 passed, 1 skipped)
  • Focused graph/publication suites (41 passed)
  • pnpm tc
  • pnpm run check:code-quality:changed
  • git diff --check

No issues/comments were created, and nothing was merged or deployed.

@greptile-apps

greptile-apps Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR adds main-process deletion fencing, propagates workspace incarnation identity through renderer snapshots, and routes folder-workspace deletion through runtime teardown.

  • Records deletion fences and rejects stale renderer snapshots.
  • Publishes worktree instance IDs with mobile session state.
  • Tears down folder-workspace PTYs, browser guests, metadata, and cached session state during deletion.

Confidence Score: 3/5

The PR is not yet safe to merge because valid recreated or host-colliding workspaces can lose all published mobile browser and session state.

The new legacy epoch fence rejects a valid same-renderer successor after recreation, while the cross-host ambiguity guard permanently skips snapshots whenever local and remote rows share a bare locator.

Files Needing Attention: src/main/runtime/orca-runtime-sync-mobile-session-tabs.ts; src/renderer/src/runtime/sync-runtime-graph.ts

Important Files Changed

Filename Overview
src/main/runtime/orca-runtime-sync-mobile-session-tabs.ts Adds instance and epoch-based deletion fencing, but rejects valid identity-less same-generation recreation snapshots.
src/main/runtime/orca-runtime-resolve-worktree-removal-target.ts Records removal identity and epoch state and clears cached browser/mobile session state at the deletion boundary.
src/renderer/src/runtime/sync-runtime-graph.ts Publishes incarnation identity and invalidates snapshot caching on identity changes, but suppresses all snapshots for same-ID cross-host collisions.
src/main/runtime/runtime-project-group-controller.ts Routes folder-workspace deletion through PTY teardown and runtime-owned state cleanup before catalog removal.
src/renderer/src/store/folder-workspaces/folder-workspace-mutations.ts Adds host-qualified deletion routing and browser guest teardown before purging the final renderer workspace state.
src/shared/runtime-session-contracts.ts Extends the renderer snapshot contract with optional worktree incarnation identity for compatibility with older clients.

Sequence Diagram

sequenceDiagram
  participant UI as Renderer
  participant Main as Main Runtime
  participant Store as Workspace Store
  participant Mobile as Mobile Client
  UI->>Main: Delete workspace
  Main->>Store: Read occupant metadata
  Main->>Main: Record instance/epoch fence
  Main->>Store: Remove workspace state
  UI->>Main: Publish later graph snapshot
  Main->>Main: Compare instance or renderer epoch
  alt Snapshot admitted
    Main->>Mobile: Publish recreated workspace state
  else Snapshot rejected
    Main-->>UI: Request resync when applicable
  end
Loading

Reviews (11): Last reviewed commit: "fix: avoid publishing ambiguous worktree..." | Re-trigger Greptile

Comment thread src/main/runtime/orca-runtime.ts Resolved
@coderabbitai

coderabbitai Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Review 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

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: cb55aaec-8101-4093-8404-85a861087808

📥 Commits

Reviewing files that changed from the base of the PR and between 8c26df3 and 6a04877.

📒 Files selected for processing (4)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/store/folder-workspaces/folder-workspace-mutations.ts
  • src/renderer/src/store/slices/folder-workspace-owner-routed-mutations.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/store/folder-workspaces/folder-workspace-mutations.ts

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


📝 Walkthrough

Walkthrough

The change adds optional worktree instance identities to mobile-session snapshots. The renderer creates new snapshot versions when a worktree identity changes. The main runtime records removal fences, cancels queued updates, rejects stale snapshots, and accepts valid snapshots after recreation. Folder deletion shuts down worktree browsers after state reconciliation. Tests cover tombstones, stale identities, recreated worktrees, PTY rescue prevention, and publication-epoch gating.

Merge Risk: 🟡 Moderate · up to 6a048

Deleted workspace browser state can still be restored through one mobile-session recovery path, so the PR is not fully merge-ready until that path is fenced. The removal tracking state also grows for the lifetime of the runtime and needs an explicit bound or cleanup strategy.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change, motivation, evidence, and tests, but it omits several template requirements. It has no Linked Issue, Visual Proof or N/A statement, AI Disclosure, Review, Agent sk… Add the missing template sections. Provide a linked issue after Fixes #; add visual proof or write N/A with a reason if there is no visual or interaction change; complete the testing checklist and platform coverage; complete the AI Disc…
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 files. (2 skipped: 2… 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 primary change: preventing deleted workspace browser snapshots from being recreated.
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 explains the change, motivation, evidence, and tests, but it omits several template requirements. It has no Linked Issue, Visual Proof or N/A statement, AI Disclosure, Review, Agent skill upstream boundary, Notes, or Checklist sections.

Resolution

Add the missing template sections. Provide a linked issue after Fixes #; add visual proof or write N/A with a reason if there is no visual or interaction change; complete the testing checklist and platform coverage; complete the AI Disclosure, Review, Agent skill upstream boundary, Notes, and remaining Checklist items.

Full details: Docstring Coverage

Explanation

Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 files. (2 skipped: 2 too large.)

✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch aug31-workspace-delete-browser-cleanup-audit

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: Team

Run ID: e4a91483-e9ad-475d-9cd1-4801c9176194

📥 Commits

Reviewing files that changed from the base of the PR and between 406bd0e and 68b32b819f04a622c1b1c73b4ce14707b5c4055f.

📒 Files selected for processing (5)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/runtime/sync-runtime-graph-workspace-publication.test.ts
  • src/renderer/src/runtime/sync-runtime-graph.ts
  • src/shared/runtime-session-contracts.ts
Files not reviewed due to moderation or processing errors (1)
  • src/main/runtime/orca-runtime.test.ts

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

Comment thread src/main/runtime/orca-runtime.ts Outdated
Comment on lines +3303 to +3311
private readonly removedMobileSessionWorktreeIds = new Map<
string,
{
removedInstanceId?: string
removedPublicationEpoch?: string
acceptedPublicationEpoch?: string
blockedPublicationEpochs: Set<string>
}
>()

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Bound or evict entries in removedMobileSessionWorktreeIds.

removedMobileSessionWorktreeIds gets a new entry on every worktree removal (removeWorktreeMetadataAndHistory, line 29534), but no code path ever calls .delete() on this map. Search the file: .get, .has, and .set are the only operations against it.

For a long-running runtime (headless orca serve, or a desktop session left open for days), repeated create/delete cycles on differently-named worktrees (the documented agent/automation workflow this PR targets) accumulate one entry per distinct worktree ID forever. Each entry also owns a blockedPublicationEpochs Set that keeps growing for a given worktree ID across repeated recreate cycles at the same path, since legacy-epoch entries are also never pruned.

The codebase already has precedent for bounding equivalent long-lived state, for example MAX_TRACKED_PTY_LIVENESS_VERDICTS combined with pruneDisconnectedPtyRecords. Apply the same pattern here: cap the map size with LRU eviction, or clear the fence once a snapshot with a matching current instanceId has been durably accepted (at that point the recreation race window has closed and the guard has served its purpose).

♻️ Sketch of a bounded fix
+  private static readonly MAX_TRACKED_REMOVED_MOBILE_SESSION_WORKTREES = 256
+
   private readonly removedMobileSessionWorktreeIds = new Map<
     string,
     {
       removedInstanceId?: string
       removedPublicationEpoch?: string
       acceptedPublicationEpoch?: string
       blockedPublicationEpochs: Set<string>
     }
   >()

And, once a snapshot's worktreeInstanceId matches the current metadata's instanceId and is accepted, remove the fence for that worktree id (or evict the oldest entry once the map exceeds a cap), mirroring pruneDisconnectedPtyRecords.

Also applies to: 29532-29540

@Jinwoo-H
Jinwoo-H force-pushed the aug31-workspace-delete-browser-cleanup-audit branch from 68b32b8 to a4bca50 Compare September 1, 2026 01:58

@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

  • Deletion-boundary fence (main) — removeWorktreeMetadataAndHistory now records the removed worktree's instanceId and publication epoch into removedMobileSessionWorktreeIds, deletes the stored snapshot, cancels any queued coalesced notification, and emits the removal tombstone immediately instead of waiting for a later graph prune to do it.
  • Snapshot acceptance gate (main) — syncMobileSessionTabs filters incoming snapshots against the fence: frames carrying the removed occupant's worktreeInstanceId (or a mismatched current instance id) are dropped, and legacy frames without an identity are gated by publication epoch. Removed worktrees are also excluded from hydration and resync.
  • Renderer identity publication — buildMobileSessionTabSnapshots now carries each worktree's instanceId, includes it in the snapshot-reuse comparison, and re-publishes an identity-only snapshot with a fresh version when tab content is unchanged but the instance changed.
  • Contract + tests — RuntimeMobileSessionTabsSnapshot gains an optional worktreeInstanceId (a new optional field, wire-safe), plus three main-process tests and one renderer test covering the resurrection, recreation, and legacy-epoch paths.

The new tests are meaningful — each would fail against the pre-PR behavior (verified by running the focused suites: renderer publication suite 5/5, and the three new orca-runtime cases in isolation).

ℹ️ Fence map grows without eviction

removedMobileSessionWorktreeIds is keyed by worktree id and entries are never removed, so a long-lived serve process that creates and deletes many worktrees accumulates entries indefinitely. The legacy path's blockedPublicationEpochs set also only grows (each newly accepted epoch pushes the previous one into the blocked set). Each entry is small and the fence is deliberately persistent — a delayed frame from the removed occupant must keep being blocked even after a recreation is accepted — so this is informational rather than a bug, but it may be worth a future eviction strategy for long-running hosts.

ℹ️ Legacy (pre-identity) renderers stay fenced across same-epoch recreation

For renderers that omit worktreeInstanceId, fencing keys on the per-renderer-session publicationEpoch. Since that epoch does not change when a worktree is recreated at the same path without a renderer restart, a recreated worktree's frames from such a renderer stay fenced until the epoch rotates. This only affects pre-PR renderers in mixed-version deployments, and it errs on the safe side (no resurrection), matching the code comment "same-epoch frames are ambiguous and stay fenced."

Pullfrog  | View workflow run | Using DeepSeek Pro (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 blocking issues — one minor perf note on the follow-up commit, anchored inline.

Reviewed changes (delta since the prior pullfrog review at 68b32b8)

  • Renderer instance-id lookup moved to a local helper — the @/store/selectors import was dropped in favor of getWorktreeInstanceIdFromState, a manual linear scan over state.worktreesByRepo, avoiding a store ↔ runtime import cycle.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (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 (delta since the prior pullfrog review at a4bca50)

  • Cached worktree identity lookup — getWorktreeInstanceIdFromState now resolves the worktree through getIndexedWorktreesById from @/store/worktree-repo-index, replacing the per-sync O(worktrees × repo rows) scan with the module's WeakMap-cached index. The leaf-module import avoids the store ↔ runtime cycle that motivated the earlier @/store/selectors swap, and the .find(w => w.instanceId !== undefined)?.instanceId fallback preserves the multi-row semantics the index documents.

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

@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

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 4abfeefe-f101-4fc6-b5f4-680eae0bf751

📥 Commits

Reviewing files that changed from the base of the PR and between 59fd0fe and 8c26df3.

📒 Files selected for processing (4)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/store/folder-workspaces/folder-workspace-mutations.ts
  • src/renderer/src/store/slices/folder-workspace-owner-routed-mutations.test.ts
Files not reviewed due to moderation or processing errors (1)
  • src/main/runtime/orca-runtime.test.ts

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

Comment thread src/main/runtime/orca-runtime.ts Resolved
Comment thread src/main/runtime/orca-runtime.ts Resolved

@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 (delta since the prior pullfrog review at 59fd0fe)

  • Fenced the paired-PTY rescue path — restoreLivePairedRendererSessionOwnedMobileTerminals now skips a worktree when the graph-sync rescue (missingSnapshotOnly) hits a removal tombstone with no current worktree metadata, closing the remaining resurrection vector where a still-connected renderer-owned PTY could repopulate a deleted worktree's mobile-session entry.
  • Regression test — a new orca-runtime.test.ts case registers a connected paired PTY, marks it renderer-owned, removes the worktree, then runs a graph sync and asserts the worktree is not repopulated.

The new test is meaningful: without the guard the syncWindowGraph path would re-insert the deleted worktree via the paired PTY, so it fails against the pre-fix behavior. The guard is correctly scoped to missingSnapshotOnly (the graph-sync resume), leaving the explicit listMobileSessionTabs / collectAllMobileSessionTabs restore calls unaffected for worktrees that still have metadata.

Pullfrog  | View workflow run | Using DeepSeek Pro (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 (delta since the prior pullfrog review at 3df7285)

  • Fenced pre-publication deletion — removeWorktreeMetadataAndHistory now falls back to this.rendererGeneration when computing removedPublicationEpoch, so a worktree deleted before any snapshot was ever published still fences an identity-less legacy snapshot that arrives afterward.
  • Folder workspace browser teardown — deleteFolderWorkspace now awaits shutdownWorktreeBrowsers(folderWorkspaceKey(id)) before purgeWorktreeTerminalState, matching the worktree teardown ordering (Chromium guests unregister before terminal state is purged). The call is correctly scoped to the no-sibling-row branch.

Both new tests are meaningful: the pre-publication case would previously accept the recreated worktree's first identity-less snapshot, and the folder-deletion cases assert shutdownWorktreeBrowsers fires on full removal but not when a colliding sibling-host row keeps the ID alive.

Pullfrog  | View workflow run | Using DeepSeek Pro (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 blocking issues — one minor note on duplicate repo-change notifications inline.

Reviewed changes (delta since the prior pullfrog review at 6a04877)

  • Folder deletion routed through runtime cleanup — the local folderWorkspaces:delete IPC handler now calls runtime.deleteFolderWorkspace (fencing the deleted folder key, tearing down headless and client-hosted browser pages, and emitting the removal tombstone) instead of mutating the store directly, with registerRepoHandlers / registerFolderWorkspaceHandlers threading the runtime through.
  • Owner host preserved in delete intents — the sidebar quick action and context-menu delete intent now carry the row's executionHostId into deleteFolderWorkspace, and both only clear the active worktree when the deleted row's host matches the active host.
  • Tests — a new runtime case asserts the folder path closes client-hosted pages, emits the tombstone, and fences the key; a new intent test asserts executionHostId is preserved.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H force-pushed the aug31-workspace-delete-browser-cleanup-audit branch from dae08d5 to e1845ed Compare September 1, 2026 03:17

@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 (delta since the prior pullfrog review at 5e01a54)

  • Folder PTY sweep on runtime deletion — deleteFolderWorkspace now sweeps the folder's PTYs via killAllProcessesForWorktree before removing metadata, resolving the SSH provider through connectionId and falling back to the runtime-local provider, mirroring the existing removeFolderWorkspace teardown.
  • Stale legacy-epoch fence — syncMobileSessionTabs accepts a rendererGeneration and drops identity-less snapshots whose publicationEpoch no longer matches the current renderer generation, closing the hole where an unseen epoch from a superseded renderer could repopulate a removed worktree.
  • Paired-PTY rescue fence widened to inventory — the deletion-tombstone fence in restoreLivePairedRendererSessionOwnedMobileTerminals no longer applies only to graph sync (missingSnapshotOnly); listAllMobileSessionTabs can no longer repopulate a removed worktree either.
  • Prior feedback addressed — the local folderWorkspaces:delete handler now notifies only in the no-runtime fallback (if (deleted && !runtime)), so a local folder deletion no longer double-notifies the renderer and remote clients.

All three touched tests are meaningful and pass in isolation (sweeps folder PTYs…, rejects an unseen legacy epoch…, does not rescue a paired PTY… or inventory).

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

Comment on lines +165 to +168
function getWorktreeInstanceIdFromState(state: AppState, worktreeId: string): string | undefined {
return getIndexedWorktreesById(state.worktreesByRepo ?? {}, worktreeId).find(
(worktree) => worktree.instanceId !== undefined
)?.instanceId

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 Wrong-host snapshot identity

When local and SSH workspaces share a path-derived worktree ID but have different instance IDs, this lookup publishes the first indexed instance without checking host ownership. The main deletion fence then rejects the recreated workspace's valid browser snapshot as an identity mismatch, leaving its browser tabs and pages absent.

Knowledge Base Used: Workspace and worktree lifecycle

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

Important

The rebase onto the modular runtime refactor restored the production fences but dropped this PR's main-process regression tests. The fence behavior is now entirely untested, and the PR body's test claims are stale.

Reviewed changes (delta since the prior pullfrog review at dae08d5)

  • Rebased onto the modular runtime refactor — the monolithic orca-runtime.ts / orca-runtime.test.ts were split into per-concern mixins and orca-runtime-tests/*.spec.ts.
  • Deletion fences restored in the new structure — the fence map moved to orca-runtime-runtime-id.ts, the accept gate plus rendererGeneration epoch fence to orca-runtime-sync-mobile-session-tabs.ts, the removal fence + browser teardown to orca-runtime-resolve-worktree-removal-target.ts, the paired-PTY rescue fence to orca-runtime-restore-live-paired-renderer-session-owned-mobile-terminals.ts, and folder deletion to RuntimeProjectGroupController.deleteFolderWorkspace (PTY teardown via teardownFolderWorkspacePtys, then cleanupRemovedFolderWorkspaceState → removeWorktreeMetadataAndHistory).

⚠️ Main-process regression tests dropped in the rebase

Every main-process test this PR added in earlier revisions is gone. The production fences were re-applied correctly, but nothing in the tree verifies them anymore.

Technical details
# Main-process fence tests lost during the modular refactor rebase

## Affected sites
- `git diff main...HEAD` lists 18 files and no main-process test file; the three remaining test files are all renderer-side (`worktree-context-menu-delete-intent.test.ts`, `sync-runtime-graph-workspace-publication.test.ts`, `folder-workspace-owner-routed-mutations.test.ts`).
- No `removedMobileSessionWorktreeIds` / `blockedPublicationEpochs` / `removedPublicationEpoch` / `acceptedPublicationEpoch` / `removedInstanceId` reference exists in any `*.spec.ts` — they appear only in the four production mixin files.
- The previously-added cases are all absent: folder deletion tombstone + PTY sweep + client-hosted browser close, `does not republish a removed worktree's client tabs to a same-id recreate`, `ignores a renderer graph that arrives after worktree removal`, `accepts an identity-less recreated snapshot only after a renderer epoch changes`, `fences an identity-less snapshot when deletion precedes the first publication`, `rejects an unseen legacy epoch from a different renderer generation`, and `does not rescue a paired PTY … during graph sync or inventory`.

## Required outcome
- Re-add these regression tests into the new `orca-runtime-tests/` layout (the natural homes are `worktree-removal-and-reconciliation*.spec.ts` and `mobile-session-tabs*.spec.ts`) so the accept gate, the `rendererGeneration` epoch fence, the paired-PTY rescue fence, and the folder-deletion fence/tombstone/PTY-sweep are each exercised.
- Update the PR body's "Tests" section, which still cites `orca-runtime.test.ts (1223 passed)` and the focused suites from the pre-rebase tree.

## Suggested approach (optional)
- The production mixins carry `@ts-nocheck -- mechanically split` headers; the restored fences in `orca-runtime-sync-mobile-session-tabs.ts`, `orca-runtime-resolve-worktree-removal-target.ts`, and `runtime-project-group-controller.ts` are the ground truth to mirror into tests.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Comment on lines +60 to +63
if (fence.blockedPublicationEpochs.has(snapshot.publicationEpoch)) {
blockedRecreatedWorktreeIds.add(snapshot.worktree)
return false
}

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 Same-generation recreation stays blocked

When an identity-less client deletes and recreates a workspace during one renderer generation, deletion blocks the renderer's publication epoch and the recreated workspace reuses that same epoch. This check therefore rejects every valid successor snapshot until the renderer reloads, leaving the recreated workspace's browser tabs and pages absent.

Knowledge Base Used:

Comment on lines +1381 to +1384
if (getIndexedWorktreesById(state.worktreesByRepo ?? {}, worktreeId).length > 1) {
mobileSessionSnapshotCacheByWorktree.delete(worktreeId)
continue
}

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 Host collisions suppress valid snapshots

When local and SSH workspaces share a path-derived worktree ID, this branch removes the cached snapshot and skips the worktree on every publication instead of selecting its owning host. Mobile clients consequently receive no terminal, editor, or browser state for the affected workspace while both host rows exist.

Knowledge Base Used: Workspace and worktree lifecycle

@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 (delta since the prior pullfrog review at e1845ed)

  • Fail-closed renderer guard for ambiguous worktree ids — buildMobileSessionTabSnapshots now skips any worktree id with more than one indexed row in getIndexedWorktreesById, refusing to publish a snapshot when local and remote hosts share the same id rather than attaching the wrong host's worktreeInstanceId. The guard is precise: folder workspace keys and single-row worktrees pass through unchanged.
  • Re-added main-process accept-gate test — graph-sync-mobile-snapshot-gating.test.ts now covers rejects a delayed renderer snapshot from the deleted occupant after recreation, exercising the removedInstanceId fence in syncMobileSessionTabs.
  • Renderer ambiguity test — does not publish an ambiguous worktree id across hosts locks in the new guard.

Both new tests pass in isolation, and the fail-closed guard is scoped to genuinely duplicated (multi-host) rows — single-row and folder-workspace publications are unaffected.

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

@Jinwoo-H
Jinwoo-H force-pushed the aug31-workspace-delete-browser-cleanup-audit branch from f208090 to 3ae73b3 Compare September 1, 2026 18:10

@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 (delta since the prior pullfrog review at f208090b)

  • Paired-PTY fence at the deletion boundary — removeWorktreeMetadataAndHistory now drops any pairedRendererSessionOwnedPtyIds entry whose PTY belongs to the removed worktree (scoped to the !preservesSameIdOwner branch), so a still-connected renderer-owned PTY that outlives the delete acknowledgement can no longer be rescued through restoreLivePairedRendererSessionOwnedMobileTerminals into a recreated occupant of the same path-derived id. This closes the gap the earlier removedMobileSessionWorktreeIds fence left open, since that fence only fires when worktree metadata is absent, not when it has been recreated.
  • Regression test — a new browser-capabilities.spec.ts case registers a paired PTY, marks it renderer-owned, removes the worktree, and asserts the PTY is dropped from ownership tracking, which fails against the pre-fix behavior.

The guard is precise: identity matching uses the same runtimeWorktreeIdsEqual path-identity comparator as the rescue path, and the cleanup is gated identically to the existing tombstone so a same-id owner on another host (preservesSameIdOwner) is not torn down.

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

- Folder-group delete no longer fails on a mixed-host group: an ambiguous
  connection skips the PTY sweep instead of rejecting the delete.
- Share one folder-workspace PTY teardown helper between the runtime
  removal path and the project-group controller.
- Simplify the mobile snapshot fence: identity-carrying frames are judged
  against the live catalog instanceId and clear the fence once the
  successor is accepted; identity-less frames are fenced by renderer
  generation. Drops the unbounded epoch bookkeeping.
- A fenced frame no longer triggers a resync request on every sync while
  the renderer still lists it as unchanged.
- Cross-host id collisions publish without an instanceId rather than
  blanking the mobile session for that workspace.
- Folder delete IPC always routes through the runtime; the store-only
  fallback and double notify are gone.
- Drop the redundant rescue-path tombstone check; ownership is purged at
  removal.
- Fence tests drive removeWorktreeMetadataAndHistory + syncWindowGraph
  instead of seeding the fence map, and add accept-after-recreate,
  no-resync, and ambiguous-host folder delete cases.

@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 (delta since the prior pullfrog review at 8afc766)

  • Simplified the deletion fence — removedMobileSessionWorktreeIds dropped the removedInstanceId memory and the acceptedPublicationEpoch / blockedPublicationEpochs epoch machinery in favor of { removedPublicationEpoch?, rejectedPublication? }. The accept gate now rejects any identity-carrying frame whose worktreeInstanceId mismatches the live catalog row's instanceId, and clears the fence on the first matching successor frame. This is sound because recreation always mints a fresh instanceId (randomUUID()), so "mismatch against live meta" is exactly "not the current occupant" — no removed-id memory needed.
  • Anti-resync-spiral flag — a rejected frame sets rejectedPublication, which suppresses resync requests for a worktree the renderer still lists as unchanged, so a fenced frame no longer ping-pongs a republish → reject loop.
  • Ambiguous cross-host ids publish identity-less instead of blanking — resolveWorktreeInstanceId returns undefined when getIndexedWorktreesById has more than one row, and buildMobileSessionTabSnapshots no longer skips those worktrees. This is a deliberate reversal of the earlier fail-closed guard: main's generation fence still gates identity-less frames, so resurrection safety is unchanged while the session is no longer blanked for the STA-4343 multi-host case.
  • Folder-delete teardown hardened — teardownFolderWorkspacePtys was extracted to folder-workspace-pty-teardown.ts; RuntimeProjectGroupController.deleteFolderWorkspace now catches the folder_workspace_connection_ambiguous throw (skips only the PTY sweep, still deletes); and registerRepoHandlers / registerFolderWorkspaceHandlers make runtime required, so the delete handler drops the dead store.removeFolderWorkspace fallback and always routes through runtime.
  • Regression tests restored — new graph-sync-deletion-fence.test.ts (5 cases) and runtime-project-group-controller-folder-delete.test.ts (2 cases) cover the accept gate, fence clearing, legacy-epoch fencing, resync suppression, and folder teardown ordering. All pass in isolation.

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

@Jinwoo-H
Jinwoo-H merged commit bed9734 into main Sep 2, 2026
31 checks passed
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Sep 3, 2026
* Prevent deleted workspace browser snapshot resurrection

* fix: tear down folder workspace browser tabs

* fix: fence pre-publication browser snapshots

* fix: route folder deletion through runtime cleanup

* chore: retrigger CI

* fix: sweep folder PTYs on runtime deletion

* fix: restore deletion fences after runtime refactor

* test: cover deleted renderer snapshot after recreation

* fix: avoid publishing ambiguous worktree snapshots

* fix: preserve optional worktree index state

* fix: fence paired PTYs on worktree removal

* fix: harden deletion fence and folder-delete teardown

- Folder-group delete no longer fails on a mixed-host group: an ambiguous
  connection skips the PTY sweep instead of rejecting the delete.
- Share one folder-workspace PTY teardown helper between the runtime
  removal path and the project-group controller.
- Simplify the mobile snapshot fence: identity-carrying frames are judged
  against the live catalog instanceId and clear the fence once the
  successor is accepted; identity-less frames are fenced by renderer
  generation. Drops the unbounded epoch bookkeeping.
- A fenced frame no longer triggers a resync request on every sync while
  the renderer still lists it as unchanged.
- Cross-host id collisions publish without an instanceId rather than
  blanking the mobile session for that workspace.
- Folder delete IPC always routes through the runtime; the store-only
  fallback and double notify are gone.
- Drop the redundant rescue-path tombstone check; ownership is purged at
  removal.
- Fence tests drive removeWorktreeMetadataAndHistory + syncWindowGraph
  instead of seeding the fence map, and add accept-after-recreate,
  no-resync, and ambiguous-host folder delete cases.

Mirror-Of: bed9734
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* Prevent deleted workspace browser snapshot resurrection

* fix: tear down folder workspace browser tabs

* fix: fence pre-publication browser snapshots

* fix: route folder deletion through runtime cleanup

* chore: retrigger CI

* fix: sweep folder PTYs on runtime deletion

* fix: restore deletion fences after runtime refactor

* test: cover deleted renderer snapshot after recreation

* fix: avoid publishing ambiguous worktree snapshots

* fix: preserve optional worktree index state

* fix: fence paired PTYs on worktree removal

* fix: harden deletion fence and folder-delete teardown

- Folder-group delete no longer fails on a mixed-host group: an ambiguous
  connection skips the PTY sweep instead of rejecting the delete.
- Share one folder-workspace PTY teardown helper between the runtime
  removal path and the project-group controller.
- Simplify the mobile snapshot fence: identity-carrying frames are judged
  against the live catalog instanceId and clear the fence once the
  successor is accepted; identity-less frames are fenced by renderer
  generation. Drops the unbounded epoch bookkeeping.
- A fenced frame no longer triggers a resync request on every sync while
  the renderer still lists it as unchanged.
- Cross-host id collisions publish without an instanceId rather than
  blanking the mobile session for that workspace.
- Folder delete IPC always routes through the runtime; the store-only
  fallback and double notify are gone.
- Drop the redundant rescue-path tombstone check; ownership is purged at
  removal.
- Fence tests drive removeWorktreeMetadataAndHistory + syncWindowGraph
  instead of seeding the fence map, and add accept-after-recreate,
  no-resync, and ambiguous-host folder delete cases.
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