Persist AI panel router history stack across page reloads

What does this MR do and why?

Persists the AI panel's Vue Router (abstract mode) history stack to sessionStorage so the in-panel "Go back" button continues to work after a full page reload.

Before this MR, the panel's navigation history lived entirely in JS memory; a hard refresh wiped it and router.canGoBack() returned false until the user navigated at least twice in the panel again. After this MR, every successful navigation serializes the stack to a new duo_agents_platform_history_stack_{context} sessionStorage key, and restoreLastRoute replays the stack on boot.

Behind the duo_panel_history_stack_persistence feature flag (gitlab_com_derisk type, disabled by default).

The MR is structured as three commits so reviewers can take it a layer at a time:

  1. Register the feature flag — adds the flag YAML and pushes it through gon_helper.rb so the frontend can gate on window.gon.features.duoPanelHistoryStackPersistence.
  2. Add history stack serialization helpers — three pure functions (saveHistoryStack, getHistoryStack, getHistoryStackKey) with 28 unit tests. Inert at this layer — no callers wired yet.
  3. Wire history stack write and restore paths — registers a router.afterEach inside restoreLastRoute to persist the stack on every navigation, and replays the persisted stack on panel init. Gated on the feature flag; falls back to the existing single-route restore when the flag is off.

A behavioral subtlety: when the flag is on, restoreLastRoute no longer falls through to the legacy single-route fallback path on empty or corrupt stacks. The flag-on branch owns its own navigation policy and pushes a mode-aware default route on replay error. The shouldShowBlockedState check was also hoisted above the FF branch so blocked users land on the blocked route regardless of which path is active.

Screenshots or screen recordings

How to set up and validate locally

  1. Enable the flag:
    Feature.enable(:duo_panel_history_stack_persistence)
  2. Open the AI panel from the navigation rail.
  3. Navigate Chat → Sessions tab → open any session detail.
  4. In devtools console:
    sessionStorage.getItem('duo_agents_platform_history_stack_side_panel')
    You should see an array of {name, params} route entries.
  5. Hard reload the page (Cmd+Shift+R).
  6. Verify the panel restores to the session detail and the "Go back" button is visible. Click it — you should return to the sessions list.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Andrew Fontaine

Merge request reports

Loading