Make target.loadedFromSource the sole cache-disposition signal (net of v5.1 #1575 + #1590)#1626
Make target.loadedFromSource the sole cache-disposition signal (net of v5.1 #1575 + #1590)#1626kriszyp wants to merge 3 commits into
Conversation
…v5.1 #1575 + #1590) Make target.loadedFromSource the sole cache-disposition signal. - setLoadedFromSource() writes only the RequestTarget, guarding against primitive-id instance-API targets; no Context mirror. - Mark disposition false on cache hits in the loadAsInstance=false value path and ensureLoaded branch so REST emits the Age header on hits. - Remove the unused wasLoadedFromSource() method and Context.loadedFromSource declaration. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request refactors how the cache disposition flag loadedFromSource is set and tracked. It removes the unused wasLoadedFromSource method from Resource and ResourceInterface, and introduces a helper function setLoadedFromSource in Table.ts to safely set the flag on the RequestTarget object, preventing issues when the target is a primitive ID. Additionally, new unit tests are added to verify this behavior under different caching configurations. I have no feedback to provide.
|
Reviewed; no blockers found. Non-blocking suggestion — |
|
CI note: the red Unit Test job (v22/v24/v26) is the pre-existing Posted by KrAIs (Claude Opus 4.8). |
…king (#1576) Addresses cb1kenobi's review note on PR #1626 (two low-risk coverage gaps): - loadAsInstance=false onlyIfCached cache-hit marks target.loadedFromSource=false (the value-path twin of the loadAsInstance=true instance path; previously untested). - primitive-id instance-API getResource() no longer throws when recording cache disposition — locks in the `typeof target === 'object'` guard in setLoadedFromSource. Verified the test fails without the guard ("Cannot create property 'loadedFromSource' on number '41'"). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
seems like a rebase is needed to know if this can land cleanly. Rerequest review once rebased. Thanks! sent with Claude Fable 5 |
Brings the net end-state of the
loadedFromSourcecache-disposition work tomain/5.2. That work landed only onv5.1as two PRs — #1575 (initial fix) and #1590 (rework) — and was never onmain. This is the single clean end-state, not a replay of #1575-then-#1590.Why
Cache disposition (
loadedFromSource: served from source vs. cache) is fundamentally a per-get()result — eachget()has its ownRequestTarget. #1575 additionally mirrored disposition onto the request Context, which is shared for the whole request lifecycle, making it last-write-wins: an internal cachingget()inside a resource's ownget()overwrites the entry get's disposition before the caller reads it. #1590 dropped that mirror and standardized ontarget.loadedFromSource, whichserver/REST.tsalready reads.What changed
target.loadedFromSourceis the sole signal. NewsetLoadedFromSource(target, bool)helper inTable.tswrites only theRequestTarget, with a primitive-id guard (typeof target === 'object') — instance-API calls can pass a primitive id that can't hold the flag. No Context writes anywhere.Ageheader now emitted on cache hits. TheloadAsInstance=falsevalue path and theensureLoadedbranch (Table.ts~1229/~1242) previously set the flag only on source fetch, leaving itundefinedon hits — soREST.ts(if (loadedFromSource !== undefined)) skipped theAgeheader on hits. They now markfalseon hits.wasLoadedFromSource()method (Resource.ts/ResourceInterface.ts) and theContext.loadedFromSourcedeclaration (ResourceInterface.ts), both now unused.Where to look
resources/Table.tsis the substance — 7 small hunks routing all disposition writes through the guarded helper plus the two new cache-hit markings. The get() path is hot; the helper is a trivial branch, no added async.security/certificateVerification/{ocsp,crl}Verification.tsstill callcacheEntry.wasLoadedFromSource?.(). Removing the method is behavior-preserving there — it always returnedundefined/void, and the optional-chaining call now yieldsundefined, i.e. the same "cache hit" branch as before. To actually observe disposition there, aRequestTargetmust be passed to the get; that's out of scope here (matches Make target.loadedFromSource the sole cache-disposition signal; drop the Context mirror (#1576) #1590's downstream note). This is the one spot worth a reviewer's eye.Testing
Ported the v5.1 caching unit coverage to
unitTests/resources/caching.test.js: aloadAsInstance=falsehit/miss case and a stale-while-revalidateloadedFromSource=falseassertion. 15/15 caching tests pass againstdist.Generated by KrAIs (Claude Opus 4.8), at Kris's direction.