Skip to content

fix(session): stop elevation from disabling session restore and saving - #1083

Open
Sakyvo wants to merge 1 commit into
Kuddev:release/auto-2.6.2from
Sakyvo:elevated-session-fix-official
Open

Sakyvo wants to merge 1 commit into
Kuddev:release/auto-2.6.2from
Sakyvo:elevated-session-fix-official

Conversation

@Sakyvo

@Sakyvo Sakyvo commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Why

An administrator-started Pebrel never restores or saves the workspace. Every launch opens a single tab in the user's home directory, and quitting — including through the tray — writes nothing, so the tab layout is lost on every run.

requires_isolation() (platform/elevation.rs) answers "is this process privileged?". It was also used to switch off the workspace snapshot in two places: workspace/session_persistence.rs refused to write session.json and workspace/windowing/startup_geometry.rs refused to read it. The result is a P0 data-loss path for anyone who launches elevated — which on Windows is a normal way to run a terminal.

What it does

The workspace snapshot is user-visible state, not a control-plane resource, so elevation is no longer an input to it.

  • SessionPersistence drops its isolated field. Every instance takes the same write path, and the replayed snapshot is written on checkpoint, window close, closing all tabs and quit.
  • An elevated instance that has an armed update still hands the workspace to the update transaction through checkpoint_scheduled before writing, so the elevated relaunch keeps its own scheduled-workspace.json. That transaction snapshot is unchanged; it just no longer replaces the workspace snapshot.
  • update_windows() prefers the persisted snapshot and falls back to the in-memory one, so a scheduled update still sees a complete workspace before the first successful write (previously the fallback only existed on the isolated path).
  • The restore path no longer short-circuits under isolation.

Isolation keeps guarding everything it was introduced for: runtime port publication, the two startup handovers, keep-session residency and the mobile pairing key. This change does not touch those.

Reproduction

  1. Launch Pebrel as administrator (on Windows, run pebrel.exe from an elevated shell or a shortcut marked "Run as administrator").
  2. Open several tabs.
  3. Quit from the tray icon (or Settings → Advanced → Quit Pebrel).
  4. Launch as administrator again.

Before this change: one tab in %USERPROFILE%, and %APPDATA%\Pebrel\session.json keeps its old mtime. After: the tabs come back and the file is rewritten on quit.

Evidence from the reporting machine: session.json held 15 tabs with clean_exit: true and boot_attempts: 0, and every tab's directory still existed, but its mtime was two days older than pebrel_settings.txt and the command history — the snapshot was simply never read or written again.

Verification

  • cargo check -p nebula --bin pebrel --features gpui-shell and cargo check --tests -p nebula --bin pebrel pass.
  • cargo test -p nebula --bin pebrel session_persistence — 24 passed, 0 failed. The former negative case (isolated_windows_never_write_shared_session_storage) becomes a positive one driven by the same constructor the app uses, and a new test asserts the update handoff still sees a complete workspace after a failed checkpoint.
  • cargo test -p nebula-settings — 113 passed.
  • python scripts/check_architecture.py — no errors.
  • Not verified here: the actual elevated restore/save round trip and window geometry restore. A test process cannot be elevated, which is why the decision is expressed as "elevation is not an input" rather than a parameterised branch; the visual check needs a manual run as administrator.

Trade-off and known limitations

  • An elevated instance now inherits the layout a non-elevated one wrote, and vice versa. On a single-user machine that is the expected behaviour; keeping two stores would have meant "my tabs vanish when I start the app a different way".
  • try_save is an atomic write with no cross-process lock, so two instances running at once are last-writer-wins. That is the pre-existing behaviour of the non-isolated path and is unchanged here.
  • Rejected alternatives: keeping the blanket isolation (P0 data loss), a separate session-elevated.json (two layouts for one user), and removing requires_isolation() everywhere (that would let a low-privilege process hand commands to an elevated instance).

A CHANGELOG entry is included under Unreleased.

@Sakyvo
Sakyvo requested a review from Kuddev as a code owner November 21, 2026 09:25
@Sakyvo

Sakyvo commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Priority: P0 — blocks release / data loss. An outside contributor cannot apply labels on this repository, so please label this P0, �ug, �rea: session, os: windows, size/S.

Why P0: any Pebrel started as administrator never restores and never saves the workspace. Users lose the whole tab layout on every launch, and quitting writes nothing, so the previous snapshot is lost on the next start. On Windows, launching elevated is a normal way to run a terminal, so this is not an edge case.

Base note: this targets
elease/auto-2.6.2\ rather than \main\ because \main\ has renamed the crates to \pebrel_\ while this patch is written against the
ebula_
\ layout. The touched files are byte-identical between \�2.6.1\ and
elease/auto-2.6.2, so it applies cleanly. Happy to redo it on \main\ if you prefer.

@Sakyvo
Sakyvo force-pushed the elevated-session-fix-official branch from d76827d to b8bb5e7 Compare November 21, 2026 09:32
`requires_isolation()` answers "is this process privileged?", and it was also
used to switch off the workspace snapshot: an elevated instance never read
`session.json` and never wrote it. Every administrator launch therefore opened
a single home-directory tab, and both tray quit and safe quit saved nothing,
even though the previous snapshot was intact on disk.

The workspace snapshot is user-visible state, not a control-plane resource, so
elevation is no longer an input to it:

- `SessionPersistence` drops its `isolated` field; every instance takes the
  same write path.
- An elevated instance that has an armed update still hands the workspace to
  the update transaction (`checkpoint_scheduled`) before writing, so the
  elevated relaunch keeps its own `scheduled-workspace.json`.
- `update_windows()` prefers the persisted snapshot and falls back to the
  in-memory one, so a scheduled update still sees a complete workspace before
  the first successful write.
- The restore path no longer short-circuits under isolation.

Isolation keeps guarding the control plane: runtime port publication, both
startup handovers, keep-session residency and mobile pairing.

Tests: the negative "isolated windows never write shared storage" case becomes
a positive one driven by the same constructor the app uses, plus a test that a
failed checkpoint still leaves the workspace visible to the update handoff.
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