impr(CLDSRV-852): Refactor cache and helpers#6107
impr(CLDSRV-852): Refactor cache and helpers#6107tmacro wants to merge 2 commits intoimprovement/CLDSRV-869/account_limitingfrom
Conversation
❌ 109 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
Review by Claude Code |
|
a09c5af to
ec63d65
Compare
4b83cef to
b40ff80
Compare
Review by Claude Code |
b40ff80 to
100976b
Compare
| } | ||
|
|
||
| if (!request.accountLimits) { | ||
| const cachedOwner = cache.getCachedBucketOwner(request.bucketName); |
There was a problem hiding this comment.
cache.getCachedBucketOwner is not defined or exported from cache.js. This will throw a TypeError: cache.getCachedBucketOwner is not a function at runtime.
— Claude Code
| buckets.push(bucket); | ||
|
|
||
| if (allowed) { | ||
| log.trace('Rate limit check: allowed (token consumed)', { |
There was a problem hiding this comment.
Log message says "token consumed" but tokens are not consumed until line 132 (bucket.tryConsume()). At this point we only know the bucket has capacity. Consider changing the message to something like "Rate limit check: passed (has capacity)".
— Claude Code
| // Map<bucketKey, Array<timestamp>> - rolling 1-second window | ||
| const requestTimestamps = new Map(); | ||
| const namespace = { | ||
| bucket: 'bkt', |
There was a problem hiding this comment.
namespace only defines bucket: 'bkt', but helpers.js:93 uses cache.namespace.account which is undefined. This will produce cache keys like undefined:accountId. Add account to the namespace object.
— Claude Code
| function checkRateLimitsForRequest(checks, log) { | ||
| const buckets = []; | ||
| for (const check of checks) { | ||
| const bucket = getTokenBucket(check.resourceClass, check.resourceId, check.measure, check.config, log); |
There was a problem hiding this comment.
getTokenBucket in tokenBucket.js has signature (bucketName, limitConfig, log) (3 params), but here it is called with 5 args: (resourceClass, resourceId, measure, config, log). This means limitConfig receives a string (resourceId) and log receives a string (measure), causing runtime failures.
Also, bucket.hasCapacity() (line 110) does not exist on WorkerTokenBucket — the class only has tryConsume(). This will return undefined (falsy), causing all requests to be denied.
It looks like tokenBucket.js needs to be updated in this PR to match the new calling convention.
— Claude Code
Review by Claude Code |
Note for revewers: This PR "breaks" most of the S3 API unit tests as metadataUtils.js is still using the old helpers. Fixes will come in later feature branch PRs.