Skip to content

fix(mobile): ignore stale account responses after sign-out - #2899

Merged
richiemcilroy merged 3 commits into
CapSoftware:mainfrom
yashranaway:fix/mobile-ui-state
Oct 23, 2026
Merged

richiemcilroy merged 3 commits into
CapSoftware:mainfrom
yashranaway:fix/mobile-ui-state

Conversation

@yashranaway

@yashranaway yashranaway commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

in the mobile app, the account bootstrap request and the switch organisation call wrote their result straight into auth state when they came back. if you signed out, or signed in as someone else, while one was still in flight, the late response put the previous user's account and orgs back on screen.

now the auth provider bumps a session revision on sign in and sign out, and those responses are only applied if the revision hasn't changed since the request started. a failed refresh only clears the session it belonged to. the test signs out while a bootstrap is pending.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; both previous findings are addressed.

Summary

Prevents late account responses from restoring old account data after a session change.

  • The mobile app ignores account replies from earlier sign-in sessions.

Reviews (2) · Last reviewed commit: "fix(mobile): discard account responses s..." · Reviewed by Greptile

@yashranaway

Copy link
Copy Markdown
Contributor Author

@greptileai review

@vercel

vercel Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
cap-status Skipped Skipped Oct 23, 2026 9:40pm UTC

@vercel
vercel Bot temporarily deployed to Preview – cap-status October 22, 2026 07:54 Inactive
);

const signOut = useCallback(async () => {
sessionRevision.current += 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Old account data returns

signOut bumps sessionRevision before waiting for revocation and deleting saved credentials. The old apiKey and callbacks remain active during those waits. A background upload check can call refreshAuth() in that window, capturing the bumped revision while using the old key. If its response arrives after sign-out finishes, the equality check still passes and restores the old bootstrap.

Invalidate requests when credentials are cleared too, or prevent requests from starting while sign-out is pending.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/mobile/src/auth/AuthContext.tsx
Line: 229

Comment:
**Old account data returns**

`signOut` bumps `sessionRevision` before waiting for revocation and deleting saved credentials. The old `apiKey` and callbacks remain active during those waits. A background upload check can call `refreshAuth()` in that window, capturing the bumped revision while using the old key. If its response arrives after sign-out finishes, the equality check still passes and restores the old `bootstrap`.

Invalidate requests when credentials are cleared too, or prevent requests from starting while sign-out is pending.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. A refresh could start during revocation with the old key and pick up the bumped revision, so I bump it again once the saved credentials are deleted. There's a regression test for that window now, it failed before the change (79f0150).

);
});

it("does not restore account data when a refresh finishes after sign-out", async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Two guards lack regression tests

The new test covers only a successful refresh() response after sign-out. It never exercises the stale-failure guard or the guard in setActiveOrganization. Removing either guard leaves this test passing.

Add deferred tests that reject an old automatic bootstrap after a new sign-in and resolve an old organization switch after a session change. These would catch regressions that clear a new login or replace its account data.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/mobile/src/auth/AuthProvider.test.tsx
Line: 263

Comment:
**Two guards lack regression tests**

The new test covers only a successful `refresh()` response after sign-out. It never exercises the stale-failure guard or the guard in `setActiveOrganization`. Removing either guard leaves this test passing.

Add deferred tests that reject an old automatic bootstrap after a new sign-in and resolve an old organization switch after a session change. These would catch regressions that clear a new login or replace its account data.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added deferred tests for both, an old bootstrap failing after a new sign-in and an old organization switch resolving after a session change (79f0150).

@vercel
vercel Bot temporarily deployed to Preview – cap-status October 22, 2026 08:37 Inactive
@richiemcilroy

Copy link
Copy Markdown
Member

@greptileai review

@vercel
vercel Bot temporarily deployed to Preview – cap-status October 23, 2026 21:40 Inactive
@richiemcilroy
richiemcilroy merged commit fb9e981 into CapSoftware:main Oct 23, 2026
29 of 30 checks passed

This branch was previously deployed

1 inactive deployment
Preview – cap-status — 7f4a9619 Deployed Oct 23, 2026 by vercel[bot]
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.

2 participants