Commit a7f1a05
committed
fix(cache): harden invalidation helpers + align fingerprint expiry
Two bot-review findings on commit 6cbb21d:
1. **Invalidation helpers could mask successful mutations**
(cursor-bot, src/lib/response-cache.ts:717 +
src/lib/api/issues.ts:571).
`invalidateCachedResponsesMatching` called
`getIdentityFingerprint()` outside the `readdir` try/catch, so a
DB failure inside the fingerprint lookup could throw up through
callers. In `updateIssueStatus` (org-scoped path) the
`invalidateIssueCaches` call was also unguarded, and in
`mergeIssues` the per-ID invalidation sat inside the outer
try/catch meant to only handle 204s — either could turn a
successful mutation into a user-visible error.
Fix: push the guard into the helpers themselves. Every invalidation
helper now wraps its body in try/catch with an explicit
"Never throws" contract in the JSDoc. Callers no longer need to
remember; future call sites get the same safety automatically.
The existing caller-side try/catch in `createProject` /
`deleteProject` stays as defense-in-depth.
2. **`getIdentityFingerprint` skipped expired-token check vs
`getAuthConfig`** (cursor-bot, src/lib/db/auth.ts:325).
An expired access-only OAuth row (no refresh_token) is unusable —
`getAuthConfig` falls past it to the env token, and the API
client sends the env token on the next request. But the old
fingerprint still hashed the stale access token, bucketing cache
reads/writes under a dead identity while requests went under the
env identity. Result: stale cached data from a previous user
could leak to the env-token user.
Fix: mirror `getAuthConfig`'s expiry semantics. Skip the access
token when it has `expires_at` in the past and no refresh token;
fall through to the env-token / anonymous path. Added two tests
covering this and the access-token-rotation-with-refresh-token
stability case.1 parent 6cbb21d commit a7f1a05
6 files changed
Lines changed: 212 additions & 121 deletions
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
717 | 717 | | |
718 | 718 | | |
719 | 719 | | |
720 | | - | |
721 | | - | |
722 | | - | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
723 | 725 | | |
724 | 726 | | |
725 | 727 | | |
726 | 728 | | |
727 | 729 | | |
728 | 730 | | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | | - | |
737 | | - | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
738 | 744 | | |
739 | 745 | | |
740 | 746 | | |
| |||
746 | 752 | | |
747 | 753 | | |
748 | 754 | | |
| 755 | + | |
| 756 | + | |
749 | 757 | | |
750 | 758 | | |
751 | 759 | | |
752 | 760 | | |
753 | 761 | | |
754 | 762 | | |
755 | | - | |
756 | | - | |
757 | | - | |
758 | | - | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
759 | 771 | | |
760 | 772 | | |
761 | 773 | | |
| |||
764 | 776 | | |
765 | 777 | | |
766 | 778 | | |
| 779 | + | |
| 780 | + | |
767 | 781 | | |
768 | 782 | | |
769 | 783 | | |
770 | 784 | | |
771 | 785 | | |
772 | | - | |
773 | | - | |
774 | | - | |
775 | | - | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
776 | 794 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
269 | 275 | | |
270 | 276 | | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
276 | 286 | | |
277 | 287 | | |
278 | 288 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
312 | 319 | | |
313 | 320 | | |
314 | 321 | | |
315 | | - | |
| 322 | + | |
316 | 323 | | |
317 | | - | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
318 | 329 | | |
319 | 330 | | |
320 | 331 | | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
321 | 335 | | |
322 | 336 | | |
323 | | - | |
| 337 | + | |
324 | 338 | | |
325 | 339 | | |
326 | 340 | | |
327 | | - | |
| 341 | + | |
328 | 342 | | |
329 | 343 | | |
330 | 344 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
697 | 697 | | |
698 | 698 | | |
699 | 699 | | |
700 | | - | |
701 | | - | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
702 | 708 | | |
703 | | - | |
704 | | - | |
705 | | - | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
706 | 718 | | |
707 | 719 | | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | 720 | | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
716 | 725 | | |
717 | | - | |
| 726 | + | |
718 | 727 | | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
734 | 746 | | |
735 | | - | |
736 | | - | |
737 | | - | |
738 | | - | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
739 | 751 | | |
740 | 752 | | |
741 | 753 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
282 | 322 | | |
0 commit comments