Skip to content

fix: don't hydrate a headless mobile session for a repo that no longer exists - #9343

Merged
nwparker merged 1 commit into
stablyai:mainfrom
PannenetsF:fix/hydrate-mobile-session-repo-gate
Jul 24, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
PannenetsF:fix/hydrate-mobile-session-repo-gate

Conversation

@PannenetsF

@PannenetsF PannenetsF commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stops a deleted project from reappearing in the mobile/headless sidebar as a phantom "unknown" or duplicate workspace on boot.

ELI5: When you delete a project, some leftover bookkeeping could quietly bring it back the next time the app started up. This makes the app skip that stale leftover so the deleted project stays gone.

Root cause & fix: hydrateHeadlessMobileSessionTabsFromWorkspaceSession rebuilt session tabs by iterating every workspaceSession.tabsByWorktree entry with no repo gate. Those keys (${repoId}::${path}) are not pruned when a repo disappears from the client's view (e.g. removed on another client, or a stale browser-persisted session), so a leftover key re-materialized a phantom workspace with no live repo behind it. The fix computes liveRepoIds from store.getRepos() and early-continues on any entry whose parsed repoId is no longer live; unparseable keys (no ::, where splitWorktreeIdForFilesystem returns null) are left alone. This mirrors the pre-existing getKnownWorkspaceSessionWorktreeIds() gate in the same file — same source of truth, established pattern.

Scope: one file changed, src/main/runtime/orca-runtime.ts (+10 lines). Pure fix, no trade-offs; the guard is a local, conservative early-continue.

Original fix by @PannenetsF. Validated, rebased, and (where applicable) hardened via automated bug-bash review; original fix design preserved.

Screenshots

No visual change. This is a main-process hydration-logic change (src/main/runtime/orca-runtime.ts); no renderer UI is touched.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests (or explained why not)

Author's reported validation (not the full pnpm gates above):

  • npx oxlint src/main/runtime/orca-runtime.ts exited 0 with no warnings.
  • Existing hydrate tests confirm the guard does not drop legitimate tabs (repo live -> tabs still hydrate):
    • graph-sync-mobile-snapshot-gating.test.ts — 21 passed
    • orca-runtime.test.ts -t "hydrate" — 22 passed
  • No dedicated phantom-skip test was added; that specific branch is verified by code inspection against the established getRepos()-gate pattern rather than a new test.

AI Review Report

I reviewed this diff directly. The change adds a repo-liveness guard inside the tabsByWorktree iteration loop:

  • Correctness: liveRepoIds is built from this.store?.getRepos?.() ?? [] (optional-chained, empty-array fallback — no crash if store/method is absent). Each entry's repoId comes from splitWorktreeIdForFilesystem(entryWorktreeId)?.repoId. The guard if (ownerRepoId && !liveRepoIds.has(ownerRepoId)) continue only skips entries whose repo is confirmed missing. I verified in src/shared/worktree-id.ts that splitWorktreeIdForFilesystem returns null for keys without the :: separator, so ownerRepoId is undefined for unparseable keys and the guard falls through — they hydrate as before. Consistent with the description.
  • Edge cases: Empty repo store means an empty liveRepoIds, so all parseable entries would be skipped — acceptable, since with no live repos there is no legitimate workspace to hydrate. Folder-workspace UUID-suffixed IDs still parse to the correct repoId (the suffix only affects worktreePath), so those are gated by repo identity as intended.
  • Cross-platform (macOS/Linux/Windows): Checked. No keyboard shortcuts, shortcut labels, filesystem path construction, shell invocation, or Electron main/renderer boundary behavior is touched. The change is pure in-memory set/string logic and behaves identically on all three platforms. Notably relevant to the SSH/headless case (this is the headless mobile hydration path) and behaves the same there.

No fabricated results; the two test runs cited above are the author's, not re-run here.

Security Audit

Reviewed against the diff. No new input handling, command execution, path handling, authentication, secret, dependency, or IPC surface changes. The change reads existing in-memory repo IDs and filters an existing iteration; it is strictly more restrictive (it can only skip entries, never add or widen access). No security concerns.

Notes

  • Affects the headless/mobile session hydration path specifically, which is relevant to the SSH/remote use case.
  • Follow-up: no test covers the phantom-skip branch itself; a targeted test would close the residual coverage gap noted above.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Workspace session tab hydration now builds a set of live repository IDs from the store, parses persisted worktree keys, and skips entries associated with repositories no longer present. Unparseable worktree keys continue through hydration unchanged. Comments document the ${repoId}::${path} key format and stale-session filtering behavior.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 matches the main change: preventing hydration of stale headless mobile sessions for deleted repos.
