Skip to content

Editor tabs multiply on every session save — same file restored as 17–20 tabs #23967

Done

Description

@malgcheong

Repo: stablyai/orca
Version: 1.4.183 (installed 2026-08-15). Latest at time of writing: 1.4.217.
OS: Windows 11 Pro 26200
State file: %APPDATA%\orca\profiles\local-default\orca-data.json


Summary

workspaceSession.openFilesByWorktree and workspaceSession.unifiedTabs are appended to
rather than replaced/deduplicated when the session is persisted. Every launch re-adds the same
files, so the editor fills with duplicate tabs of a handful of documents.

Closing a tab does not help: the user is closing one of ~17 identical copies, so the same
document reappears immediately. Editing the JSON while Orca runs does not help either — the
in-memory session is authoritative and is written back on exit.

Measured state (2026-09-30)

Two workspaces, 5 real files total:

workspace openFiles entries unique files editor tabs unique tab ids
A 71 4 24 16
B 8 1 8 6
total 79 5 32 22

Per-file counts in workspace A:

20  PM-DECISIONS-20260923.html
17  20260805-gcp-deploy-topology.md
17  20260818-tra-front-noti-group-mapping.txt
17  WISH_CHAR_SEED_SAMPLE_MARIADB.sql

Growth observed over four days (same 4–5 files throughout):

09-27   18 entries
09-28   37 entries
09-28   94 entries
09-30   79 entries   (after a manual cleanup on 09-28)

Three distinct defects

1. runtimeEnvironmentId is part of the tab identity

Editor tab ids are built as:

editor:<worktreeId>:<runtimeEnvironmentId>:<urlencoded filePath>

Two distinct runtimeEnvironmentId values were present for the same files in one workspace —
842ee5ff-… (22 entries) and 1456a0bf-… (49 entries). Because the id differs, dedup does not
match and the whole file set is duplicated per environment.

This is expected to worsen with remote/paired runtimes: connecting from another machine
introduces another environment id and therefore another full copy of every open file.

2. Path separators are inconsistent within the same id scheme

For the same file, some ids encode the path with forward slashes and some with backslashes:

…%3A%3AD%3A%5Cworkspace_idle%5Cclaude-task:…:D%3A%5Cworkspace_idle%5Cclaude-task%5Chandoffs%5C20260805-gcp-deploy-topology.md
…                                          :…:…%2Fhandoffs%2F20260818-tra-front-noti-group-mapping.txt

%5C = \, %2F = /. String comparison therefore treats one file as two.

3. Exactly-identical ids appear more than once in unifiedTabs

Independent of (1) and (2), the same tab id occurs twice in the array (observed id ×2 for three
different files). This is a plain missing-dedup on append, not an identity problem.

tabGroups[worktreeKey].tabOrder mirrors the duplication (length 18 for 4 real files).

Expected behaviour

On persist, openFilesByWorktree and unifiedTabs should be replaced by the current set, and
identity for an open file should be a normalized file path (case- and separator-normalized),
independent of runtimeEnvironmentId. tabOrder should not contain repeated ids.

Reproduction

  1. Open a workspace and open 3–4 files in the editor.
  2. Quit and relaunch Orca several times (ideally with more than one runtime environment,
    e.g. local plus a paired remote).
  3. Inspect workspaceSession.openFilesByWorktree[<worktreeKey>] — the array grows each launch
    while the set of distinct filePath values stays constant.

Workaround in use

A script run while Orca is closed that, per workspace:

  • dedups openFilesByWorktree by normalized filePath,
  • keeps the first editor tab per normalized entityId in unifiedTabs,
  • removes dropped ids from tabGroups[].tabOrder and repoints activeTabId /
    activeTabIdByWorktree / activeFileIdByWorktree,
  • leaves terminal and browser tabs untouched.

Result: openFiles 79 → 5, editor tabs 32 → 5, with every actually-open document preserved.

It has to run before launch, because a running Orca overwrites the file from memory on exit.

Note

Release notes for 1.4.215–1.4.217 do not mention editor tabs, open files or session restore, so
this may still be present on latest. Happy to re-measure on 1.4.217 if useful.

Activity

  1. ggbdpq commented on Sep 30, 2026

    @ggbdpq
    Contributor

    Taking this one. I traced the write path with a probe driving the real store (hydrateTabsSession → hydrateEditorSession → mirror apply / openFile → buildWorkspaceSessionPayload), and the growth loop is:

    Root cause in one sentence: an open file's identity is the raw path string × runtimeEnvironmentId, and hydration recasts every persisted row to an owned id (editor:<wt>:<env>:<encoded path>), so the session mirror's lookup by raw path always misses and re-appends a (raw path, current env) row each launch — while rows from older environments are never re-keyed or culled, so they only accumulate. Probe evidence: with the env id changing between launches, row count grew 2→3→4→5→6 (+1 per launch, zero user interaction); with a stable env, the mirror settles into two byte-identical persisted rows per file — matching defect 3's "exactly identical ids ×2".

    I'm splitting this into two PRs, because the full fix needs a semantic decision:

    1. Stop-the-bleeding (PR incoming shortly): fold exact duplicate (filePath, worktreeId, runtimeEnvironmentId) tuples on the persist side (buildEditorSessionData), aligned with what hydration already does — hydrate-editor-session.ts treats repeated records for the same owner as corruption and keeps one row (fix(session): deduplicate editor records during restore #17370), so folding them at persist is lossless for restore. This stops new identical-tuple rows and cleans existing ones on the next save. Your shutdown dedup script (79 → 5 with every document preserved) is empirical evidence this fold is safe. Split-tab sharing is unaffected — it lives in unifiedTabs (multiple tabs sharing one OpenFile's entityId), not in repeated open-file rows.

    2. Real fix (follow-up, needs a maintainer decision): converge identity across environment changes — re-key old-owner rows to the current owner at env transitions or mirror apply, plus normalize path separators (defect 2, %5C vs %2F). One caution on the "normalized path independent of runtimeEnvironmentId" proposal in the issue: the same absolute path on a different machine's runtime is a genuinely different file, so cross-environment folding must be limited to a same-worktree ownership migration, not applied globally by path. I'll open a separate issue with the data and two candidate approaches for that decision.

    Defect 3's tabOrder duplicates mirror the open-file row duplication (the unified-tab layer already dedupes on hydrate), so PR 1 shrinks it as a side effect; the tab layer itself needs no change.

  2. AmethystLiang commented on Sep 30, 2026

    @AmethystLiang
    Contributor

    We're improving how the environment is wired in. This will be fixed later this week

  3. kyeolee89 commented on Oct 3, 2026

    @kyeolee89

    Same on macOS with 1.4.219, and I think I found what drives the growth: connected peers re-inject each other's openFilesByWorktree on every connect. Clearing one machine never sticks, because the copies live on the other machines.

    Setup

    A laptop (client) paired with two remote Orca servers over a private VPN — call them peer A (a workstation) and peer B (a desktop). All three run the desktop app.

    Measurements

    I ran a read-only watcher polling profile-state.db every 20s, logging per-file entry counts for both workspaceSession.openFilesByWorktree and workspaceSessionsByHostId[*].openFilesByWorktree, together with the state of the 6768 sockets at each change.

    1. Closed tabs come back the moment a peer connects

    23:09:23  12 -> 8 entries      (I closed four image tabs by hand)
       -- local/projA|image1.png: x1 -> x0
       -- local/projA|image2.png: x1 -> x0
       ...
       out: peerB(ESTABLISHED)    in: none
    
    23:10:23  8 -> 49 entries      (peer A connects)
       ++ hostB/app|File1.kt:        x1 -> x6
       ++ hostA/projC|script1.sh:    x1 -> x4
       ++ local/projA|image1.png:    x0 -> x3
       ++ local/projA|image2.png:    x0 -> x3
       ++ local/projB|script2.py:    x1 -> x4
       out: peerA(ESTABLISHED), peerB(ESTABLISHED)
       in : peerA -> me:6768 (ESTABLISHED)
    

    One minute after being closed, the same files were back at x3.

    2. Direction does not matter

    I first assumed only inbound connections (a peer dialing me) did this. It isn't so — after emptying both domains to 0 with the app stopped:

    23:33:10  cleanup: workspaceSession 26 -> 0, workspaceSessionsByHostId 10 -> 0
    23:33:33  0 -> 32 entries
       out: peerB(ESTABLISHED)     in: none      <-- outbound only
    

    Peer A was powered down at this point. Peer B alone restored 32 entries, including peer A's host session (hostA/projC|script1.sh and friends) — so a peer also propagates third-party host sessions it is holding.

    3. The copies are sitting on the peers

    I opened a terminal on peer A (orca terminal create --environment …) and read its own profile-state.db:

    workspaceSessionsByHostId   total 37
      x6  hostB/app|File1.kt
      x4  me/projB|script1.py
      x4  me/projB|script2.py
      x4  me/projB|script3.py
      x3  me/projA|image1.png
      x2  me/projA|image2.png
      ...
    

    Peer A was holding 37 entries of my laptop's session — the exact files I had been deleting locally all evening. Peer B held an equivalent snapshot.

    So the per-file count is not a local accumulator. Each peer keeps its own stale copy and merges it in additively on connect, which is why counts climb by +2/+3/+5 in one step rather than +1, and why clearing a single machine is always undone by whichever peer connects next. Emptying them one at a time cannot converge; every peer has to be emptied in the same window.

    This looks like the additive-union hydration described in #21341, but applied to openFilesByWorktree rather than tabsByWorktree.

    Also worth noting for anyone scripting around this

    • Restarting the app normalizes rather than worsens the counts (I saw 38 -> 12, every file collapsing to x1), so a restart is not what drives the growth.
    • pgrep -f /Applications/Orca.app/Contents/MacOS/Orca does not match the main process on macOS (only the Helpers), presumably because the hardened bundle's argv isn't readable. ps -A -o pid=,comm= does. A liveness check built on pgrep silently reports the app as stopped while it is still running.

    Version

    Reproduced on 1.4.219 / macOS. The 1.4.217–219 release notes contain no fix for this.

  4. BearMett commented on Oct 6, 2026

    @BearMett
    Contributor

    @kyeolee89 thanks for the measurements. They match what I found: a paired desktop republished the tabs it was only mirroring from a peer, so each peer kept handing your laptop's session back. #25877 stops that, and the mirror marker now survives restart.

    Two caveats from your setup: every paired machine needs the fix before the loop fully stops, and rows already saved before the fix are not cleaned by it (#21125 / #24191 cover those).

  5. 4riel commented on Oct 8, 2026

    @4riel

    Still present on 1.4.216 (Windows 11 desktop) with a paired macOS remote — reproduced today, 2026-10-08.

    Measured from the live store (profile-state.db, workspaceSession domain, rev 36589):

    worktree unifiedTabs duplicates
    …::C:/Users/ariel/Code/Tradify 7 poc-multilogin-seed.sql ×2, report.md ×2, 2026-09-17-…-poc.md ×2
    …::C:/Users/ariel/Code/Tradify/workdeck 487 automation-run terminal tabs repeated dozens of times ("Run WorkDeck Sentinel clock", "Run PR babysitting workflow", …)
    …::…/orca/worktree 111 "Check newly opened PRs" ×~70, README.md ×4

    So the unbounded growth isn't limited to editor tabs — automation-run terminal tabs accumulate identically and nothing prunes them.

    Live repro: clicking the X on an editor tab (report.md) returns success but the tab stays — an identical stored copy takes its place instantly. Middle-click is also a no-op.

    Adjacent symptom (happy to split into its own issue): after orca project setup-delete + project setup-existing-folder re-add — which created a new repoId 1fa2faec… — workspaceSession.activeRepoId / activeWorktreeId / activeTabId still point at the deleted repoId 71d7fff8…, and the sidebar option is still keyed to it (worktree-list-option-repo%3A71d7fff8…); clicking it doesn't navigate. The orphaned editor tabs now render "Unable to load file — The host couldn't find this file's workspace" and still can't be closed from the tab strip. Deleting/re-adding a workspace therefore never resets its session state — the ghost keeps the stale tabs alive.

    Local workaround I used: while Orca is fully closed, dedupe unifiedTabs/openFilesByWorktree by normalized path in profile_state_documents, remap the session keys from the deleted repoId onto the re-added one, and scrub dropped tab ids from tabGroups[].tabOrder + the active* pointers. Verified: 7 → 5 tabs with the duplicates gone and the workspace rebound to the live repoId.

  6. nwparker commented on Dec 1, 2026

    @nwparker
    Contributor

    Fixed by PR #19444 (253fa43256a0), PR #31925 (ea60ec5d7cb9), and PR #33259 (917899bf8df8): buildHydratedEditorSessionState (src/renderer/src/store/slices/editor/hydration/hydrated-editor-session-state.ts) and dedupeEditorTabsWithinGroups (src/renderer/src/store/slices/tabs/tab-hydration-records.ts) deduplicate persisted openFilesByWorktree and editor tabs on hydration, and isMobilePublishableOpenFile skips mirrored tabs so paired desktops no longer republish each other's editor tabs across restarts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions