diff --git a/.compozy/tasks/server-side-simulation/reviews-002/issue_001.md b/.compozy/tasks/server-side-simulation/reviews-002/issue_001.md index 0ed970d..01c0ffa 100644 --- a/.compozy/tasks/server-side-simulation/reviews-002/issue_001.md +++ b/.compozy/tasks/server-side-simulation/reviews-002/issue_001.md @@ -3,7 +3,7 @@ provider: manual pr: 2 round: 2 round_created_at: 2026-07-05T15:16:15Z -status: pending +status: resolved file: apps/web/src/stores/simulationStore.ts line: 141 severity: medium @@ -46,5 +46,5 @@ Add a store test asserting that after `reset()` a subsequent `play()` emits ## Triage -- Decision: `UNREVIEWED` -- Notes: +- Decision: `VALID` +- Notes: Confirmed — `clearSimId()` was only called on the "unknown simulation" error, never on reset, so localStorage kept the id and the next play() re-attached to the old sim. Fixed: `reset()` now calls `socket.clearSimId()` before closing. Test added: "clears the persisted sim id so the next play starts a fresh simulation" asserts the next play() emits CreateSimulation, not AttachSimulation. Full suite green (248 web tests, turbo 7/7). diff --git a/apps/web/src/stores/simulationStore.test.ts b/apps/web/src/stores/simulationStore.test.ts index 8fc9ee0..47ff773 100644 --- a/apps/web/src/stores/simulationStore.test.ts +++ b/apps/web/src/stores/simulationStore.test.ts @@ -202,4 +202,17 @@ describe('simulationStore — reset', () => { expect(store().simId).toBeNull() expect(store().scenarioVessels).toEqual([]) }) + + it('clears the persisted sim id so the next play starts a fresh simulation', () => { + createSession() + expect(storage.getItem('ymir.simId')).toBe('sim-1') + store().reset() + expect(storage.getItem('ymir.simId')).toBeNull() + + store().play(0.05) + lastWs().open() + const msgs = lastWs().sentMessages + expect(msgs.some((m) => m.type === 'CreateSimulation')).toBe(true) + expect(msgs.some((m) => m.type === 'AttachSimulation')).toBe(false) + }) }) diff --git a/apps/web/src/stores/simulationStore.ts b/apps/web/src/stores/simulationStore.ts index 0936cd2..8a237b8 100644 --- a/apps/web/src/stores/simulationStore.ts +++ b/apps/web/src/stores/simulationStore.ts @@ -141,6 +141,9 @@ export const useSimulationStore = create((set, get) => { reset() { const { socket, simId } = get() if (socket && simId) socket.send({ type: 'Reset', simId }) + // Forget the persisted sim id so the next play() starts a fresh + // simulation instead of re-attaching to the old (reset) one. + socket?.clearSimId() socket?.close() pendingPlayDt = null set({ status: 'idle', error: null, state: null, connection: 'idle', socket: null, simId: null, scenarioVessels: [] })