Description check ✅ Passed All required template sections are present, and the testing, review, security, and notes sections are substantially filled in.

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.

…r exists

`hydrateHeadlessMobileSessionTabsFromWorkspaceSession` iterates
`workspaceSession.tabsByWorktree` with no repo gate. Those keys are
`${repoId}::${path}` and are not pruned when a repo disappears from this
client's view, so a stale key re-materializes a phantom "unknown"/duplicate
workspace with no live repo behind it, on boot, with no `session-created` event.

Skip entries whose parsed repoId is not in the live `repos`; leave unparseable
keys alone (conservative). Defensive complement to the delete-path (stablyai#9025) and
load-time (stablyai#9200) fixes — this closes the mobile/headless hydration path.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@nwparker
nwparker force-pushed the fix/hydrate-mobile-session-repo-gate branch from 3f690d8 to d72a458 Compare July 23, 2026 11:48
@nwparker
nwparker merged commit c2371c0 into stablyai:main Jul 24, 2026
@nwparker

Copy link
Copy Markdown
Contributor

Thanks so much for this, @PannenetsF — don't hydrate a headless mobile session for a repo that no longer exists. Verified (fail-on-main/pass-on-branch), rebased on latest main, reviewed, and merged. Really appreciate it! 🙏

AmethystLiang added a commit that referenced this pull request Jul 24, 2026
Main's headless tab hydrate (#9343) skips worktree keys whose repo is not
in getRepos. Retirement tests that rebuild mobile tabs from a persisted
session now advertise the fixture repo as live so PR Checks merge stays green.
AmethystLiang added a commit that referenced this pull request Jul 24, 2026
…10429)

* Fix fork PR/MR worktree creation race via durable review-head refs

When creating a fork PR/MR worktree, concurrent `git fetch origin` operations
clobber the shared FETCH_HEAD, causing the wrong commit to be checked out.
Fetch PR/MR heads into dedicated per-review refs (`refs/orca/pull/<N>`,
`refs/orca/merge-requests/<N>`) that persist and isolate each head from other
fetches. Gracefully keep the compare-base when the fetch fails but the local
ref already exists, avoiding silent fallback to the wrong branch on transient
network errors.

* Bound PR/MR head fetches with 60s timeout

Prevent PR/MR creation from hanging when a remote is stalled or
unreachable. Both GitHub and GitLab head fetches now enforce a
60-second timeout, matching the bound used in the create-path
fetch. Durable refs (refs/orca/pull/*, refs/orca/merge-requests/*)
decouple the ref from FETCH_HEAD, preserving legacy client semantics.

* test: align CI expectations with main PowerShell/sparse regressions

PR checks merge into main, which recently changed PowerShell launch args
(cwd restore after profiles) and sparse-checkout detection (require
core.sparseCheckout). Derive PowerShell spawn args from the production
resolver, mock the sparse config flag, reset shared worktree list scan
cache between tests, and stop requiring floating polls to avoid getRepos
hydration.

* Address review follow-ups on durable review-head refs

- Unify PR review-head remote selection: local and SSH GitHub paths share
  resolveGitHubReviewHeadRemote, which prefers the remote mapping to the
  hosting GitHub project (upstream before origin, matching work-item/API
  candidate order) so contributor clones fetch refs/pull from the repo
  that actually hosts the PR.
- Soft-keep durable review heads: when the PR/MR head fetch fails but
  refs/orca/pull/<N> / refs/orca/merge-requests/<iid> still resolves,
  keep the pinned SHA (warn) instead of failing resolve, mirroring the
  compare-base fallback. Extracted shared compare-base soft-keep into
  compare-base-ref-fetch.ts.
- Extract fetchGitLabMergeRequestHeadRef (local + SSH) parallel to the
  GitHub helper; bound its local fetch with the shared 60s timeout.
- Share relay-style fetch validation (positive safe-integer id, remote
  not starting with "-") between relay and local helpers via
  review-head-tracking-ref.ts; move REVIEW_HEAD_FETCH_TIMEOUT_MS there.
- Drop the githubPullRequestHeadLocalRef re-export; resolve head SHAs via
  rev-parse --verify <ref>^{commit}.
- Add GitLab anti-FETCH_HEAD regression test plus durable-head soft-keep
  and remote-selection unit tests.

Co-authored-by: Orca <[email protected]>

* test: supply live getRepos for terminal-retirement hydrates

Main's headless tab hydrate (#9343) skips worktree keys whose repo is not
in getRepos. Retirement tests that rebuild mobile tabs from a persisted
session now advertise the fixture repo as live so PR Checks merge stays green.

* fix(editor): extract RichMarkdownEditor props to stay under max-lines

Main's SSH external-image wiring (#10323) pushed RichMarkdownEditor.tsx over
the 400-line tsx budget, failing PR Checks lint on every merge into main.
Move the props type into a sibling module so the component stays under the
limit without disabling max-lines.

* Make durable review-head refs remote-identity scoped

Embed remote name + URL hash into refs/orca/pull|merge-requests refs to prevent soft-keep from serving wrong project's PR/MR when FETCH_HEAD is clobbered by concurrent fetch. Fetch functions now return the written ref path (writer-authoritative) so callers rev-parse exactly what was fetched, not re-derive identity. Soft-keep only applies to transient errors (timeout, network); fails hard on missing refs, auth failures, and stale relay. Relay returns localRef so client avoids re-hashing (URL normalization can disagree).

---------

Co-authored-by: Orca <[email protected]>
brennanb2025 added a commit that referenced this pull request Jul 24, 2026
…ry tab (#10437)

* fix(runtime): stop the headless hydration repo gate from dropping every tab

#9343 gated headless mobile-session hydration on the live repo list, but read
it as `this.store?.getRepos?.() ?? []`. A store that cannot report repos then
yields an empty set, which reads as "every repo is gone" and skips every
parseable session key — so no tabs hydrate at all. It also called getRepos on
every hydrate, including the hot floating-tab poll path that is contractually
free of repo/provider inventory work.

Resolve the inventory lazily and only for keys that parse to a repoId, and keep
`null` (unavailable) distinct from an empty list (all repos really gone). An
absent list now fails open; a known list still prunes as #9343 intended.

Fixes 3 tests that have been failing on main since #9343 landed:
orca-runtime-terminal-retirement (2) and orca-runtime (1).

* refactor(editor): extract the pending-focus effect to clear the max-lines cap

#8083 pushed RichMarkdownEditor.tsx to 404 counted lines against the 400-line
.tsx cap, failing lint for every PR that merges current main. The Explorer
find-focus request is self-contained, so it moves to its own hook.
brennanb2025 added a commit that referenced this pull request Jul 24, 2026
…10443)

#9343 broke two contracts at once and #10437 fixed both, but neither is
asserted: #10429 repaired the failing tests by deleting the poll assertion and
by handing the retirement store a live repo, so a revert would land silently.

Restore `expect(getRepos).not.toHaveBeenCalled()` on the floating-tab poll, and
add a hydrate case for a store that cannot report repos. Verified both fail
against the pre-#10437 code: the poll assertion reports getRepos "called 2
times", and the hydrate case returns [] instead of the persisted tab.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…r exists (stablyai#9343)

`hydrateHeadlessMobileSessionTabsFromWorkspaceSession` iterates
`workspaceSession.tabsByWorktree` with no repo gate. Those keys are
`${repoId}::${path}` and are not pruned when a repo disappears from this
client's view, so a stale key re-materializes a phantom "unknown"/duplicate
workspace with no live repo behind it, on boot, with no `session-created` event.

Skip entries whose parsed repoId is not in the live `repos`; leave unparseable
keys alone (conservative). Defensive complement to the delete-path (stablyai#9025) and
load-time (stablyai#9200) fixes — this closes the mobile/headless hydration path.

Co-authored-by: fanyunqian.1 <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#10429)

* Fix fork PR/MR worktree creation race via durable review-head refs

When creating a fork PR/MR worktree, concurrent `git fetch origin` operations
clobber the shared FETCH_HEAD, causing the wrong commit to be checked out.
Fetch PR/MR heads into dedicated per-review refs (`refs/orca/pull/<N>`,
`refs/orca/merge-requests/<N>`) that persist and isolate each head from other
fetches. Gracefully keep the compare-base when the fetch fails but the local
ref already exists, avoiding silent fallback to the wrong branch on transient
network errors.

* Bound PR/MR head fetches with 60s timeout

Prevent PR/MR creation from hanging when a remote is stalled or
unreachable. Both GitHub and GitLab head fetches now enforce a
60-second timeout, matching the bound used in the create-path
fetch. Durable refs (refs/orca/pull/*, refs/orca/merge-requests/*)
decouple the ref from FETCH_HEAD, preserving legacy client semantics.

* test: align CI expectations with main PowerShell/sparse regressions

PR checks merge into main, which recently changed PowerShell launch args
(cwd restore after profiles) and sparse-checkout detection (require
core.sparseCheckout). Derive PowerShell spawn args from the production
resolver, mock the sparse config flag, reset shared worktree list scan
cache between tests, and stop requiring floating polls to avoid getRepos
hydration.

* Address review follow-ups on durable review-head refs

- Unify PR review-head remote selection: local and SSH GitHub paths share
  resolveGitHubReviewHeadRemote, which prefers the remote mapping to the
  hosting GitHub project (upstream before origin, matching work-item/API
  candidate order) so contributor clones fetch refs/pull from the repo
  that actually hosts the PR.
- Soft-keep durable review heads: when the PR/MR head fetch fails but
  refs/orca/pull/<N> / refs/orca/merge-requests/<iid> still resolves,
  keep the pinned SHA (warn) instead of failing resolve, mirroring the
  compare-base fallback. Extracted shared compare-base soft-keep into
  compare-base-ref-fetch.ts.
- Extract fetchGitLabMergeRequestHeadRef (local + SSH) parallel to the
  GitHub helper; bound its local fetch with the shared 60s timeout.
- Share relay-style fetch validation (positive safe-integer id, remote
  not starting with "-") between relay and local helpers via
  review-head-tracking-ref.ts; move REVIEW_HEAD_FETCH_TIMEOUT_MS there.
- Drop the githubPullRequestHeadLocalRef re-export; resolve head SHAs via
  rev-parse --verify <ref>^{commit}.
- Add GitLab anti-FETCH_HEAD regression test plus durable-head soft-keep
  and remote-selection unit tests.

Co-authored-by: Orca <[email protected]>

* test: supply live getRepos for terminal-retirement hydrates

Main's headless tab hydrate (stablyai#9343) skips worktree keys whose repo is not
in getRepos. Retirement tests that rebuild mobile tabs from a persisted
session now advertise the fixture repo as live so PR Checks merge stays green.

* fix(editor): extract RichMarkdownEditor props to stay under max-lines

Main's SSH external-image wiring (stablyai#10323) pushed RichMarkdownEditor.tsx over
the 400-line tsx budget, failing PR Checks lint on every merge into main.
Move the props type into a sibling module so the component stays under the
limit without disabling max-lines.

* Make durable review-head refs remote-identity scoped

Embed remote name + URL hash into refs/orca/pull|merge-requests refs to prevent soft-keep from serving wrong project's PR/MR when FETCH_HEAD is clobbered by concurrent fetch. Fetch functions now return the written ref path (writer-authoritative) so callers rev-parse exactly what was fetched, not re-derive identity. Soft-keep only applies to transient errors (timeout, network); fails hard on missing refs, auth failures, and stale relay. Relay returns localRef so client avoids re-hashing (URL normalization can disagree).

---------

Co-authored-by: Orca <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ry tab (stablyai#10437)

* fix(runtime): stop the headless hydration repo gate from dropping every tab

stablyai#9343 gated headless mobile-session hydration on the live repo list, but read
it as `this.store?.getRepos?.() ?? []`. A store that cannot report repos then
yields an empty set, which reads as "every repo is gone" and skips every
parseable session key — so no tabs hydrate at all. It also called getRepos on
every hydrate, including the hot floating-tab poll path that is contractually
free of repo/provider inventory work.

Resolve the inventory lazily and only for keys that parse to a repoId, and keep
`null` (unavailable) distinct from an empty list (all repos really gone). An
absent list now fails open; a known list still prunes as stablyai#9343 intended.

Fixes 3 tests that have been failing on main since stablyai#9343 landed:
orca-runtime-terminal-retirement (2) and orca-runtime (1).

* refactor(editor): extract the pending-focus effect to clear the max-lines cap

stablyai#8083 pushed RichMarkdownEditor.tsx to 404 counted lines against the 400-line
.tsx cap, failing lint for every PR that merges current main. The Explorer
find-focus request is self-contained, so it moves to its own hook.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#10443)

stablyai#9343 broke two contracts at once and stablyai#10437 fixed both, but neither is
asserted: stablyai#10429 repaired the failing tests by deleting the poll assertion and
by handing the retirement store a live repo, so a revert would land silently.

Restore `expect(getRepos).not.toHaveBeenCalled()` on the floating-tab poll, and
add a hydrate case for a store that cannot report repos. Verified both fail
against the pre-stablyai#10437 code: the poll assertion reports getRepos "called 2
times", and the hydrate case returns [] instead of the persisted tab.
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.

4 participants