Closed Bug 2088568 Opened 22 days ago Closed 20 days ago

An error in SessionStore.#initSession drops saved tab groups

Categories

(Firefox :: Session Restore, defect)

defect
Points:
2

Tracking

()

RESOLVED DUPLICATE of bug 2087599

People

(Reporter: mhynson, Assigned: mhynson)

Details

Within the inner try block of SessionStore.#initSession, this.#savedGroups = state?.savedGroups ?? [] is the last statement (searchfox).

The catch simply logs that "The session file is invalid". If anything earlier in the block throws, #savedGroups stays [], and the next session write saves an empty saved-groups list to disk.

One likely culprit that can throw is #prepDataForDeferredRestore, which converts open tab groups into saved groups for a deferred session (searchfox):

let groupStateToSave = window.groups.find(
  groupState => groupState.id == window.tabs[tIndex].groupId
);
let groupToSave = groupsToSave.get(groupStateToSave.id);

If a tab's groupId has no matching entry in window.groups, or the window has no groups key, this throws a TypeError.

Assignee: nobody → mhynson
Points: --- → 2
Summary: Saved tab groups are lost, and a deferred session is restored, when a tab refers to a missing tab group → An error in SessionStore.#initSession drops saved tab groups

I reproduced this on a clean tree, and the mechanism is exactly as you describe. A deferred session whose tab refers to a group the window does not define ends with:

TypeError: can't access property "id", groupStateToSave is undefined at groupsToSave.get(groupStateToSave.id) in #prepDataForDeferredRestore, and after startup SessionStore.savedGroups is [].

This is the same failure as bug 2087599 (D338378). I updated its test to use your trigger - a tab with an unresolvable groupId - alongside a second one (a window with no _closedTabs). Both are red on a clean tree and green with the patch.

To be explicit about what that patch does and does not do: it keeps state.savedGroups in the catch, so the data survives whatever threw. It does not stop the throw, so the deferred restore is still left half-converted. The guard on groupStateToSave is the other half and is yours to decide. If you would rather track this in one place, I can fold 2087599 into this bug.

Status: NEW → ASSIGNED

It sounds like you've got a good start to a solution on bug 2087599. Nice work! I pulled down your changes and can confirm that savedGroups does survive trying to restore from an error in the session restore file when there are missing groups. Thank you for adding that trigger in the test. I'll close this bug out as a duplicate of 2087599.

Status: ASSIGNED → RESOLVED
Closed: 20 days ago
Duplicate of bug: 2087599
Resolution: --- → DUPLICATE
See Also: 2083249 →
No longer blocks: 2063477
You need to log in before you can comment on or make changes to this bug.