Repository navigation
fix(cache): store empty arrays - #15704
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adapters and saveWithLease refused [] along with '' and '0'. Store []; keep refusing '' and '0'. Filesystem and Storage store strings, so they still refuse []. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. No blocking issues — approved ✅; 1 nitpick below. 🧹 Nitpicks (1) — 🟢 1 low
This change relaxes the falsy-value guard in cache adapters so that empty arrays are serialized and stored instead of being rejected, with the base test suite updated to assert the new round-trip contract and adapter-specific overrides adjusted accordingly.
Reviewed commit: 88eb19d |
🟢 Tier S · Ready to mergeThe cache adapters now accept empty arrays while continuing to reject empty and zero strings, with tests covering ordinary writes, leases, touch, CAS, batching, and telemetry. HIBP now distinguishes empty or HTML responses from padded empty ranges, and JWKS tests cover caching an empty key set and later refresh behavior.
📂 Walkthrough · 6
🔇 Filtered out · 1Findings Hansi considered but did not post.
Reviewed |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@Luxor-Code-Review Thanks. The difference between adapters is intended. Filesystem and Storage store strings, so they cannot round-trip an array: a stored
So both keep their |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oad telemetry Co-Authored-By: Claude Opus 5.5 <[email protected]>
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…as no breaches Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@appwrite review |
|
@tenki-reviewer review |
|
Review complete. No issues found — approved ✅. This PR replaces the truthiness-based
Verified candidates did not meet the confidence threshold, so the review is an approval; correctness-3 (a test-only file) never published, accepted as a gap given the other coverage of the same test suite. Reviewed commit: c6bea66 |
Superseded by a newer Luxor approval on this pull request.
fix(auth): refuse unreadable HIBP ranges, cache empty HIBP ranges and JWKS key sets
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@appwrite review |
|
@tenki-reviewer review |
|
Review complete. No issues found — approved ✅. This change standardizes how the packages/cache adapters and Cache facade treat saving an empty array, and hardens the HIBP validator response parsing.
No high-confidence defects were found in the verified candidates; the one remaining verified item was below the reporting threshold. The generated/large files listed as skipped in the diff summary were not reviewed. Reviewed commit: a1c6fb6 |
Superseded by a newer Luxor approval on this pull request.
Issue
Closes #15702 (narrowed to empty arrays, see below). Closes #15703 (folded in from #15705: HIBP and JWKS callers).
Every
utopia-php/cacheadapter refused to store[].save()andCache::saveWithLease()returnedfalseonempty($data), so an empty answer was never cached and was fetched again on every request.Solution
The change is limited to empty arrays.
''and'0'stay refused, exactly as before.Redis,Redis\Multiplexing,RedisCluster,Memory,Memcached,HazelcastandCache::saveWithLease():empty($data)becomes$data === '' || $data === '0'. Key checks and return values are unchanged.FilesystemandStorageare unchanged. They store strings and cannot round-trip an array ([]would read back as''), so they keep refusing[],''and'0'.Pool,CircuitBreakerandShardingdelegate, so they store[]when their inner adapter does.save()stores and refuses. The example's miss check is nowif ($data === false), becauseif (!$data)treats a cached[]as a miss, and the line says a successfulsave([])returns[], so callers compare with=== false.Needs a major release of
utopia-php/cache(latest tagcache/7.1.0, so this iscache/8.0.0), becausesave([])no longer returnsfalse. Not tagged here; releasing is a separate call.Tests
New and changed tests, all in
packages/cache/tests:Base::testEmptyArrayIsStored:[]saves and loads back as[]; a never-written key, an expired entry (TTL 0) and a purged key load asfalse. Runs on every adapter test class (Memory, Pool, None, and in E2E Redis, RedisCluster, Sharding, Memcached, Hazelcast).Base::testEmptyArrayIsStoredWithLease: the same throughsaveWithLease, on adapters that support versioning (skipped elsewhere).Base::testEmptyStringIsRefused:''and'0'are still refused on every adapter.FilesystemTest,StorageTest,PoolTest(a pool of Filesystem) andNoneTestoverridetestEmptyArrayIsStoredto assert[]is still refused.PoolTest::testEmptyArrayIsStoredThroughAPoolOfMemory:[]through Pool, withsaveandsaveWithLease.CircuitBreakerTest::testPassesThroughAnEmptyArray:[]through CircuitBreaker;''and'0'still refused.E2E/MultiplexingTest::testEmptyArrayIsStored: Multiplexing does not extendBase, so it gets its own copy.MemoryTest::testConditionalFillsRejectTheSameEmptyInputsAsOrdinarySavesis renamedtestConditionalFillsTreatEmptyInputsLikeOrdinarySaves: the''and'0'cases stay refused, the[]case is now stored.Locally I ran the unit tier only (no Docker, and no redis, swoole or igbinary extension). The Redis, RedisCluster, Sharding, Memcached, Hazelcast and Multiplexing tests run in CI (
bin/monorepo test cache).Red: new tests on the old source (unit tier, filtered)
The 3 errors are
CodecTestdata providers that need the igbinary extension, which my machine does not have. They also fail onmain.Green: same filter after the fix
Full unit tier:
Tests: 175, Assertions: 429, Errors: 13, Skipped: 9, 0 failures. All 13 errors need igbinary, redis or swoole, are in files this PR does not touch, and also fail onmain.bin/monorepo check cache: Rector, Pint and PHPStan pass.Follow-up: other paths
[]can takeAdded after review, in the shared
Baseso every adapter test class runs them, with the same refusal overrides as above for Filesystem, Storage, None and Pool (of Filesystem):Base::testEmptyArrayIsKeptByTouch:touch()on a stored[]keeps it as[]. The overrides assertsave([])andtouch()both returnfalse.Base::testEmptyArrayIsStoredWithCompareAndSwap: on versioned adapters (skipped elsewhere),compareAndSwapwith[]returns a version andloadVersionedreturns['version' => <that version>, 'value' => []].Base::testEmptyArrayFieldIsStoredInABatch:saveManywith a field value[]round-trips throughloadMany. Batch writes already accepted[]; this locks it in. Skipped when the adapter does not store fields, so it runs on Redis and Sharding in E2E.LoadResultsTelemetryTest::testEmptyArrayLoadIsAHit: a load of a stored[]is counted as ahit.''and'0'throughcompareAndSwapandsaveManyare out of scope here and tracked in #15707.Red: follow-up tests on the cache source of
origin/main(unit tier, filtered)The other 3 errors are the igbinary
CodecTestdata providers, as above.Green: same filter on this branch
Full unit tier:
Tests: 191, Assertions: 444, Errors: 13, Skipped: 18, 0 failures (the same 13 extension errors as before).bin/monorepo check cache: Rector, Pint and PHPStan pass.New files, classes and tests
No new files or classes. New test methods:
Base::testEmptyArrayIsKeptByTouch,Base::testEmptyArrayIsStoredWithCompareAndSwap,Base::testEmptyArrayFieldIsStoredInABatch,LoadResultsTelemetryTest::testEmptyArrayLoadIsAHit,Base::emptyStrings,Base::testEmptyArrayIsStored,Base::testEmptyArrayIsStoredWithLease,Base::testEmptyStringIsRefused,PoolTest::testEmptyArrayIsStoredThroughAPoolOfMemory,CircuitBreakerTest::testPassesThroughAnEmptyArrayandMultiplexingTest::testEmptyArrayIsStored, each listed above.Folded in from #15705
Two callers start caching an empty array once this change lands, and #15705 (merged into this branch) covers them:
src/Appwrite/Auth/Validator/PasswordPwned/HIBP.php): a 200 response with noSUFFIX:COUNTentry at all (an empty body or an HTML page) now raisesGENERAL_PWNED_PASSWORDS_UNAVAILABLE, instead of being read as "no breaches" and cached for an hour. A range made only of padding entries is still valid, and is cached as no breaches.src/Appwrite/Auth/OIDC/Jwks.php): no code change. A test shows an empty key set is fetched once and cached, and that a newly published key is still picked up after the refresh cooldown.See #15705 for the red/green output.
🤖 Generated with Claude Code