Skip to content

Bug: Welcome session deleted by persister race condition on first launch #3767

@devin-ai-integration

Description

@devin-ai-integration

Bug: "Welcome to Hyprnote" session is deleted immediately after creation

Description

When a new user launches the app for the first time (no existing data on disk), initializeStore creates a "Welcome to Hyprnote" session in memory. However, this session is immediately deleted by the session persister's initial load.

Root Cause

Race condition between useInitializeStore and useSessionPersister in persisters.ts:

  1. React renders, effects fire in order
  2. Session persister's effect starts the async factory (useCreatePersister calls startAutoPersisting()) — does not block
  3. useInitializeStore's effect fires — store has no sessions yet, so it creates the "Welcome to Hyprnote" session in memory
  4. The async startAutoPersisting() completes — performs its initial load from disk

The initial load goes through multi-table-dir.tsdeletionMarker.markAll():

  • For every row in the store that is NOT in the loaded disk data, it marks that row as undefined (deleted)
  • Since the welcome session was just created in memory and never saved to disk, loadAll returns data without it
  • markAll sees it in the store but not on disk → marks it for deletion
  • The store applies this, and the session disappears

Relevant Files

  • apps/desktop/src/store/tinybase/store/initialize.ts — creates the welcome session
  • apps/desktop/src/store/tinybase/store/persisters.ts — hooks up persisters and initialization
  • apps/desktop/src/store/tinybase/persister/session/index.ts — async session persister factory
  • apps/desktop/src/store/tinybase/persister/factories/multi-table-dir.ts — load + deletion marker logic
  • apps/desktop/src/store/tinybase/persister/shared/deletion-marker.tsmarkAll implementation

Fix

Ensure initializeStore runs after the session persister's initial load completes by gating it on the sessionPersister being non-null (returned by useCreatePersister only after the async factory resolves).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions