Skip to content

Group the sidebar by machine by default when the account has two machines (851-4436) - #1438

Merged
pondorasti merged 8 commits into
mainfrom
alexandru/851-4436-group-the-sidebar-by-machine-once-when-a
Nov 26, 2026
Merged

pondorasti merged 8 commits into
mainfrom
alexandru/851-4436-group-the-sidebar-by-machine-once-when-a

Conversation

@pondorasti

@pondorasti pondorasti commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Fixes 851-4436

When the user has never picked a sidebar grouping, the sidebar groups by Machine while the account has two or more machines, and stays on None otherwise.

The rule

  • Never picked: Machine with two or more machines, None with fewer. It follows the count up and down.
  • Ever picked (including None): the saved grouping always wins, as today. It is read first, so machine changes don't touch the sidebar for these users.
  • Nothing synced is written automatically. The grouping preference only changes when the user picks an item.
  • One place: SidebarGroupingChoice in CodevisorUI holds the rule. The macOS sidebar, the command palette, and the iOS sidebar and options menu all read the grouping through it.
  • The menu: the checkmark shows the effective grouping, and picking an item saves it as an explicit choice.

A count that is settled before it is used

AccountMachineCount (a small observable model on AppEnvironment) holds the count the default uses.

  • It only takes a new count when all of these hold: the cloud account has finished loading and no sign-in is in progress; the machine list is there (verified, or a cached list); and, on a Mac, the Mac knows its own cloud device ID.
  • Until then it shows the last count, remembered in a local preference that is not synced (machines.lastKnownAccountMachineCount). So launch never regroups, and this Mac's own record can't be mistaken for a second machine while it is still unidentified.
  • Counted by device ID: this Mac, plus every other non-sandbox record. Online state and names don't matter, so a same-named Mac that sleeps doesn't flip the grouping.

Known limits

  • Existing users: those with two or more machines who never picked a grouping will see Machine grouping after updating.
  • Stale record of this Mac: counting is by device ID, so a record left by a reinstall under a new ID counts as a machine. Nothing in the cloud record tells it apart from a second Mac. This was chosen on purpose: a one-Mac user sees a stable "Machines" header and can pick None, while filtering by name made the grouping flap every time a same-named Mac slept. Removing the stale record in Settings › Machines also fixes it.
  • A Mac without its cloud ID: a signed-in Mac that never learns its own cloud ID keeps the last remembered result.
  • iOS repeat pick: the iOS Grouping menu is the same Picker as on main, bound to the effective grouping. Whether picking the already-checked option saves it is unverified on iOS. On macOS it does (checked in the running app).

Tests

SidebarGroupingChoiceTests (14 tests) pass, three runs in a row. Each of these fails when its fix is swapped out:

  • launch shows the remembered result until the cloud account has loaded;
  • signed in with no machine list yet, the remembered result still shows;
  • a same-named second Mac counts whether online or asleep (real CodevisorMachine.local.name);
  • this Mac's own record is never a second machine, even renamed and before the Mac knows its ID;
  • with a saved grouping, machine changes don't invalidate the grouping;
  • a cloud provider attached after start-up is followed.
  • a sign-in that runs again while signed in keeps the grouping until it finishes.

The rest cover the basic rule, sandboxes, an unreadable saved value, and signing out. macOS and iOS both build.

Tophat (macOS dev app, ad-hoc signed because the Apple Development certificate is still revoked)

  1. One machine, grouping never set: "Workspaces", menu has None checked, nothing saved.
  2. A second machine joins: the sidebar regroups to "Machines › This Mac", menu has Machine checked, still nothing saved.
  3. Picking None by hand: stays None with both machines connected.
  4. Final build, remembered count cleared: the app computed 2 itself and showed Machines with nothing saved.
  5. Final build, relaunch recording: the sidebar draws Machines from its first frame and stays there.
  6. In the real macOS menu, picking the already-checked Machine saved "machine".

Not hand-checked on iOS. The simulator could not be run: starting it pushed this Mac's load past 600, so I stopped. The iOS app builds.

Evidence (also on the Linear ticket):

Shots 01–07 are from the previous head; the rule they show is unchanged.

🤖 Generated with Claude Code

pondorasti added a commit that referenced this pull request Nov 19, 2026
…1-4436)

Review fixes for #1438:
- Decide only after this session has received the synced preferences
  from every reachable machine (tracked per machine in ConfigSync), not
  from an on-disk replica that any local write creates.
- "oneMachine" is now a fallback ranked below the existing-account
  "settled" fallback, and both lose to any real write, so a one-machine
  record can never beat "settled".
- The automatic Machine grouping is written as a fallback, so a grouping
  the user picked on another device wins even if it syncs here later.
- Count the machines the sidebar lists (de-duplicated allMachines, minus
  sandboxes), folding an offline entry that shares its name with another
  machine (a stale record after a reinstall or data reset). Other offline
  machines still count. On a Mac, wait until the local server has reported
  in, so this Mac's own cloud record is folded in.
- The watcher stops once settled or when its environment is gone; the
  environment cancels it on teardown.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@pondorasti
pondorasti force-pushed the alexandru/851-4436-group-the-sidebar-by-machine-once-when-a branch from be9c5c1 to 7968cf5 Compare November 19, 2026 22:23
pondorasti added a commit that referenced this pull request Nov 19, 2026
… (851-4436)

Code review fixes for #1438:
- Decide only when every machine the sidebar lists (sandboxes left out)
  is connected and has delivered the synced preferences since it last
  connected. A second Mac set up while the first one sleeps now waits
  for it instead of settling and missing the switch.
- Forget a machine's delivered preferences when it reconnects, so a
  reconnect waits for a fresh merge.
- Count the sidebar's de-duplicated machine list without folding by
  name: two Macs that share a name are two machines. A stale offline
  record of this Mac can't be synced, so it holds the decision instead
  of switching a one-Mac account.
- A fallback write for a key that isn't synced falls back to a local
  set-if-absent on the watcher's own preferences, so the step can't
  repeat.
- Rename cancelOnTeardown to cancelOnDeinit to say what it does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
pondorasti added a commit that referenced this pull request Nov 19, 2026
…1-4436)

Review fixes for #1438:
- Decide only after this session has received the synced preferences
  from every reachable machine (tracked per machine in ConfigSync), not
  from an on-disk replica that any local write creates.
- "oneMachine" is now a fallback ranked below the existing-account
  "settled" fallback, and both lose to any real write, so a one-machine
  record can never beat "settled".
- The automatic Machine grouping is written as a fallback, so a grouping
  the user picked on another device wins even if it syncs here later.
- Count the machines the sidebar lists (de-duplicated allMachines, minus
  sandboxes), folding an offline entry that shares its name with another
  machine (a stale record after a reinstall or data reset). Other offline
  machines still count. On a Mac, wait until the local server has reported
  in, so this Mac's own cloud record is folded in.
- The watcher stops once settled or when its environment is gone; the
  environment cancels it on teardown.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@pondorasti
pondorasti force-pushed the alexandru/851-4436-group-the-sidebar-by-machine-once-when-a branch from ea1a0da to 91eeb77 Compare November 19, 2026 22:43
pondorasti added a commit that referenced this pull request Nov 19, 2026
… (851-4436)

Code review fixes for #1438:
- Decide only when every machine the sidebar lists (sandboxes left out)
  is connected and has delivered the synced preferences since it last
  connected. A second Mac set up while the first one sleeps now waits
  for it instead of settling and missing the switch.
- Forget a machine's delivered preferences when it reconnects, so a
  reconnect waits for a fresh merge.
- Count the sidebar's de-duplicated machine list without folding by
  name: two Macs that share a name are two machines. A stale offline
  record of this Mac can't be synced, so it holds the decision instead
  of switching a one-Mac account.
- A fallback write for a key that isn't synced falls back to a local
  set-if-absent on the watcher's own preferences, so the step can't
  repeat.
- Rename cancelOnTeardown to cancelOnDeinit to say what it does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@pondorasti
pondorasti force-pushed the alexandru/851-4436-group-the-sidebar-by-machine-once-when-a branch from 91eeb77 to 943f47e Compare November 26, 2026 01:09
pondorasti added a commit that referenced this pull request Nov 26, 2026
…cheap (851-4436)

Code review fixes for #1438:
- A saved grouping this build can't decode (for example a case added by a
  newer build) still counts as the user's choice and shows None, as it
  did before, instead of falling back to the machine default.
- The default reads a machine count that doesn't build the machine list,
  since the sidebar reads the grouping once per row.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@pondorasti
pondorasti force-pushed the alexandru/851-4436-group-the-sidebar-by-machine-once-when-a branch from 943f47e to 8e533f8 Compare November 26, 2026 01:36
@pondorasti pondorasti changed the title Group the sidebar by machine once when a second machine connects (851-4436) Group the sidebar by machine by default when the account has two machines (851-4436) Nov 26, 2026
pondorasti added a commit that referenced this pull request Nov 26, 2026
…cheap (851-4436)

Code review fixes for #1438:
- A saved grouping this build can't decode (for example a case added by a
  newer build) still counts as the user's choice and shows None, as it
  did before, instead of falling back to the machine default.
- The default reads a machine count that doesn't build the machine list,
  since the sidebar reads the grouping once per row.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@pondorasti
pondorasti force-pushed the alexandru/851-4436-group-the-sidebar-by-machine-once-when-a branch from 8e533f8 to 5d69a0a Compare November 26, 2026 02:49
pondorasti added a commit that referenced this pull request Nov 26, 2026
…436)

Code review fixes for #1438:
- The automatic grouping now comes from AccountMachineCount, a small
  observable model on AppEnvironment. It only takes a new count once the
  cloud account has finished loading and, on a Mac, once the Mac knows
  its own cloud device ID. Until then it shows the last count, which is
  remembered in a local preference that is not synced, so launch never
  regroups.
- Machines are counted by device ID: this Mac plus every other
  non-sandbox record. The count no longer depends on a machine being
  online or on its name, so a same-named Mac that sleeps doesn't flip the
  grouping, and this Mac's own record is never a second machine, even
  when it was renamed in the cloud.
- The grouping reads the saved value first and touches the machine count
  only when nothing is saved.
- The iOS sample sidebar saves an explicit grouping after its reset.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
pondorasti added a commit that referenced this pull request Nov 26, 2026
…om app start-up (851-4436)

Code review fixes for #1438:
- Signed in with no machine list loaded yet (no cache and the cloud
  unreachable), the count stays unknown, so the remembered result keeps
  showing instead of a wrong count being saved.
- The count follows a cloud provider that is attached after start-up.
- The apps start following the count at launch, next to preference sync,
  so preview and test environments no longer write the remembered count
  into the shared preferences.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
pondorasti and others added 8 commits November 25, 2026 19:39
…ines (851-4436)

When the user has never picked a sidebar grouping, the effective grouping
is now computed: Machine while the account has two or more machines, None
otherwise. It follows the machine count up and down, and nothing is
written automatically. A saved grouping, including None, always wins.

- SidebarGroupingChoice is the one place that holds the rule. The macOS
  sidebar, the command palette, and the iOS sidebar and options menu all
  read the effective grouping through it, and the Grouping menu's
  checkmark shows it. Picking an item saves it as an explicit choice.
- The count is the machines the sidebar lists, without sandboxes, so a
  second Mac with the same name counts and a stale offline record of this
  Mac doesn't.

This replaces the earlier one-time switch: no marker key, watcher, or
sync changes remain.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…cheap (851-4436)

Code review fixes for #1438:
- A saved grouping this build can't decode (for example a case added by a
  newer build) still counts as the user's choice and shows None, as it
  did before, instead of falling back to the machine default.
- The default reads a machine count that doesn't build the machine list,
  since the sidebar reads the grouping once per row.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…436)

Code review fixes for #1438:
- The automatic grouping now comes from AccountMachineCount, a small
  observable model on AppEnvironment. It only takes a new count once the
  cloud account has finished loading and, on a Mac, once the Mac knows
  its own cloud device ID. Until then it shows the last count, which is
  remembered in a local preference that is not synced, so launch never
  regroups.
- Machines are counted by device ID: this Mac plus every other
  non-sandbox record. The count no longer depends on a machine being
  online or on its name, so a same-named Mac that sleeps doesn't flip the
  grouping, and this Mac's own record is never a second machine, even
  when it was renamed in the cloud.
- The grouping reads the saved value first and touches the machine count
  only when nothing is saved.
- The iOS sample sidebar saves an explicit grouping after its reset.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…851-4436)

The iOS Grouping menu now uses checkmark toggles that always save the
tapped grouping, so tapping the one already shown keeps it as an explicit
choice without relying on how a menu Picker handles a repeat pick.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…om app start-up (851-4436)

Code review fixes for #1438:
- Signed in with no machine list loaded yet (no cache and the cloud
  unreachable), the count stays unknown, so the remembered result keeps
  showing instead of a wrong count being saved.
- The count follows a cloud provider that is attached after start-up.
- The apps start following the count at launch, next to preference sync,
  so preview and test environments no longer write the remembered count
  into the shared preferences.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Calling follow() again no longer adds another observation chain, and a
manual update supersedes the pending one instead of stacking up.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…851-4436)

The iOS options menu is the Picker from main again, now bound to the
effective grouping, so the Grouping row still shows the current choice.
Whether picking the already-checked option saves it is unverified on iOS.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…vironment's preferences (851-4436)

- A sign-in in progress now leaves the machine count unsettled, so
  re-running sign-in while signed in no longer drops the count for a
  moment and regroups the sidebar. Only a real signed-out state counts
  as this Mac alone.
- SidebarGroupingChoice reads the saved grouping from the environment's
  own preferences, the same store the remembered machine count uses.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@pondorasti
pondorasti force-pushed the alexandru/851-4436-group-the-sidebar-by-machine-once-when-a branch from 7d99787 to abaadf0 Compare November 26, 2026 03:40
@pondorasti
pondorasti merged commit edda615 into main Nov 26, 2026
@pondorasti
pondorasti deleted the alexandru/851-4436-group-the-sidebar-by-machine-once-when-a branch November 26, 2026 03:48
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