Skip to content

Two overlapping App Store reads on a store that is being downloaded make the second one return a half-downloaded or empty store #679

Closed

Description

@nixfred

What happens

registry() in omarchyd/apps.mjs (about lines 962-1005) has no lock and no shared in-flight promise. Every caller that finds the cache empty (or the hourly sync window expired) runs its own syncStore() for every store, and all of them work in the same folder (storeDir(url)).

The callers that overlap in normal use are apps.list (it starts a background registry() as soon as it is first called, line 1357), apps.updates (the Apps screen polls it, web/src/data.ts:29) and appStore.registry (the App Store screen). On the first start, or after the hourly window has passed, two of them run at once:

  • first call: git clone --depth 1 -- URL DIR is still checking files out
  • second call: sees DIR/.git already exists, so it runs git fetch, git reset --hard FETCH_HEAD and git clean -fdx inside the half-written clone, then loadStore() reads whatever folders exist at that moment

(If the second call starts before .git exists it runs its own git clone, which fails because the folder is not empty; the error is swallowed by the empty catch {} and loadStore() runs on the half-written tree, or throws and the store is skipped.)

The second caller then returns a list with some of the apps, or without the store at all. The web app keeps appStore.registry for 10 minutes (staleTime: 10 * 60_000), so the App Store shows "0 apps for your server" or a partial catalog until it is re-fetched. A store with many apps (a clone that takes a second or more) makes the window wide.

How to reproduce

Scratch script (no network, real git, a local bare repository with 2,000 app folders, createApps with allowFileStores: true and run doing real git through execFile):

const p1 = apps.procedures['appStore.registry'].run()
await sleep(delay)
const p2 = apps.procedures['appStore.registry'].run()
const [a, b] = await Promise.all([p1, p2])
console.log(a[0]?.apps.length ?? 'store missing', b[0]?.apps.length ?? 'store missing')

Actual output on a fresh data directory, one run per delay:

delay 0  first call apps: 2000  second call apps: (store missing)
delay 5  first call apps: 2000  second call apps: (store missing)
delay 40 first call apps: 2000  second call apps: 2000

With 2,000 apps and a delay of 60 ms the second call returned 1,533 apps; with 120 ms it returned 1,963. The git commands that ran were clone, then -C DIR fetch --depth 1 origin HEAD and -C DIR reset --hard FETCH_HEAD from the second call.

Expected: both calls return the same complete list (the second one waits for the sync that is already running).

Suggested fix

Keep one in-flight promise for registry() (and one per store for syncStore()), and let overlapping callers await it instead of syncing the same folder again.

Environment

Omarchy Server main (6aa7f7d, 0.9.52), Node 26.

Activity

  1. calledtoconstruct commented on Nov 20, 2026

    @calledtoconstruct
    Collaborator

    Tracked on the checklist in #701. This report stays open for its own reproduction.

    Posted by Grok 4.7 via Grok Build.

  2. calledtoconstruct commented on Nov 21, 2026

    @calledtoconstruct
    Collaborator

    Working to resolve this.

    No open pull request references this issue, and no one has commented that they are working on it.

    This shares the app manager with #804, #688, #138, #679, #528, and #134. They share code and will land in one pull request.

    🤖 Generated with Grok 4.7

  3. calledtoconstruct commented on Nov 21, 2026

    @calledtoconstruct
    Collaborator

    Thank you @nixfred. Overlapping reads of a store that is still downloading share one download. A failed download rejects every waiter, and the next read starts again. This is on main in #844.

    🤖 Generated with Grok 4.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions