Repository navigation
Conversation
pr-reviewer Summary for #7825eef✅ No issues found The code review completed successfully with no findings. Review effort: 2/5 (Simple) SummaryThis PR correctly fixes a long-standing telemetry bug where Production changes reviewed:
No issues found. This is a clean, targeted fix. Token usage: 4,093 input, 2,766 output, 240,180 cache read, 34,542 cache write | Usage Guide New pushes are reviewed automatically with a 10-minute cooldown between reviews. To request a review at any time, comment |
There was a problem hiding this comment.
Auto-approved
This PR was automatically approved because:
- Claude recommends approval
- Claude assessed this as a moderate effort change
- The effort level is within the auto-approval threshold of 2
- No high or critical issues were detected
If you have any concerns, please request a manual review.
Problem
The success-tracking call sites in
src/cli.jsread the cache flag off the payload:Nothing ever sets
fromCacheat the top level.getCachedResponse()records the hit one level down, on_meta:So
result.fromCachewasundefinedon every command andfrom_cachereported a miss for every event — including responses that never touched the network.grep -rn fromCache srcshows the whole story: one writer, on_meta, and two readers that look somewhere else.The
alerts list --tablepath had the same metric broken a second way: it never passedfrom_cacheat all.Why not just read
_meta.fromCacheThat was the first fix I tried, and it is not enough. Handlers are free to rebuild their result, and some do —
alerts listextracts the array out of the response and filters it into a fresh one (src/commands/alerts.js:588), so any marker carried on the body is gone before tracking runs. A test drivingalerts list --tablethrough the real cache still reported a miss.Cache-hit state is therefore recorded on the API instance, for exactly the reason
lastResponseMetaalready lives there — the class comment on that field says it "survives any reshaping a command handler does to the response body".servedFromCacheis set next to the early return inrequest()and read at the tracking sites, so it works regardless of what a handler does to the payload.Fix
src/api.js—this.servedFromCacheis settruebeside the cache-hit early return inrequest()andfalseon the path that goes to the network. Declared in the constructor next tolastResponseMeta, with the same last-write-wins semantics when a handler makes several calls.src/cli.js— the three tracking sites that report on a cacheable response now readapi.servedFromCache. The two sites that cannot involve the cache are left alone: theresult === undefinedbranch (the command wrote its own output) andschema(served locally).Tests
New
src/__tests__/telemetry-from-cache.test.jsdrivesrunCLIend to end with the realNansenAPI, a mockedfetchand a tempHOME, running the same--cachecommand twice and asserting on the tracked event. It covers all three touched paths — default output,--stream, andalerts list --table.Reverting the fix fails all three, which is what the bug looks like from the outside:
Each test also asserts
fetchwas called once across the two runs, so it is a genuine cache hit being measured rather than a second network call.With the fix:
Test Files 1 passed (1),Tests 3 passed (3).npm run lintpasses clean.On the full
npm testrun this branch produces the same failure set as unmodifiedmain— identical files, identical line numbers, identical counts — with 2640 passing against 2637 onmain, the difference being exactly the three new tests. No existing test changes status.Note
This touches
src/api.jsin different places than my open PR for the cached-array shape, so the two are independent and do not conflict.Checklist
npm test— no test changes status vsmain; the new file passes 3/3npm run lintpassesconsole.login core, no hardcoded secretspatch, user-facing fix)src/schema.json— not applicable, no commands or options changed