Skip to content

Scope Channels (bluebird) browser tabs to the signed-in user#3164

Draft
adamleithp wants to merge 1 commit into
mainfrom
posthog-code/per-user-browser-tabs
Draft

Scope Channels (bluebird) browser tabs to the signed-in user#3164
adamleithp wants to merge 1 commit into
mainfrom
posthog-code/per-user-browser-tabs

Conversation

@adamleithp

Copy link
Copy Markdown
Contributor

Problem

Channels/canvas browser tabs are persisted machine-wide, not per user. Everyone who logs into the app on the same machine shares one tab strip: logging out leaves the previous user's tabs behind, and switching accounts doesn't restore that user's own tabs.

Why

Tabs should follow the login, not the install — logging into an account should bring back that account's tabs, and switching users should restore theirs (raised for PostHog Code / project bluebird).

Changes

  • browser_windows rows now carry an account_scope (<cloudRegion>:<accountKey>, migration 0017); tabs inherit scope through their window FK. Load/save in BrowserTabsRepository only touch the active account's rows.
  • BrowserTabsService gets setAccountScope(): login loads that account's persisted snapshot and fans it out to all windows; logout swaps to a blank memory-only strip (nothing persisted while signed out, so no account's saved tabs are overwritten).
  • Rows persisted before scoping existed are adopted by the first account that signs in, so existing users keep their tabs after upgrading.
  • AuthState now exposes accountKey, with a getAccountScopeKey() helper; the Electron main process wires auth state changes to the tabs service (skipping the transient restoring status so a slow session restore doesn't flash a signed-out strip).

How did you test this?

  • New unit tests: browser-tabs-repository.test.ts (scope isolation, round-trip, legacy-row adoption) and service.test.ts (per-account restore on user switch, memory-only signed-out behavior, scope-change emissions) — 12 tests passing.
  • Updated auth.test.ts for the new accountKey field — 43 tests passing.
  • pnpm typecheck clean across all 22 packages; Biome clean on changed files.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Code

Tab strips were stored machine-wide, so every account on a machine shared
one set of tabs and logout left the previous user's tabs behind. Persist
them per (cloudRegion, accountKey) instead: each login restores that
user's tabs, switching accounts swaps snapshots, and signed-out sessions
are memory-only so no account's saved tabs get overwritten. Pre-account
rows are adopted by the first login so existing users keep their tabs.

Generated-By: PostHog Code
Task-Id: b06ce1b6-aef9-4164-8274-0ae6374ca8c1
@trunk-io

trunk-io Bot commented Jul 6, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 1562158.

@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff (1)

  1. packages/workspace-server/src/services/browser-tabs/service.test.ts, line 1549-1560 (link)

    P2 Prefer parameterised test for emission-count assertions

    The "emits… but not on a repeat" test drives the same setAccountScope→count-check pattern twice (once for no-op on repeat, once for null scope). Per the project's preference for parameterised tests, this could be expressed as a single it.each table with [scope, expectedCount] rows, making it easier to add further edge cases.

    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!

Reviews (1): Last reviewed commit: "Scope Channels browser tabs to the signe..." | Re-trigger Greptile

@@ -0,0 +1,2 @@
ALTER TABLE `browser_windows` ADD `account_scope` text;--> statement-breakpoint
CREATE INDEX `browser_windows_account_scope_idx` ON `browser_windows` (`account_scope`); No newline at end of file

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 The file is missing a trailing newline, which can cause issues with some SQL tools and shows as a diff noise marker (\ No newline at end of file) in git diff.

Suggested change
CREATE INDEX `browser_windows_account_scope_idx` ON `browser_windows` (`account_scope`);
CREATE INDEX `browser_windows_account_scope_idx` ON `browser_windows` (`account_scope`);

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!

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.

1 participant