Skip to content

fix: Model cache toast warning fires on every first message in OpenCode plugin sandbox #3412

@garnetlyx

Description

@garnetlyx

Problem

When OmO runs as an OpenCode plugin (Bun runtime sandbox), the "Model Cache Not Found" toast warning appears on every first message of a session, even though the cache was successfully written moments before.

Root Cause

isModelCacheAvailable() calls hasProviderModelsCache(), which ultimately calls existsSync() on the cache file. In the OpenCode plugin sandbox:

  1. The config hook runs updateConnectedProvidersCache() which calls writeFileSync — this succeeds in the sandbox virtual filesystem
  2. The chat.message hook then calls isModelCacheAvailable() which calls existsSync() — but this runs in a different sandbox context
  3. The file written in step 1 is invisible to the filesystem check in step 2
  4. Result: isModelCacheAvailable() returns false every time, triggering the warning toast

Key Files

  • src/shared/json-file-cache-store.tshas() uses existsSync() as its final fallback
  • src/shared/connected-providers-cache.tshasProviderModelsCache() delegates to the stores has()
  • src/shared/model-availability.tsisModelCacheAvailable() triggers the false-negative path

Fix

Added in-process tracking flags so that has() never needs to hit existsSync() if the cache was already written in the current process:

json-file-cache-store.ts

  • Added writtenInCurrentProcess module-level boolean flag
  • write() sets writtenInCurrentProcess = true on success
  • has() checks memoryValue → writtenInCurrentProcess → existsSync() (three-tier)
  • resetMemory() resets the flag

connected-providers-cache.ts

  • Added providerModelsCacheWrittenInCurrentProcess module-level flag
  • writeProviderModelsCache() sets it to true
  • hasProviderModelsCache() checks the flag before delegating to the stores has()
  • _resetMemCacheForTesting() resets it

This ensures that in sandbox environments where existsSync() is unreliable across hook contexts, the cache is still correctly detected as available.

Impact

  • Eliminates spurious "Model Cache Not Found" toast warnings in the OpenCode plugin runtime
  • No behavior change for non-sandbox environments (falls back to existsSync() as before)
  • All 5450+ existing tests pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions