Commit 08d3c7c
🐛 fix(usage): clear in-flight lock on a successful fetch (#487)
* fix(usage): drop in-flight lock on fetch success
The pre-fetch usage.lock is written as a 'timeout' guard before the API
call but is never removed on success, so it lingers for LOCK_MAX_AGE. A
cache miss in that window (e.g. an account switch invalidating the token
fingerprint) then returns getStaleUsageOrError('timeout', ...), showing a
spurious [Timeout] while the API is healthy.
Clear the lock after a successful cache write. Genuine error and
rate-limit backoff locks are untouched.
Fixes #486
* fix(usage): preserve throttle for incomplete usage fetches
Only clear the in-flight usage lock after a successful API response satisfies the fields requested by the caller. Aggregate-only responses that are missing per-model fields remain cached, but keep the short timeout lock so later renders do not refetch the API on every status line render.
Add regression coverage for a weekly Sonnet usage request receiving an aggregate-only 200 response, verifying that the second fetch is throttled instead of issuing another API request.
---------
Co-authored-by: Matthew Breedlove <sirmalloc@gmail.com>1 parent 6793c75 commit 08d3c7c
2 files changed
Lines changed: 96 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
674 | 674 | | |
675 | 675 | | |
676 | 676 | | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
677 | 683 | | |
678 | 684 | | |
679 | 685 | | |
680 | 686 | | |
681 | | - | |
| 687 | + | |
682 | 688 | | |
683 | 689 | | |
684 | 690 | | |
| |||
691 | 697 | | |
692 | 698 | | |
693 | 699 | | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
694 | 760 | | |
695 | 761 | | |
696 | 762 | | |
| |||
849 | 915 | | |
850 | 916 | | |
851 | 917 | | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
852 | 924 | | |
853 | 925 | | |
854 | 926 | | |
855 | 927 | | |
856 | | - | |
| 928 | + | |
857 | 929 | | |
858 | 930 | | |
859 | 931 | | |
| |||
895 | 967 | | |
896 | 968 | | |
897 | 969 | | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
898 | 976 | | |
899 | 977 | | |
900 | 978 | | |
901 | 979 | | |
902 | | - | |
| 980 | + | |
903 | 981 | | |
904 | 982 | | |
905 | 983 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
431 | 439 | | |
432 | 440 | | |
433 | 441 | | |
| |||
664 | 672 | | |
665 | 673 | | |
666 | 674 | | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
667 | 682 | | |
668 | 683 | | |
669 | 684 | | |
| |||
0 commit comments