fix: use in-process flag instead of existsSync for cache availability#3414
Open
garnetlyx wants to merge 1 commit intocode-yeongyu:devfrom
Open
fix: use in-process flag instead of existsSync for cache availability#3414garnetlyx wants to merge 1 commit intocode-yeongyu:devfrom
garnetlyx wants to merge 1 commit intocode-yeongyu:devfrom
Conversation
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
There was a problem hiding this comment.
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,providerModelsCacheWrittenInCurrentProcesscan 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 |
There was a problem hiding this comment.
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
existsSync()is unreliable across different Bun sandbox hook contexts (config vs chat.message) because each runs in an isolated virtual filesystemwrittenInCurrentProcessflags tojson-file-cache-storeandconnected-providers-cacheso cache availability is tracked at the process level instead of relying solely on filesystem checksCloses #3412
Changes
src/shared/json-file-cache-store.tswrittenInCurrentProcessclosure-level boolean flagwrite()sets flag totrueon successful writehas()uses three-tier check:memoryValue → writtenInCurrentProcess → existsSync()resetMemory()resets the flagsrc/shared/connected-providers-cache.tsproviderModelsCacheWrittenInCurrentProcessmodule-level flagwriteProviderModelsCache()sets flag on successful writehasProviderModelsCache()checks flag before delegating to store'shas()_resetMemCacheForTesting()resets the flagTesting
bun run build)connected-providers-cache.test.ts(7 tests) passesSummary by cubic
Fixes spurious "Model Cache Not Found" toasts by tracking cache writes in-process instead of relying on
existsSyncin Bun sandbox contexts. Addresses Linear #3412 and stops first-message warnings in the OpenCode plugin.writtenInCurrentProcessinjson-file-cache-storeand a module-level flag inconnected-providers-cacheto track successful writes.has()to check memory → in-process flag → filesystem, withwrite()setting the flag and reset methods clearing it.Written for commit 177c51b. Summary will update on new commits.