Skip to content

fix: use in-process flag instead of existsSync for cache availability#3414

Open
garnetlyx wants to merge 1 commit intocode-yeongyu:devfrom
garnetlyx:fix/sandbox-cache-availability-check
Open

fix: use in-process flag instead of existsSync for cache availability#3414
garnetlyx wants to merge 1 commit intocode-yeongyu:devfrom
garnetlyx:fix/sandbox-cache-availability-check

Conversation

@garnetlyx
Copy link
Copy Markdown

@garnetlyx garnetlyx commented Apr 14, 2026

Summary

  • Fixes spurious "Model Cache Not Found" toast warnings that fire on every first message when running as an OpenCode plugin
  • Root cause: existsSync() is unreliable across different Bun sandbox hook contexts (config vs chat.message) because each runs in an isolated virtual filesystem
  • Adds writtenInCurrentProcess flags to json-file-cache-store and connected-providers-cache so cache availability is tracked at the process level instead of relying solely on filesystem checks

Closes #3412

Changes

src/shared/json-file-cache-store.ts

  • Added writtenInCurrentProcess closure-level boolean flag
  • write() sets flag to true on successful write
  • has() uses three-tier check: memoryValue → writtenInCurrentProcess → existsSync()
  • resetMemory() resets the flag

src/shared/connected-providers-cache.ts

  • Added providerModelsCacheWrittenInCurrentProcess module-level flag
  • writeProviderModelsCache() sets flag on successful write
  • hasProviderModelsCache() checks flag before delegating to store's has()
  • _resetMemCacheForTesting() resets the flag

Testing

  • All 5450+ existing tests pass
  • TypeScript typecheck passes
  • Build succeeds (bun run build)
  • connected-providers-cache.test.ts (7 tests) passes

Summary by cubic

Fixes spurious "Model Cache Not Found" toasts by tracking cache writes in-process instead of relying on existsSync in Bun sandbox contexts. Addresses Linear #3412 and stops first-message warnings in the OpenCode plugin.

  • Bug Fixes
    • Added in-process flags: writtenInCurrentProcess in json-file-cache-store and a module-level flag in connected-providers-cache to track successful writes.
    • Updated has() to check memory → in-process flag → filesystem, with write() setting the flag and reset methods clearing it.
    • Prevents false negatives when hook contexts use isolated virtual filesystems.

Written for commit 177c51b. Summary will update on new commits.

In OpenCode plugin sandbox, existsSync fails across different hook
contexts (config vs chat.message) because each runs in an isolated
virtual filesystem. Add writtenInCurrentProcess flags to track cache
writes at the process level, eliminating spurious Model Cache Not
Found toast warnings.

Closes code-yeongyu#3412
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Confidence score: 4/5

  • This PR is likely safe to merge with minimal risk; the reported issue is moderate (5/10) and scoped to cache state tracking rather than a broad functional break.
  • In src/shared/connected-providers-cache.ts, providerModelsCacheWrittenInCurrentProcess can be set to true even when the file write fails, which may falsely signal cache availability and lead to stale/missing cache behavior.
  • Pay close attention to src/shared/connected-providers-cache.ts - ensure the write-success flag is only updated after a confirmed successful file write.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/shared/connected-providers-cache.ts">

<violation number="1" location="src/shared/connected-providers-cache.ts:105">
P2: `providerModelsCacheWrittenInCurrentProcess` is set to `true` even when the underlying file write fails, which can incorrectly report cache availability.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

...data,
updatedAt: new Date().toISOString(),
})
providerModelsCacheWrittenInCurrentProcess = true
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: providerModelsCacheWrittenInCurrentProcess is set to true even when the underlying file write fails, which can incorrectly report cache availability.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/shared/connected-providers-cache.ts, line 105:

<comment>`providerModelsCacheWrittenInCurrentProcess` is set to `true` even when the underlying file write fails, which can incorrectly report cache availability.</comment>

<file context>
@@ -92,6 +102,7 @@ export function createConnectedProvidersCacheStore(
 			...data,
 			updatedAt: new Date().toISOString(),
 		})
+		providerModelsCacheWrittenInCurrentProcess = true
 	}
 
</file context>
Fix with Cubic

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant