Fix effect cache returning nested-option sentinel for None#1284
Merged
Conversation
A cached effect with an optional output that resolves to None returns the
ReScript nested-option sentinel { BS_PRIVATE_NESTED_SOME_NONE: 0 } instead
of undefined on a cache hit, because the in-memory effect cache stores
option<output> and the hit path returns it without unwrapping the outer
option, leaking Some(None).
The in-memory effect cache stored option<output>; getEffectOutput wrapped
the raw output in Some(), encoding Some(None) as the nested-option sentinel
{ BS_PRIVATE_NESTED_SOME_NONE: 0 } for effects with an optional output that
resolved to None. getUnsafeInMemory unwrapped with Option.getUnsafe (an
identity), so the sentinel leaked to the handler instead of undefined.
Split getEffectOutput into hasEffectOutput (presence check) and
getEffectOutputUnsafe (raw output), mirroring InMemoryTable.Entity.getUnsafe,
so the output is never wrapped in an extra option.
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR fixes a regression in envio v3.1.0-rc.x where optional effect outputs were incorrectly cached. The in-memory store's cache API was refactored from ChangesEffect cache optional output handling
🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
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
Fixes a regression in envio v3.1.0-rc.x where effects with optional outputs that resolve to
Nonewould leak the ReScript nested-option sentinel{ BS_PRIVATE_NESTED_SOME_NONE: 0 }instead ofundefinedwhen served from the in-memory cache.Root Cause
The in-memory effect cache stores
option<output>for all effects. When an effect with optional output (e.g.,option<bigint>) returnsNone, the cache storesSome(None). On cache hits, the code was wrapping this cached value in anotherOption.getUnsafe, which returned the rawSome(None)to the handler instead of unwrapping it toNone/undefined.Key Changes
InMemoryStore.res: Split
getEffectOutputinto two functions:hasEffectOutput: Checks cache presence without wrapping the resultgetEffectOutputUnsafe: Returns the raw cached output directly (never wrapped inOption), preventing the nested-option sentinel from leakingLoadLayer.res: Updated cache access to use the new functions, eliminating the extra
Optionwrapping that was causing the regressionLoadLayer_test.res: Added regression test verifying that optional outputs resolving to
Nonereturnundefined(not the sentinel) on cache hitsImplementation Details
The fix ensures the cache hit path mirrors the cache miss path: both return the raw effect output without additional option wrapping. For effects with optional outputs,
Noneis now correctly represented asundefinedin both paths.https://claude.ai/code/session_01QV6rPnY9qR7RubvyACNUdb
Summary by CodeRabbit
Bug Fixes
Tests