fix(workspace): close the sealed-switch privacy race, restore the parked filter

Two findings from the workspace persona review, both rated high:

* Switch race: the hub client re-pointed at a sealed area's hub
  before the workspace announced the sealed context, so the 2 s
  page pollers (runs, audit) could fetch and render that hub's
  data without the sealed marking. Switches now run inside an
  explicit switching window: opened before anything touches the
  connection, announced optimistically in the identity bar
  ("switching…" + spinner, leave button hidden), pollers and the
  shell health tick pause inside it, and pages drop replies whose
  context epoch changed mid-flight. The sealed context is
  announced only after the new hub answered healthy.

* Filter loss: entering a sealed area cleared the shared-hub
  project filter and returning restored only the endpoint. The
  filter is now parked on entry and restored on return; prefs
  keep the parked value throughout, so live state and prefs agree
  after the round trip (and after a mid-session relaunch).

Guard: workspace_switch_race_test pins both invariants
state-matrix-style against scripted hub + sealed-area fakes —
reconnects may only happen inside an open switch window, pollers
must stay silent inside it, and the filter must survive the round
trip. SealedAreaService gained a debugSetInstance seam so the
suite never scans a real ~/.chain.

Signed-off-by: flemming-it <stefan.a.flemming@googlemail.com>
This commit is contained in:
flemming-it 2026-08-27 23:48:03 +02:00
parent 906290f445
commit afe782e826
13 changed files with 480 additions and 52 deletions

View file

@ -22,7 +22,15 @@ class ChainSealedIdentityBar extends StatelessWidget {
return ListenableBuilder(
listenable: Workspace.instance,
builder: (context, _) {
final area = Workspace.instance.activeSealed;
final ws = Workspace.instance;
// While a switch is in flight the bar announces it BEFORE the
// client re-points (privacy race guard): entering shows the
// target area, leaving keeps the current area's marking —
// whatever is still on screen is that area's data.
final switching = ws.switching;
final area = switching
? (ws.switchTarget ?? ws.activeSealed)
: ws.activeSealed;
if (area == null) return const SizedBox.shrink();
final theme = Theme.of(context);
final l = AppLocalizations.of(context)!;
@ -51,7 +59,7 @@ class ChainSealedIdentityBar extends StatelessWidget {
const SizedBox(width: ChainSpace.md),
Expanded(
child: Text(
l.sealedIdentityBar,
switching ? l.sealedSwitchingBar : l.sealedIdentityBar,
style: theme.textTheme.bodySmall?.copyWith(
color: onAccent.withValues(alpha: 0.85),
),
@ -59,12 +67,22 @@ class ChainSealedIdentityBar extends StatelessWidget {
),
),
const SizedBox(width: ChainSpace.sm),
TextButton.icon(
onPressed: () => Workspace.instance.switchToShared(),
style: TextButton.styleFrom(foregroundColor: onAccent),
icon: const Icon(Icons.logout, size: 15),
label: Text(l.sealedLeave),
),
if (switching)
SizedBox(
width: 14,
height: 14,
child: CircularProgressIndicator(
strokeWidth: 2,
color: onAccent,
),
)
else
TextButton.icon(
onPressed: () => Workspace.instance.switchToShared(),
style: TextButton.styleFrom(foregroundColor: onAccent),
icon: const Icon(Icons.logout, size: 15),
label: Text(l.sealedLeave),
),
],
),
),