-
Notifications
You must be signed in to change notification settings - Fork 30
[Bug] Race condition in task-store hydrate with cachedDeviceId #239
Copy link
Copy link
Open
Labels
area/coreTask & Session Core WGTask & Session Core WGgood first issueGood for newcomersGood for newcomers
Description
Problem
Module-level mutable variable cachedDeviceId creates a race condition when hydrate() is called concurrently. Multiple calls can overwrite each other's state.
Location
File: packages/core/src/stores/task-store.ts:95
Code:
let cachedDeviceId: string | null = null;
// In hydrate():
if (get().hydrated) return;
cachedDeviceId = await deps.getDeviceId();Fix Approach
Use a hydration promise to ensure single execution:
let hydrationPromise: Promise<void> | null = null;
// In hydrate:
if (get().hydrated) return;
if (hydrationPromise) return hydrationPromise;
hydrationPromise = (async () => {
cachedDeviceId = await deps.getDeviceId();
// ... rest of hydration
})();
return hydrationPromise;Or move cachedDeviceId into store state.
Verification
- Run
pnpm check— must pass - Test concurrent hydrate calls don't race
Context
- WG: Task & Session Core
- Priority: Low (good first issue)
- Estimated effort: 15-30 minutes
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area/coreTask & Session Core WGTask & Session Core WGgood first issueGood for newcomersGood for newcomers