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:
- The
config hook runs updateConnectedProvidersCache() which calls writeFileSync — this succeeds in the sandbox virtual filesystem
- The
chat.message hook then calls isModelCacheAvailable() which calls existsSync() — but this runs in a different sandbox context
- The file written in step 1 is invisible to the filesystem check in step 2
- Result:
isModelCacheAvailable() returns false every time, triggering the warning toast
Key Files
src/shared/json-file-cache-store.ts — has() uses existsSync() as its final fallback
src/shared/connected-providers-cache.ts — hasProviderModelsCache() delegates to the stores has()
src/shared/model-availability.ts — isModelCacheAvailable() 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
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()callshasProviderModelsCache(), which ultimately callsexistsSync()on the cache file. In the OpenCode plugin sandbox:confighook runsupdateConnectedProvidersCache()which callswriteFileSync— this succeeds in the sandbox virtual filesystemchat.messagehook then callsisModelCacheAvailable()which callsexistsSync()— but this runs in a different sandbox contextisModelCacheAvailable()returnsfalseevery time, triggering the warning toastKey Files
src/shared/json-file-cache-store.ts—has()usesexistsSync()as its final fallbacksrc/shared/connected-providers-cache.ts—hasProviderModelsCache()delegates to the storeshas()src/shared/model-availability.ts—isModelCacheAvailable()triggers the false-negative pathFix
Added in-process tracking flags so that
has()never needs to hitexistsSync()if the cache was already written in the current process:json-file-cache-store.tswrittenInCurrentProcessmodule-level boolean flagwrite()setswrittenInCurrentProcess = trueon successhas()checksmemoryValue → writtenInCurrentProcess → existsSync()(three-tier)resetMemory()resets the flagconnected-providers-cache.tsproviderModelsCacheWrittenInCurrentProcessmodule-level flagwriteProviderModelsCache()sets it totruehasProviderModelsCache()checks the flag before delegating to the storeshas()_resetMemCacheForTesting()resets itThis ensures that in sandbox environments where
existsSync()is unreliable across hook contexts, the cache is still correctly detected as available.Impact
existsSync()as before)