Commit 4cb0edb
authored
🤖 Guarantee workspace createdAt at backend level (#412)
## Problem
**Initial issue:** New workspaces jump from top to bottom after creation
**Root causes:**
1. Backend can create aggregators without `createdAt` → recency defaults
to 0
2. Frontend has race conditions in initialization - effects can access
stores before syncing
## Solution
### Part 1: Backend guarantees `createdAt` (fail-fast)
- **config.ts**: All workspace loading paths guarantee `createdAt`
timestamp
- **StreamingMessageAggregator**: Constructor requires `createdAt:
string` (readonly, not optional)
- **WorkspaceStore**: Added assertions - workspace must exist before
access
### Part 2: Frontend initialization with AppLoader wrapper
**Refactored initialization to use dedicated wrapper component:**
- **AppLoader** component handles:
1. Load workspace metadata and projects
2. Sync stores with loaded data
3. Restore workspace from URL hash (if present)
4. Only renders App when everything is ready
- **App.tsx** now:
- Accepts all state as props (no longer calls management hooks)
- Assumes stores are always synced (no guards needed)
- Simpler effects without conditional execution
**Benefits:**
- Explicit loading boundary at component tree level
- All initialization logic in one place
- No more race conditions between effects
- Similar to Suspense pattern but simpler
### Part 3: Page reload restoration fix
Hash restoration effect now waits for stores to be synced before
running, and URL sync effect doesn't clear hash prematurely.
## Testing
- ✅ All 765 unit tests passing
- ✅ All CI checks passing (lint, typecheck, E2E, integration, visual
regression, storybook)
## Changes
```
docs/AGENTS.md | 2 +
src/App.stories.tsx | 10 +-
src/App.tsx | 162 +++++++++------------
src/components/AppLoader.tsx | 119 +++++++++++++++
src/components/LoadingScreen.tsx | 10 ++
src/config.ts | 10 +-
src/hooks/useWorkspaceManagement.ts | 17 +++
src/main.tsx | 4 +-
src/stores/WorkspaceStore.test.ts | 35 +++--
src/stores/WorkspaceStore.ts | 46 +++---
.../messages/StreamingMessageAggregator.test.ts | 1 -
11 files changed, 273 insertions(+), 143 deletions(-)
```
**Net:** +273 insertions, -143 deletions (+130 lines)
_Generated with `cmux`_1 parent a21c914 commit 4cb0edb
File tree
15 files changed
+461
-187
lines changed- docs
- src
- components
- contexts
- hooks
- stores
- utils/messages
15 files changed
+461
-187
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
| 181 | + | |
| 182 | + | |
181 | 183 | | |
182 | 184 | | |
183 | 185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| |||
618 | 618 | | |
619 | 619 | | |
620 | 620 | | |
621 | | - | |
| 621 | + | |
622 | 622 | | |
623 | 623 | | |
624 | 624 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | 13 | | |
16 | 14 | | |
17 | 15 | | |
18 | 16 | | |
19 | | - | |
20 | 17 | | |
21 | 18 | | |
22 | 19 | | |
| |||
34 | 31 | | |
35 | 32 | | |
36 | 33 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
41 | 47 | | |
42 | 48 | | |
43 | 49 | | |
| |||
59 | 65 | | |
60 | 66 | | |
61 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
62 | 71 | | |
63 | 72 | | |
64 | 73 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | 74 | | |
71 | 75 | | |
72 | 76 | | |
73 | 77 | | |
74 | 78 | | |
75 | 79 | | |
76 | | - | |
77 | 80 | | |
78 | 81 | | |
| 82 | + | |
79 | 83 | | |
80 | 84 | | |
81 | 85 | | |
82 | 86 | | |
83 | 87 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
| 88 | + | |
| 89 | + | |
119 | 90 | | |
120 | | - | |
121 | | - | |
122 | | - | |
| 91 | + | |
| 92 | + | |
123 | 93 | | |
124 | | - | |
| 94 | + | |
125 | 95 | | |
126 | 96 | | |
127 | 97 | | |
| |||
155 | 125 | | |
156 | 126 | | |
157 | 127 | | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | 128 | | |
191 | 129 | | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | 130 | | |
196 | 131 | | |
197 | 132 | | |
| |||
215 | 150 | | |
216 | 151 | | |
217 | 152 | | |
218 | | - | |
| 153 | + | |
219 | 154 | | |
220 | 155 | | |
221 | 156 | | |
| |||
635 | 570 | | |
636 | 571 | | |
637 | 572 | | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
638 | 581 | | |
639 | 582 | | |
640 | 583 | | |
| |||
664 | 607 | | |
665 | 608 | | |
666 | 609 | | |
667 | | - | |
668 | | - | |
669 | | - | |
670 | 610 | | |
671 | 611 | | |
672 | 612 | | |
673 | 613 | | |
674 | | - | |
675 | | - | |
676 | 614 | | |
677 | 615 | | |
678 | 616 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
0 commit comments