ADR-0007: Scheduled paydown of imperative server state on workspace-affected pages
- Status: Accepted
- Date: 2026-08-11
- Deciders: Cardsite platform team (workstream 004, operator-directed)
Context
ADR-0005 made TanStack Query a ratchet: new fetches use hooks, legacy
useEffect+services/* pages are "accepted legacy, not a defect to
file", migrating only when a change touches their data flow. That
stance assumed the legacy pattern was merely architectural drift.
Workspace tenancy (ADR-0006) changed the facts. useSwitchWorkspace
clears the query cache, so hook-based pages refetch under the new
X-Workspace-ID — but 62 of 81 pages hold server rows in component
useState, which the cache clear cannot reach, and their effects do
not depend on the active workspace. Switching workspaces while such a
page is mounted leaves the previous workspace's data on screen. The
debt is now a correctness bug on every workspace-scoped list surface.
Decision
Workspace-affected user-facing pages migrate to hooks/queries/ as
scheduled work (workstream 004, waves B1–B3), not opportunistically.
ADR-0005's other rules are unchanged: new code uses hooks, all
mutations invalidate, and admin pages (single-workspace surfaces where
the staleness bug cannot bite) remain accepted legacy, migrating
opportunistically or in an explicit stretch wave.
Consequences
The stale-workspace bug is fixed page-by-page as each migrates, with a workspace-switch E2E assertion per wave. Anticipatory query keys gain consumers or are deleted in the wave covering their resource, ending the dead-key drift. The cost is the churn ADR-0005 sought to avoid — accepted because the sweep now has user-visible payoff, and it is paced in reviewed waves rather than one bulk mechanical pass (the R2 audit's regression source).
Alternatives considered
- Keep opportunistic-only migration — rejected: leaves a live cross-tenant display bug on ~60 pages indefinitely.
- Make imperative pages workspace-aware (subscribe effects to the workspace store) — rejected: invests in the deprecated pattern and doubles the eventual migration.
- Workspace-scope all query keys instead of clearing the cache — deferred, not rejected: only helps pages already on hooks; may land as a final step after the waves.
Source: docs/decisions/0007-query-ratchet-scheduled-paydown.md