Skip to content

feat(web): restore the thread workspace across restarts and save named ones - #27

Merged
BarretoDiego merged 1 commit into
mainfrom
feat/persist-thread-workspace
Aug 25, 2026
Merged

BarretoDiego merged 1 commit into
mainfrom
feat/persist-thread-workspace

Conversation

@BarretoDiego

Copy link
Copy Markdown
Owner

Problem

The thread workspace threw away everything but its geometry on reload. Open tabs were rebuilt from whichever thread the URL happened to name, so stopping work meant reopening every pane by hand.

That was a deliberate trade, not an oversight — the old partialize comment says so. Nothing on the client could tell a deleted thread apart from one that simply had not synced yet, so persisting tabs risked restoring dead ones. Discarding the state was the safe answer available at the time.

Fix

Persists the whole workspace — layout, the tabs in each pane, and the selected thread — and solves the staleness problem with a prune pass instead of by discarding state.

Pruning. A new atom separates "environments this device is configured for" from "environments that have actually delivered a snapshot". Only the latter can be trusted to say a thread is gone. The rules, in threadWorkspacePrune.ts:

  • catalog not resolved yet → keep everything
  • environment unknown to this device → drop
  • environment known but not loaded (offline, still syncing) → keep
  • environment loaded → keep only what it reported
  • the routed tab → never dropped, the router always needs one to represent

The default is always to keep. Dropping a tab because the network was slow would quietly erase a workspace, which is a far worse failure than briefly showing a tab for a deleted thread.

Repair on read. Everything coming out of storage goes through normalizeThreadWorkspaceModel, which fixes pane count versus layout, duplicate pane ids, the same tab appearing in two panes, and an activeTabKey pointing at nothing. A truncated or hand-edited entry degrades into a usable workspace instead of crashing one. Storage version 1 → 2 with a migration, since v1 only ever wrote the layout.

Named workspaces. The layout menu gains a Save current workspace action plus a list of what is saved. Restoring one also navigates to the thread it had active — without that, the still-current URL would be bound straight back into the workspace the user just restored. Snapshots store panes by position and mint fresh pane ids on restore, so restoring the same one twice cannot alias a live pane. Saving under an existing name replaces it; the list is capped at 20 so storage does not grow without bound.

Performance

The prune pass is gated on a signature of what actually decides its outcome. Both of its inputs (useThreadRefs and the prune scope) recompute on ordinary thread traffic while their membership is unchanged, and every pruneTargets call writes the persisted workspace to storage — ungated, that would be one storage write per incoming message.

Notes

Verification

  • vp test run apps/web/src/threadWorkspaceStore.test.ts apps/web/src/threadWorkspacePrune.test.ts — 24 passed
  • targeted lint on the seven touched source files — clean
  • vp run --filter @t3tools/web typecheck — clean
  • rebased onto current main (5356de110) and re-verified; no overlap with the upstream sync

No screenshots attached: the maintainer asked to ship this directly without a browser pass.

Model: Claude Opus 5 via Claude Code

…d ones

The workspace threw away everything but its geometry on reload. Open tabs were
rebuilt from whichever thread the URL happened to name, so stopping work meant
reopening every pane by hand. That was a deliberate trade at the time: nothing
could tell a deleted thread apart from one that had simply not synced yet, so
persisting tabs risked restoring dead ones.

Persists the whole workspace — layout, the tabs in each pane, and the selected
thread — and resolves the staleness problem with a prune pass instead of by
discarding state. A tab is only dropped once the environment that owns it has
actually delivered a snapshot and did not report the thread; an environment
that is offline, still syncing, or not yet in the catalog keeps its tabs, and
the routed tab is never dropped because the router needs one to represent.
Everything read out of storage goes through a repair pass, so a truncated or
hand-edited entry degrades to a usable workspace rather than crashing one.

On top of the automatic restore, the layout menu can now save the current
workspace under a name and restore it later. Snapshots store panes by position
and mint fresh pane ids on restore, so restoring one twice cannot alias a live
pane.

The prune pass is gated on a signature of what actually decides its outcome.
Its two inputs churn on ordinary thread traffic, and pruning on each of those
would write the persisted workspace to storage on every incoming message.

Model: Claude Opus 5 via Claude Code
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XL labels Aug 25, 2026
@BarretoDiego
BarretoDiego merged commit 513d17e into main Aug 25, 2026
6 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant