Closed Bug 2077143 Opened 1 month ago Closed 6 days ago

Persist flow state and restore or recover it at startup

Categories

(Data Platform and Tools :: Glean: SDK, enhancement, P1)

enhancement

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: travis_, Assigned: travis_)

References

(Blocks 2 open bugs)

Details

Attachments

(1 external file)

Sessions resume across clean restarts, so active flow instances must too. Otherwise backgrounding the app and having it killed would end every flow with no outcome. Depends on Bug 2077136, the lifecycle bug, and the session-end bug.

Persistence:

  • Store flow state in INTERNAL_STORAGE with Lifetime::User, next to session#*. For each instance: flow_name, flow_seq, owning session_id, start time. Store the session-wide flow counter in the same write.
  • Write only when an instance opens or closes. Nothing is written on the recording path otherwise.

Clean restart (restore_session_state_from_storage()):

  • Restore instances only if their session_id matches the session being restored. Discard the rest.
  • Restore the flow counter with them, or the resumed session will reuse sequence numbers and two instances will share an identity.
  • Discard, without a flow_end, any instance whose flow is no longer registered.
  • Restore instances of a disabled flow. Restoring is not opening, and the kill switch only applies to opening.
  • Check auto_close_timeout while restoring, and close expired instances with reason: timeout right away.
  • If the session is restored and later ends by timeout in handle_client_active(), the restored instances are closed by the session-end hook as usual.

Dirty-flag restart (recover_session_on_dirty_flag()):

  • For each persisted instance whose flow is still registered, record a glean.flow_end with reason: abnormal and the original session_id as an extra. Record it out-of-session, since the original session is not current, and before the recovery session_end. Then clear flow state.

Session mode change at startup: when the persisted session is abandoned with session_end("abandoned"), treat its instances the same way as on a dirty-flag restart.

Opt-out: clear_metrics() already clears the stored state. Reset the in-memory flow state explicitly as well, and record no flow_end. See Bug 2077130 for the same problem with SessionManager.

Blocks: 2077152
Blocks: 2077127

(via GitHub webhook, authenticated as shared-secret)

Assignee: nobody → tlong
Status: NEW → ASSIGNED
Priority: P3 → P1
Status: ASSIGNED → RESOLVED
Closed: 6 days ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: