Skip to content

[Cleanup] Move cachedDeviceId from module scope into store factory closure #225

@samzong

Description

@samzong

What problem are you trying to solve?

cachedDeviceId is a module-level let variable in task-store.ts. Because it lives outside the store factory function, it leaks across store re-creations in the same process. In tests, this means vi.resetModules() is required to get a clean state. Moving it into the factory closure scopes it properly.

Where

packages/core/src/stores/task-store.tscachedDeviceId is declared at the module level (around line 95) and mutated inside the hydrate method.

What needs to be done

  1. Open packages/core/src/stores/task-store.ts
  2. Find let cachedDeviceId: string | null = null; at the module level (around line 95)
  3. Move this declaration inside the store factory function (the function that creates and returns the store)
  4. Verify that the hydrate method that sets cachedDeviceId = await deps.getDeviceId() still has access to the variable in its new scope
  5. Verify that any reads of cachedDeviceId within the factory also still work
  6. Run pnpm check to verify nothing breaks

Why does this matter?

Module-level mutable state creates implicit coupling between store instances and makes testing harder. Moving it into the factory closure ensures each store instance has its own cache.

Primary area

Task execution

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreTask & Session Core WGgood first issueGood for newcomerskind/cleanupCategorizes issue or PR as related to code cleanup

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions