clawwork-ai/ClawWork

[Bug] Race condition in task-store hydrate with cachedDeviceId

Open

#239 创建于 2026年4月1日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)TypeScript (63 fork)github user discovery
area/coregood first issue

仓库指标

Star
 (519 star)
PR 合并指标
 (PR 指标待抓取)

描述

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

  1. Run pnpm check — must pass
  2. Test concurrent hydrate calls don't race

Context

  • WG: Task & Session Core
  • Priority: Low (good first issue)
  • Estimated effort: 15-30 minutes

贡献者指南