Conversation
There was a problem hiding this comment.
I'm Bonk, and I've done a quick review of your PR.
This PR adds a ctx.cache stub property to ExecutionContext, delegating to a virtual Worker::Api::getCtxCacheProperty() hook that returns undefined by default.
Issues (highest severity first):
- [HIGH] New
ctx.cacheproperty is unconditionally exposed with no compat flag or autogate. Adding a new property to everyExecutionContextinstance is a behavioral change — it could shadow user-definedcacheproperties or break code that checks'cache' in ctx. Otherctxproperties (exports,version,abort) are all gated behind compat flags. This needs at minimum a compat flag or autogate for staged rollout. - [MEDIUM] No tests. There are no tests covering the new
getCache()path or thegetCtxCacheProperty()hook. - [LOW] Missing TypeScript type definition. The
JSG_TS_OVERRIDEblocks inJSG_RESOURCE_TYPEdon't includecache, so generated TypeScript types won't reflect this property. - [LOW] Comment inaccuracies. Minor comment issues flagged inline.
These comments were generated by an AI code review assistant and may not be perfect. Please use your judgment when evaluating them.
| JSG_LAZY_INSTANCE_PROPERTY(exports, getExports); | ||
| } | ||
| JSG_LAZY_INSTANCE_PROPERTY(props, getProps); | ||
| JSG_LAZY_INSTANCE_PROPERTY(cache, getCache); |
There was a problem hiding this comment.
[HIGH] This property is registered unconditionally, meaning every worker will see ctx.cache. Other ctx properties like exports (line 249-251), version (line 254-256), and abort (line 269) are all gated behind compat flags.
Adding a new enumerable property to a widely-used object without a gate is a backward-compat risk — it can break code that does 'cache' in ctx checks or Object.keys(ctx) assertions. This should be gated behind a compat flag or at minimum an autogate for staged rollout.
| JSG_LAZY_INSTANCE_PROPERTY(cache, getCache); | |
| // TODO(cleanup): Gate behind a compat flag once the feature is ready. | |
| // JSG_LAZY_INSTANCE_PROPERTY(cache, getCache); |
(The suggestion above is just illustrative — in practice you'd wrap this in an if (flags.getSomeNewFlag()) { ... } block like the other properties.)
There was a problem hiding this comment.
@jasnell we don't want ctx.cache to be based on a compat flag, we want it to be based on a config option, namely CacheConfig.enabled = true in the internal worker config (or maybe in the future the workerd config).
Is there a way to sort this so that ctx.cache is "not defined" in that scenario rather than "undefined"?
There was a problem hiding this comment.
That's a bit tricky here. We don't expose any mechanism currently to access the worker configuration at this point in the registration. Would have to solve that limitation first.
| return props.getHandle(js); | ||
| } | ||
|
|
||
| // Returns an optional cache object for CacheW-enabled workers. |
There was a problem hiding this comment.
[LOW] "CacheW-enabled" looks like a typo — did you mean "Cache-enabled"?
Also, the comment says "Overridden via IoChannelFactory" but the actual override mechanism is through Worker::Api subclassing (the virtual getCtxCacheProperty() method). The comment should reflect the actual design.
| // Returns an optional cache object for CacheW-enabled workers. | |
| // Returns an optional cache object for cache-enabled workers. | |
| // The default implementation returns undefined. Overridden via Worker::Api. |
There was a problem hiding this comment.
Yeah bonk is right, seems like an odd typo.
| IoContext::current().setFailOpen(); | ||
| } | ||
|
|
||
| jsg::JsValue ExecutionContext::getCache(jsg::Lock& js) { |
There was a problem hiding this comment.
[LOW] The IoContext::hasCurrent() guard means this silently returns undefined when called outside of request context. This is consistent with the pattern for a lazy property getter, but worth noting: if the embedding override returns a JS object (not undefined), the caller might be surprised that ctx.cache is undefined in some code paths (e.g., module top-level evaluation). Consider adding a brief comment explaining when this fallback triggers.
|
Review posted successfully on PR #6465. Here's a summary of the findings:
|
|
The generated output of |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6465 +/- ##
==========================================
- Coverage 70.95% 70.90% -0.05%
==========================================
Files 428 428
Lines 119850 119943 +93
Branches 18988 19003 +15
==========================================
+ Hits 85037 85048 +11
- Misses 23529 23606 +77
- Partials 11284 11289 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| JSG_METHOD(abort); | ||
| } | ||
|
|
||
| // TODO(soon): This is getting unwieldy. |
There was a problem hiding this comment.
ctx.cache is missing in the types override
No description provided.