Skip to content

[Bug]: Session restore duplicates editor tab records in orca-data.json — closed editor tab resurrects on every restart #17185

Closed

Description

@DamChan0

Operating system

Linux (Debian-based, kernel 7.0.0-30-generic, AppImage build)

Orca version

v1.4.137 (X-AppImage-Version from the generated desktop entry)

Details

Short summary:
An editor tab (a PNG image preview) resurrects on every app restart / window reload. Closing the tab does not stick. The persisted session state in orca-data.json accumulates duplicated records for the same file — session restore appears to re-add a new tab record (new uuid, fresh createdAt) while leaving the previous openFilesByWorktree entries behind, so closing the visible tab only removes one of several stale records and the file reopens on the next restore.

What happened?

  1. A PNG file (.scratch/armor_cuirass_8dir/cuirass_8dir_sheet_preview.png inside a git worktree workspace) was opened as an editor tab on Aug 23.
  2. Since then, across restarts/window reloads, the tab keeps coming back. Closing it does not persist; after the next reload it is present (and active) again.
  3. The file itself is never touched — mtime is still Aug 23, and no process re-opens it. The reopening comes purely from session restore.

State evidence (from ~/.config/orca/profiles/local-default/orca-data.json, single worktree key <worktreeId>::/home/damchan/project/Godot/Godot_rust.char3d):

  • workspaceSession.openFilesByWorktree[<key>] contains 3 identical records for the same filePath/relativePath (differing only in editor-entity uuid).
  • workspaceSession.unifiedTabs[<key>] contains 2 editor tab entries for the same entityId (the PNG path), same createdAt (1788002466152 = the moment of today's window reload), sortOrder 0 and 1.
  • workspaceSession.activeFileIdByWorktree[<key>] still points at this file (with a third, different pane uuid embedded in the id).
  • tabGroups[<key>][0].tabOrder contains an editor: id for this file with yet another uuid that matches neither of the two unifiedTabs entries.

So each restore cycle seems to mint a new editor-entity uuid for the same file and append records, while close only removes the currently-rendered one. The stale openFilesByWorktree + activeFileIdByWorktree records then re-materialize the tab on the next restore.

While inspecting I also found the same pattern with a file that fails to open: a stale editor tab record for ~/.orca/keybindings.json (file does not exist on disk) persisted under the global-floating-terminal session and restored every launch.

How can we reproduce it? (best effort — this accumulated over normal use)

  1. Open an image file as an editor tab in a worktree workspace.
  2. Reload the window / restart Orca a few times with the tab open.
  3. Close the tab, restart Orca.
  4. Tab is back and active. Inspect orca-data.json: duplicated openFilesByWorktree records and duplicated unifiedTabs editor entries for that file.

Anything else that might help:

Activity

  1. DamChan0 commented on Aug 29, 2026

    @DamChan0
    Author

    Sharing the workaround I'm running locally until this is fixed, in case it helps others (or serves as a reference for the restore-time fix).

    Approach

    Since the duplicated/stale records live entirely in orca-data.json, a cleaner script can repair the persisted session offline:

    1. Dedupe — in each worktree session, keep only the first openFilesByWorktree record per filePath and the first unifiedTabs editor entry per entityId, drop the rest.
    2. Prune missing files — drop editor records whose target file no longer exists on disk (this also covers the "failed to open / reload" tabs that keep restoring, e.g. a stale ~/.orca/keybindings.json tab I found under global-floating-terminal).
    3. Repair references — remove the dropped tab ids from tabGroups[].tabOrder, and delete activeFileIdByWorktree entries whose percent-decoded path no longer exists.
    4. Safety — dry run by default; --apply refuses to write while Orca is running (otherwise Orca overwrites the cleaned file with its in-memory state on exit), and backs up the original before writing.

    To make it self-healing I also wrapped the launcher so the cleaner runs before every start — duplicates may still accumulate during a session, but they never survive a restart.

    Essentially the same logic would work as an upstream fix if applied at session-restore time: dedupe by entityId, skip records whose file is gone, and purge all records for a file when its tab is closed (not just the current editor-entity uuid).

    orca-tab-clean

    #!/usr/bin/env python3
    """Clean stale/duplicated editor-tab records from orca-data.json.
    
    orca's session-restore can duplicate editor tab records (same file, new uuid)
    on window reload; closing the visible tab leaves stale records, so the tab
    resurrects on every restart. This dedupes them and prunes records pointing to
    files that no longer exist.
    
    Usage:
      orca-tab-clean                  dry run (default)
      orca-tab-clean --apply          write changes (refuses while orca is running)
      orca-tab-clean --remove STR     also purge any record containing STR
    """
    import json
    import os
    import shutil
    import subprocess
    import sys
    import time
    import urllib.parse
    
    PATH = os.path.expanduser("~/.config/orca/profiles/local-default/orca-data.json")
    
    removed = []
    
    
    def record_path_exists(path):
        return isinstance(path, str) and os.path.exists(path)
    
    
    def clean_session(ws, marker):
        def is_purged(obj):
            return marker and marker in json.dumps(obj)
    
        removed_tab_ids = set()
    
        for key, files in list(ws.get("openFilesByWorktree", {}).items()):
            kept, seen = [], set()
            for f in files:
                fp = f.get("filePath", "")
                if is_purged(f) or not record_path_exists(fp) or fp in seen:
                    removed.append(f"openFiles[{key}]: {fp}")
                    continue
                seen.add(fp)
                kept.append(f)
            ws["openFilesByWorktree"][key] = kept
    
        for key, tabs in list(ws.get("unifiedTabs", {}).items()):
            kept, seen = [], set()
            for t in tabs:
                if t.get("contentType") != "editor":
                    kept.append(t)
                    continue
                entity = t.get("entityId", "")
                if is_purged(t) or not record_path_exists(entity) or entity in seen:
                    removed.append(f"unifiedTabs[{key}]: {t.get('label')}")
                    removed_tab_ids.add(t.get("id"))
                    continue
                seen.add(entity)
                kept.append(t)
            ws["unifiedTabs"][key] = kept
    
        for key, groups in ws.get("tabGroups", {}).items():
            for g in groups:
                order = g.get("tabOrder", [])
                kept = [
                    i for i in order
                    if i not in removed_tab_ids and not (marker and marker in i)
                ]
                if len(kept) != len(order):
                    removed.append(f"tabGroups[{key}]: {len(order) - len(kept)} tabOrder id(s)")
                    g["tabOrder"] = kept
    
        for key, val in list(ws.get("activeFileIdByWorktree", {}).items()):
            if not isinstance(val, str):
                continue
            tail = urllib.parse.unquote(val.rsplit(":", 1)[-1])
            if (marker and marker in val) or (tail.startswith("/") and not os.path.exists(tail)):
                removed.append(f"activeFileId[{key}]")
                del ws["activeFileIdByWorktree"][key]
    
    
    def orca_running():
        return subprocess.run(
            ["pgrep", "-f", "orca.appimage|mount_orca"], capture_output=True
        ).returncode == 0
    
    
    def main():
        apply = "--apply" in sys.argv
        marker = None
        if "--remove" in sys.argv:
            marker = sys.argv[sys.argv.index("--remove") + 1]
    
        if not os.path.exists(PATH):
            print("orca-data.json not found:", PATH)
            return 0
    
        with open(PATH) as f:
            data = json.load(f)
    
        clean_session(data.get("workspaceSession", {}), marker)
        for host_ws in data.get("workspaceSessionsByHostId", {}).values():
            if isinstance(host_ws, dict):
                clean_session(host_ws, marker)
    
        print(f"{'APPLY' if apply else 'DRY RUN'}: {len(removed)} record(s)")
        for r in removed:
            print(" -", r)
    
        if not (apply and removed):
            return 0
        if orca_running():
            print("REFUSED: orca is running — it would overwrite the cleaned file on exit.")
            print("Quit orca fully, then re-run with --apply.")
            return 1
    
        backup = PATH + f".pre-clean.{int(time.time())}"
        shutil.copy2(PATH, backup)
        with open(PATH, "w") as f:
            json.dump(data, f, ensure_ascii=False, separators=(",", ":"))
        print("backup:", backup)
        print("written:", PATH)
        return 0
    
    
    if __name__ == "__main__":
        sys.exit(main())

    Launch wrapper (Linux AppImage)

    #!/usr/bin/env bash
    # Launch wrapper for Orca: clean stale/duplicated editor-tab session records
    # before start. orca-tab-clean refuses to write while orca is already running,
    # so a second launch is a safe no-op.
    "$HOME/.local/bin/orca-tab-clean" --apply || true
    exec env DESKTOPINTEGRATION=1 "$HOME/AppImages/orca.appimage" --no-sandbox "$@"

    Then point the desktop entry at the wrapper (Exec=~/.local/bin/orca-launch %U).

    Result on my affected state

    Dry run against the state described in the report:

    DRY RUN: 6 record(s)
     - openFiles[<worktreeKey>]: .../cuirass_8dir_sheet_preview.png   (x2 duplicates removed, 1 kept)
     - unifiedTabs[global-floating-terminal]: keybindings.json        (target file missing on disk)
     - unifiedTabs[<worktreeKey>]: cuirass_8dir_sheet_preview.png     (duplicate removed, 1 kept)
     - tabGroups[global-floating-terminal]: 1 tabOrder id(s)
     - tabGroups[<worktreeKey>]: 1 tabOrder id(s)
    

    After quitting Orca, applying, and restarting, the phantom tab no longer resurrects.

    Caveats: field names are from v1.4.137's orca-data.json schema and may drift across versions; mobileClientTabSelectionsByDeviceId and other tab-adjacent keys are intentionally untouched.

  2. OrcaWin commented on Aug 29, 2026

    @OrcaWin
    Collaborator

    Related editor-tab close/restore reports (not a match for closing this):

    This one is specifically session restore minting duplicate openFilesByWorktree / unifiedTabs editor records so a close does not stick.

    Reported on v1.4.137; current GitHub release is v1.4.192. I could not find a later merge that dedupes those editor records, so leaving open. Worth retrying on a current build if you can.

  3. added
    bug
    os:linux
    on Sep 19, 2026
  4. added theissue type on Sep 19, 2026
  5. nwparker commented on Sep 27, 2026

    @nwparker
    Contributor

    Closing as fixed by merged #17370. That change reproduces the duplicate persisted editor records from this report and repairs the same-owner/file records and stale tab references during restore; its regression test verifies that a closed editor stays closed after a second hydration. No later report of this failure is attached here.

  6. added a commit that references this issue on Oct 15, 2026
    3f49c9b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggitos:linux

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions