[Session] Reset global agent on expire #3838
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes a mistake I introduced in #3836.
Extracted from #3728.
The change in #3836 assumes the persistence handler will handle any errors. However, our
onAgentSessionChange
persistence handler does not currently update__globalAgent
on expiry (despite updating the related state). This is inconsistent with how the same persistence handler treatsnetwork-error
(for which it does update__globalAgent
).Updating the global agent seems like the correct behavior if we're updating the UI to show PWI. So this seems like an omission in the existing code (which #3836 made worse). I suppose this was less important before #3836 because the
catch
branch would restore__globalAgent
regardless of the persistence handler. Anyway, this fix is in the handler itself.In this PR, I adjust the
expired
branch to do the same things (copy paste) as thenetwork-error
early condition. (Unlike withnetwork-error
, we don't want an early return because we still want theaccounts
-related state update below to run.)Test Plan
To trigger the
expiry
codepath, you can set a breakpoint inresumeSession
and evaluateres.data.did = 'foo'
so that it raises an error which the agent will broadcast as an expiry.Verify that previously
__globalAgent
was being set in this case by thecatch
block I removed in #3836. So now it's not being set at all, and you can verify it's stale.After applying this PR and doing the same thing, verify that
__globalAgent
is being set by the persisted handler.Verify you get kicked to the login and can log in after entering credentials.