문제: 옮긴 기록은 지금 동작을 설명하는지, 상태가 무엇인지, 지금 정본이 어디인지 알 길이 없다. 설계서·계획서 27개와 docs/architecture 목표 설계 16개에는 상태 칸이 없고, VD는 「상태: Accepted」 같은 영어 값을 쓴다. 고른 방법: docs-system.md 4절 형식으로 맨 위에 머리 블록을 달고 본문은 한 글자도 고치지 않는다. 상태는 기계 변환이다. - 설계서: Accepted·확정·정본·설계 완료 → 채택, 상태 줄이 없으면 확인 안 함 (채택 4, 확인 안 함 21) - 계획서: 체크 상자가 모두 표시됐으면 끝남, 아니면 확인 안 함. SPEC.md는 같은 폴더 plan.md와 같은 근거(0.2.0으로 끝난 라운드)로 끝남 (끝남 5, 확인 안 함 14. 이미 블록이 있던 5개는 그대로) - 결정 기록: Accepted → 채택, 날짜가 붙은 뒤늦은 보완 메모가 본문에 있으면 채택(보완) (채택 14, 채택(보완) 9). 프론트 VD는 처음부터 한국어로 썼고 번역하지 않으므로 둘째 줄은 「원문이다」 문구다. - 작성일: 파일 이름 날짜 → 본문 날짜 줄(VD는 `결정일:`) → git 첫 추가일. 위험: VD-09·11·13은 git으로 보면 결정 뒤 본문이 그 자리에서 고쳐졌지만 본문에 날짜 표시가 없어 기계 규칙대로 채택으로 두었다. 보완으로 올릴지는 사람이 정한다. 「현재 정본」은 지금 있는 살아 있는 문서나 코드 경로만 쓴다. 검증: 블록과 그 뒤 빈 줄 하나를 빼면 72개 모두 `git show HEAD:`와 바이트가 같다. 뒤 커밋의 문서 검사 head 규칙으로 돌려 문제 0건.
6.5 KiB
기록 · 계획서 본문은 쓴 때의 원문이다. 지금 동작은 「현재 정본」을 읽는다.
- 상태: 확인 안 함
- 작성일: 2026-08-01
- 요약: 인증 scope가 바뀐 뒤 이전 계정의 query와 낙관적 상태가 화면에 남거나 다시 쓰이지 않게 하는 구현 계획이다.
- 현재 정본:
src/bootstrap/server-state-generation-store.ts,src/presentation/adapters/query/server-state-scope-provider.tsx
Scope-Owned Server State Implementation Plan
For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: Prevent previous-account query and optimistic state from remaining renderable or writable after an authentication scope transition.
Architecture: The scope runtime is a fail-closed lifecycle authority. A bootstrap generation store owns a QueryClient and its concrete invalidation coordinator, swaps them only after the previous generation is closed, and exposes a stable invalidation facade plus a subscribable generation snapshot to React.
Tech Stack: TypeScript 7, React 19, TanStack Query 5, Vitest 4, Testing Library.
Global Constraints
- FENCED is synchronous and no previous-account UI may render after it.
- Mandatory participant or cache cleanup failure never publishes READY.
- Snapshot subscriber defects never prevent reset scheduling.
- Every READY generation owns a different QueryClient identity.
- Late work from an old generation cannot write through the stable coordinator.
- Preserve existing public application ports and dirty-worktree changes.
Task 1: Fail-closed scope lifecycle
Files:
- Modify:
src/contracts/server-state-scope.ts - Modify:
src/adapters/query-cache/server-state-scope-runtime.ts - Modify:
tests/unit/server-state-scope-runtime.test.ts
Interfaces:
-
Adds phase
FAILEDand lifecycle event{ kind: "FAILED"; generation: number }. -
Adds dependency callback
activateNextGeneration(): void | Promise<void>executed after old local reset and before READY. -
Add failing tests for a throwing snapshot listener, participant failure, reset failure, and next-generation activation failure.
-
Run
corepack pnpm exec vitest run tests/unit/server-state-scope-runtime.test.tsand confirm each new behavior fails for the intended reason. -
Notify listeners from a stable snapshot with per-listener exception isolation.
-
Continue all cleanup participants, remember the first mandatory failure, and always attempt local reset.
-
Close old identities after cleanup, then publish FAILED if any mandatory step failed.
-
Call
activateNextGenerationonly after successful reset and publish READY only after it succeeds. -
Re-run the focused unit test and confirm all lifecycle cases pass.
Task 2: Render fence surface synchronously
Files:
- Modify:
src/presentation/adapters/query/server-state-scope-provider.tsx - Create:
tests/component/server-state-scope-provider.test.tsx
Interfaces:
-
ServerStateScopeProvidersubscribes to both snapshot and phase through one store notification. -
Props add optional
transitionFallback?: ReactNode; default isnull. -
Existing
useServerStateScope()continues returningCacheScopeSnapshotfor feature hooks. -
Add a failing component test that renders private child data, triggers a deferred reset, and expects the child to disappear in the same
act()turn. -
Add a failing test that FAILED never remounts children.
-
Run the new component test and confirm old children remain with the current provider.
-
Subscribe in the provider and render children only for READY; render the supplied fallback for FENCED/FAILED and nothing after DISPOSED.
-
Re-run the test and confirm no old-data frame is observable.
Task 3: QueryClient generation store and stable coordinator facade
Files:
- Create:
src/bootstrap/server-state-generation-store.ts - Modify:
src/bootstrap/runtime-adapters.ts - Modify:
src/bootstrap/runtime-application.tsx - Modify:
tests/unit/runtime-adapters.test.ts - Modify:
tests/component/runtime-application.test.tsx
Interfaces:
-
ServerStateGenerationSnapshot = { generation: number; queryClient: QueryClient; coordinator: QueryInvalidationCoordinator; crossContextStatus(): CrossContextInvalidationStatus }. -
Store methods:
getSnapshot(),subscribe(listener),activateNext(),resetCurrent(),dispose(). -
A stable
QueryInvalidationCoordinatorfacade delegates only to the current snapshot and fences delegates by generation. -
Add a failing unit test that captures the initial QueryClient, triggers session transition, completes reset, and expects a different current QueryClient.
-
Add a failing test that an old captured coordinator cannot invalidate after activation.
-
Add a component test that QueryClientProvider receives and renders against the new generation.
-
Implement generation factory ownership in bootstrap; create cross-context transport and concrete coordinator per generation.
-
Pass
resetCurrentandactivateNextto the scope runtime in the required order. -
Make
RuntimeApplicationsubscribe to the generation store and key the QueryClient provider by generation. -
Dispose the current generation and store exactly once during application shutdown.
-
Run runtime-adapter and runtime-application tests until all pass.
Task 4: Conditional validator and cleanup ordering
Files:
- Modify:
src/bootstrap/runtime-adapters.ts - Modify:
tests/unit/runtime-adapters.test.ts
Interfaces:
-
Conditional validator clearing becomes an ordered mandatory scope participant rather than a general snapshot subscriber.
-
Add a failing order test proving validator clear occurs after admission fence and before cache disposal.
-
Register the validator closer with an explicit order and remove the generic subscription.
-
Re-run runtime-adapter tests and verify each closer executes once.
Task 5: Verification
- Run scope runtime, provider, runtime-adapter, runtime-application, and application-query focused suites.
- Run
corepack pnpm check:typesandcorepack pnpm lint. - Run the complete non-browser suite.
- Record browser-only follow-up separately; do not claim it passed without Playwright evidence.