diff --git a/src/analytics/metrics/types.ts b/src/analytics/metrics/types.ts index 6994698ad..794908e50 100644 --- a/src/analytics/metrics/types.ts +++ b/src/analytics/metrics/types.ts @@ -36,6 +36,9 @@ export type Events = { errorName?: string status?: number } + 'appviewFallback:outage': { + active: boolean + } 'account:loggedIn': { logContext: diff --git a/src/components/HomeAppviewOutageNotice.tsx b/src/components/HomeAppviewOutageNotice.tsx new file mode 100644 index 000000000..53cb7ff45 --- /dev/null +++ b/src/components/HomeAppviewOutageNotice.tsx @@ -0,0 +1,34 @@ +import {View} from 'react-native' +import {Trans} from '@lingui/react/macro' + +import {useHomeAppviewOutage} from '#/state/appview-health' +import {atoms as a, useTheme} from '#/alf' +import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo' +import {Text} from '#/components/Typography' + +export function HomeAppviewOutageNotice() { + const t = useTheme() + const outage = useHomeAppviewOutage() + + if (!outage) return null + + return ( + + + + + Community features are temporarily unavailable. We're working on it — + the rest of the app still works. + + + + ) +} diff --git a/src/locale/locales/en/messages.po b/src/locale/locales/en/messages.po index cf2b9be06..eafbefb4a 100644 --- a/src/locale/locales/en/messages.po +++ b/src/locale/locales/en/messages.po @@ -195,7 +195,7 @@ msgid "{0} added to chat" msgstr "{0} added to chat" #. placeholder {0}: brand.messages.postButtonLabel -#: src/view/com/composer/Composer.tsx:1843 +#: src/view/com/composer/Composer.tsx:1844 msgctxt "action" msgid "{0} All" msgstr "{0} All" @@ -1167,11 +1167,11 @@ msgstr "" msgid "Add another account" msgstr "" -#: src/view/com/composer/Composer.tsx:1556 +#: src/view/com/composer/Composer.tsx:1557 msgid "Add another post" msgstr "" -#: src/view/com/composer/Composer.tsx:2251 +#: src/view/com/composer/Composer.tsx:2257 msgid "Add another post to thread" msgstr "" @@ -1855,7 +1855,7 @@ msgstr "" msgid "Are you sure you want to rescind your request to join {0}?" msgstr "Are you sure you want to rescind your request to join {0}?" -#: src/view/com/composer/Composer.tsx:1692 +#: src/view/com/composer/Composer.tsx:1693 msgid "Are you sure you'd like to discard this post?" msgstr "" @@ -2025,11 +2025,15 @@ msgid "Blacksky needs camera access to scan QR codes from other profiles." msgstr "Blacksky needs camera access to scan QR codes from other profiles." #: src/components/CommunityOnlyBadge.tsx:57 -#: src/view/com/composer/Composer.tsx:2040 -#: src/view/com/composer/Composer.tsx:2050 +#: src/view/com/composer/Composer.tsx:2042 +#: src/view/com/composer/Composer.tsx:2055 msgid "Blacksky Only" msgstr "Blacksky Only" +#: src/view/com/composer/Composer.tsx:2053 +msgid "Blacksky Only (temporarily unavailable)" +msgstr "Blacksky Only (temporarily unavailable)" + #: src/components/StarterPack/ProfileStarterPacks.tsx:340 msgid "Blacksky will choose a set of recommended accounts from people in your network." msgstr "Blacksky will choose a set of recommended accounts from people in your network." @@ -2346,8 +2350,8 @@ msgstr "Camera access needed" #: src/screens/Settings/Settings.tsx:302 #: src/screens/Takendown.tsx:104 #: src/screens/Takendown.tsx:107 -#: src/view/com/composer/Composer.tsx:1771 -#: src/view/com/composer/Composer.tsx:1781 +#: src/view/com/composer/Composer.tsx:1772 +#: src/view/com/composer/Composer.tsx:1782 #: src/view/com/composer/photos/EditImageDialog.web.tsx:44 #: src/view/com/composer/photos/EditImageDialog.web.tsx:53 #: src/view/shell/desktop/LeftNav.tsx:232 @@ -2820,7 +2824,7 @@ msgstr "" msgid "Closes password update alert" msgstr "" -#: src/view/com/composer/Composer.tsx:1779 +#: src/view/com/composer/Composer.tsx:1780 msgid "Closes post composer and discards post draft" msgstr "" @@ -2863,6 +2867,10 @@ msgstr "Community" msgid "Community Builder" msgstr "Community Builder" +#: src/components/HomeAppviewOutageNotice.tsx:27 +msgid "Community features are temporarily unavailable. We're working on it — the rest of the app still works." +msgstr "Community features are temporarily unavailable. We're working on it — the rest of the app still works." + #: src/Navigation.tsx:365 #: src/view/screens/CommunityGuidelines.tsx:28 msgid "Community Guidelines" @@ -2883,7 +2891,7 @@ msgid "Compose new post" msgstr "" #. placeholder {0}: MAX_GRAPHEME_LENGTH || 0 -#: src/view/com/composer/Composer.tsx:1654 +#: src/view/com/composer/Composer.tsx:1655 msgid "Compose posts up to {0, plural, other {# characters}} in length" msgstr "" @@ -2891,11 +2899,11 @@ msgstr "" msgid "Compose reply" msgstr "" -#: src/view/com/composer/Composer.tsx:2648 +#: src/view/com/composer/Composer.tsx:2654 msgid "Compressing GIF..." msgstr "" -#: src/view/com/composer/Composer.tsx:2650 +#: src/view/com/composer/Composer.tsx:2656 msgid "Compressing video..." msgstr "" @@ -3613,7 +3621,7 @@ msgstr "" #: src/components/PostControls/PostMenu/PostMenuItems.tsx:767 #: src/components/PostControls/PostMenu/PostMenuItems.tsx:769 -#: src/view/com/composer/Composer.tsx:1666 +#: src/view/com/composer/Composer.tsx:1667 msgid "Delete post" msgstr "" @@ -3772,9 +3780,9 @@ msgstr "" #: src/components/dialogs/lists/CreateOrEditListDialog.tsx:101 #: src/screens/Profile/Header/EditProfileDialog.tsx:82 -#: src/view/com/composer/Composer.tsx:1448 -#: src/view/com/composer/Composer.tsx:1492 -#: src/view/com/composer/Composer.tsx:1699 +#: src/view/com/composer/Composer.tsx:1449 +#: src/view/com/composer/Composer.tsx:1493 +#: src/view/com/composer/Composer.tsx:1700 #: src/view/com/composer/drafts/DraftItem.tsx:242 #: src/view/com/composer/drafts/DraftsButton.tsx:131 msgid "Discard" @@ -3785,14 +3793,14 @@ msgstr "" msgid "Discard changes?" msgstr "" -#: src/view/com/composer/Composer.tsx:1446 +#: src/view/com/composer/Composer.tsx:1447 #: src/view/com/composer/drafts/DraftItem.tsx:239 #: src/view/com/composer/drafts/DraftsButton.tsx:98 msgid "Discard draft?" msgstr "" -#: src/view/com/composer/Composer.tsx:1463 -#: src/view/com/composer/Composer.tsx:1691 +#: src/view/com/composer/Composer.tsx:1464 +#: src/view/com/composer/Composer.tsx:1692 msgid "Discard post?" msgstr "" @@ -3832,7 +3840,7 @@ msgstr "" msgid "Dismiss banner" msgstr "" -#: src/view/com/composer/Composer.tsx:2569 +#: src/view/com/composer/Composer.tsx:2575 msgid "Dismiss error" msgstr "" @@ -4303,7 +4311,7 @@ msgstr "" #: src/screens/Profile/Sections/CommunityFeed.tsx:156 #: src/screens/Profile/Sections/Feed.tsx:131 -#: src/view/com/feeds/CommunityFeedPage.tsx:231 +#: src/view/com/feeds/CommunityFeedPage.tsx:232 msgid "End of feed" msgstr "" @@ -4381,7 +4389,7 @@ msgstr "" msgid "Entertainment" msgstr "" -#: src/view/com/composer/Composer.tsx:2668 +#: src/view/com/composer/Composer.tsx:2674 #: src/view/com/util/error/ErrorScreen.tsx:40 msgid "Error" msgstr "" @@ -4706,7 +4714,7 @@ msgstr "Failed to leave group chat" #: src/components/CommunityFeed.tsx:39 #: src/screens/Profile/Sections/CommunityFeed.tsx:123 -#: src/view/com/feeds/CommunityFeedPage.tsx:199 +#: src/view/com/feeds/CommunityFeedPage.tsx:200 msgid "Failed to load community posts" msgstr "Failed to load community posts" @@ -4795,7 +4803,7 @@ msgstr "" msgid "Failed to rescind your request. Please try again." msgstr "Failed to rescind your request. Please try again." -#: src/view/com/composer/Composer.tsx:670 +#: src/view/com/composer/Composer.tsx:671 msgid "Failed to save draft" msgstr "" @@ -5422,7 +5430,7 @@ msgstr "" msgid "GIF" msgstr "" -#: src/view/com/composer/Composer.tsx:2673 +#: src/view/com/composer/Composer.tsx:2679 msgid "GIF uploaded" msgstr "" @@ -6293,7 +6301,7 @@ msgid "It's just you right now! Add more people to your starter pack by searchin msgstr "" #. placeholder {0}: videoState.jobId -#: src/view/com/composer/Composer.tsx:2588 +#: src/view/com/composer/Composer.tsx:2594 msgid "Job ID: {0}" msgstr "" @@ -6323,8 +6331,8 @@ msgstr "Join request rescinded." msgid "Journalism" msgstr "" -#: src/view/com/composer/Composer.tsx:1496 -#: src/view/com/composer/Composer.tsx:1506 +#: src/view/com/composer/Composer.tsx:1497 +#: src/view/com/composer/Composer.tsx:1507 #: src/view/com/composer/drafts/DraftsButton.tsx:135 msgid "Keep editing" msgstr "" @@ -6760,7 +6768,7 @@ msgstr "" #: src/screens/Profile/ProfileFeed/index.tsx:206 #: src/screens/Profile/Sections/Feed.tsx:117 #: src/screens/ProfileList/FeedSection.tsx:113 -#: src/view/com/feeds/CommunityFeedPage.tsx:262 +#: src/view/com/feeds/CommunityFeedPage.tsx:264 #: src/view/com/feeds/FeedPage.tsx:168 msgid "Load new posts" msgstr "" @@ -7428,7 +7436,7 @@ msgstr "" #: src/screens/Profile/ProfileFeed/index.tsx:217 #: src/screens/ProfileList/index.tsx:237 #: src/screens/ProfileList/index.tsx:280 -#: src/view/com/feeds/CommunityFeedPage.tsx:272 +#: src/view/com/feeds/CommunityFeedPage.tsx:274 #: src/view/screens/Feeds.tsx:545 #: src/view/screens/Notifications.tsx:165 #: src/view/screens/Profile.tsx:643 @@ -7507,7 +7515,7 @@ msgstr "" #: src/components/CommunityFeed.tsx:51 #: src/screens/Profile/Sections/CommunityFeed.tsx:133 -#: src/view/com/feeds/CommunityFeedPage.tsx:207 +#: src/view/com/feeds/CommunityFeedPage.tsx:208 msgid "No community posts yet" msgstr "No community posts yet" @@ -7869,11 +7877,11 @@ msgstr "One of the selected recipients does not allow group chats." msgid "One of the selected recipients has blocked you and cannot be messaged." msgstr "One of the selected recipients has blocked you and cannot be messaged." -#: src/view/com/composer/Composer.tsx:886 +#: src/view/com/composer/Composer.tsx:887 msgid "One or more GIFs is missing alt text." msgstr "" -#: src/view/com/composer/Composer.tsx:883 +#: src/view/com/composer/Composer.tsx:884 msgid "One or more images is missing alt text." msgstr "" @@ -7885,11 +7893,11 @@ msgstr "" msgid "One or more of your selected files are too large. Maximum size is {VIDEO_MAX_SIZE_MB} MB." msgstr "One or more of your selected files are too large. Maximum size is {VIDEO_MAX_SIZE_MB} MB." -#: src/view/com/composer/Composer.tsx:681 +#: src/view/com/composer/Composer.tsx:682 msgid "One or more posts are too long to save as a draft. {MAX_DRAFT_GRAPHEME_LENGTH, plural, one {The maximum number of characters is # character.} other {The maximum number of characters is # characters.}}" msgstr "" -#: src/view/com/composer/Composer.tsx:893 +#: src/view/com/composer/Composer.tsx:894 msgid "One or more videos is missing alt text." msgstr "" @@ -7907,7 +7915,7 @@ msgstr "" #. placeholder {0}: result.accepted.length #. placeholder {1}: next.length #. placeholder {2}: next.length -#: src/view/com/composer/Composer.tsx:241 +#: src/view/com/composer/Composer.tsx:242 msgid "Only {0} of {1} {2, plural, one {image} other {images}} added; limit is {MAX_GALLERY_IMAGES}" msgstr "Only {0} of {1} {2, plural, one {image} other {images}} added; limit is {MAX_GALLERY_IMAGES}" @@ -8000,7 +8008,7 @@ msgstr "" #: src/screens/Messages/components/MessageComposer.tsx:204 #: src/screens/Messages/components/MessageInput.web.tsx:174 -#: src/view/com/composer/Composer.tsx:2228 +#: src/view/com/composer/Composer.tsx:2234 msgid "Open emoji picker" msgstr "" @@ -8711,7 +8719,7 @@ msgstr "" msgid "Post a video" msgstr "" -#: src/view/com/composer/Composer.tsx:1505 +#: src/view/com/composer/Composer.tsx:1506 msgid "Post anyway" msgstr "Post anyway" @@ -8888,11 +8896,11 @@ msgstr "" msgid "Privacy violation of a minor" msgstr "" -#: src/view/com/composer/Composer.tsx:2662 +#: src/view/com/composer/Composer.tsx:2668 msgid "Processing GIF..." msgstr "" -#: src/view/com/composer/Composer.tsx:2664 +#: src/view/com/composer/Composer.tsx:2670 msgid "Processing video..." msgstr "" @@ -8946,22 +8954,22 @@ msgid "Public, sharable lists of users to mute or block in bulk." msgstr "" #. Accessibility label for button to publish a single post -#: src/view/com/composer/Composer.tsx:1829 +#: src/view/com/composer/Composer.tsx:1830 msgid "Publish post" msgstr "" #. Accessibility label for button to publish multiple posts in a thread -#: src/view/com/composer/Composer.tsx:1824 +#: src/view/com/composer/Composer.tsx:1825 msgid "Publish posts" msgstr "" #. Accessibility label for button to publish multiple replies in a thread -#: src/view/com/composer/Composer.tsx:1813 +#: src/view/com/composer/Composer.tsx:1814 msgid "Publish replies" msgstr "" #. Accessibility label for button to publish a single reply -#: src/view/com/composer/Composer.tsx:1818 +#: src/view/com/composer/Composer.tsx:1819 msgid "Publish reply" msgstr "" @@ -9438,7 +9446,7 @@ msgstr "" msgid "Reply" msgstr "Reply" -#: src/view/com/composer/Composer.tsx:1841 +#: src/view/com/composer/Composer.tsx:1842 msgctxt "action" msgid "Reply" msgstr "" @@ -9841,22 +9849,22 @@ msgstr "Save birthdate" #: src/screens/SavedFeeds.tsx:126 #: src/screens/SavedFeeds.tsx:314 #: src/screens/SavedFeeds.tsx:318 -#: src/view/com/composer/Composer.tsx:1486 +#: src/view/com/composer/Composer.tsx:1487 #: src/view/com/composer/drafts/DraftsButton.tsx:125 msgid "Save changes" msgstr "" -#: src/view/com/composer/Composer.tsx:1458 +#: src/view/com/composer/Composer.tsx:1459 #: src/view/com/composer/drafts/DraftsButton.tsx:93 msgid "Save changes?" msgstr "" -#: src/view/com/composer/Composer.tsx:1486 +#: src/view/com/composer/Composer.tsx:1487 #: src/view/com/composer/drafts/DraftsButton.tsx:125 msgid "Save draft" msgstr "" -#: src/view/com/composer/Composer.tsx:1460 +#: src/view/com/composer/Composer.tsx:1461 #: src/view/com/composer/drafts/DraftsButton.tsx:95 msgid "Save draft?" msgstr "" @@ -10802,7 +10810,7 @@ msgstr "" msgid "Skip contact sharing and continue to the app" msgstr "" -#: src/view/com/composer/Composer.tsx:1503 +#: src/view/com/composer/Composer.tsx:1504 msgid "Skip empty posts?" msgstr "Skip empty posts?" @@ -11987,7 +11995,7 @@ msgstr "" msgid "This post will be hidden from feeds and threads. This cannot be undone." msgstr "" -#: src/view/com/composer/Composer.tsx:1065 +#: src/view/com/composer/Composer.tsx:1066 msgid "This post's author has disabled quote posts." msgstr "" @@ -12556,7 +12564,7 @@ msgstr "" msgid "Unsupported clipboard content" msgstr "Unsupported clipboard content" -#: src/view/com/composer/Composer.tsx:1593 +#: src/view/com/composer/Composer.tsx:1594 msgid "Unsupported video type: {mimeType}" msgstr "" @@ -12641,7 +12649,7 @@ msgstr "" msgid "Upload from Library" msgstr "" -#: src/view/com/composer/Composer.tsx:2655 +#: src/view/com/composer/Composer.tsx:2661 msgid "Uploading GIF..." msgstr "" @@ -12655,7 +12663,7 @@ msgstr "" msgid "Uploading link thumbnail..." msgstr "" -#: src/view/com/composer/Composer.tsx:2657 +#: src/view/com/composer/Composer.tsx:2663 msgid "Uploading video..." msgstr "" @@ -12917,7 +12925,7 @@ msgstr "" msgid "Video settings" msgstr "" -#: src/view/com/composer/Composer.tsx:2675 +#: src/view/com/composer/Composer.tsx:2681 msgid "Video uploaded" msgstr "" @@ -12934,7 +12942,7 @@ msgstr "" msgid "Videos must be less than 3 minutes long." msgstr "" -#: src/view/com/composer/Composer.tsx:1183 +#: src/view/com/composer/Composer.tsx:1184 msgctxt "Action to view the post the user just created" msgid "View" msgstr "" @@ -13019,7 +13027,7 @@ msgstr "" msgid "View more trending videos" msgstr "" -#: src/view/com/composer/Composer.tsx:1167 +#: src/view/com/composer/Composer.tsx:1168 msgid "View post" msgstr "" @@ -13273,7 +13281,7 @@ msgstr "" msgid "We’re sorry, but your search could not be completed. Please try again in a few minutes." msgstr "We’re sorry, but your search could not be completed. Please try again in a few minutes." -#: src/view/com/composer/Composer.tsx:1063 +#: src/view/com/composer/Composer.tsx:1064 msgid "We're sorry! The post you are replying to has been deleted." msgstr "" @@ -13375,7 +13383,7 @@ msgstr "Would you like to block this user and/or leave this conversation?" msgid "Would you like to save this as a draft before viewing your drafts?" msgstr "" -#: src/view/com/composer/Composer.tsx:1474 +#: src/view/com/composer/Composer.tsx:1475 msgid "Would you like to save this as a draft to edit later?" msgstr "" @@ -13384,12 +13392,12 @@ msgstr "" msgid "Write a post" msgstr "" -#: src/view/com/composer/Composer.tsx:1653 +#: src/view/com/composer/Composer.tsx:1654 msgid "Write post" msgstr "" #: src/screens/PostThread/components/ThreadComposePrompt.tsx:91 -#: src/view/com/composer/Composer.tsx:1555 +#: src/view/com/composer/Composer.tsx:1556 msgid "Write your reply" msgstr "" @@ -13544,11 +13552,11 @@ msgid "You can now sign in with your new password." msgstr "" #. Toast shown when the user tries to add more images but the post gallery is already at the cap -#: src/view/com/composer/Composer.tsx:228 +#: src/view/com/composer/Composer.tsx:229 msgid "You can only add up to {MAX_GALLERY_IMAGES, plural, other {# images}} per post" msgstr "You can only add up to {MAX_GALLERY_IMAGES, plural, other {# images}} per post" -#: src/view/com/composer/Composer.tsx:1479 +#: src/view/com/composer/Composer.tsx:1480 msgid "You can only save drafts up to 1000 characters." msgstr "" @@ -13685,7 +13693,7 @@ msgstr "" msgid "You have temporarily reached the limit for video uploads. Please try again later." msgstr "" -#: src/view/com/composer/Composer.tsx:1469 +#: src/view/com/composer/Composer.tsx:1470 msgid "You have unsaved changes to this draft, would you like to save them?" msgstr "" @@ -13901,7 +13909,7 @@ msgstr "" msgid "You've reached the end of your feed! Find some more accounts to follow." msgstr "" -#: src/view/com/composer/Composer.tsx:668 +#: src/view/com/composer/Composer.tsx:669 msgid "You've reached the maximum number of drafts" msgstr "" @@ -14078,11 +14086,11 @@ msgstr "" msgid "Your payment is still being processed. Please check back later." msgstr "Your payment is still being processed. Please check back later." -#: src/view/com/composer/Composer.tsx:1163 +#: src/view/com/composer/Composer.tsx:1164 msgid "Your post was sent" msgstr "" -#: src/view/com/composer/Composer.tsx:1160 +#: src/view/com/composer/Composer.tsx:1161 msgid "Your posts were sent" msgstr "" @@ -14100,7 +14108,7 @@ msgstr "" msgid "Your profile, posts, feeds, and lists will no longer be visible to other {0} users. You can reactivate your account at any time by logging in." msgstr "Your profile, posts, feeds, and lists will no longer be visible to other {0} users. You can reactivate your account at any time by logging in." -#: src/view/com/composer/Composer.tsx:1162 +#: src/view/com/composer/Composer.tsx:1163 msgid "Your reply was sent" msgstr "" @@ -14121,7 +14129,7 @@ msgstr "Your session has expired. Please sign in again." msgid "Your support helps us maintain and improve the Blacksky community." msgstr "Your support helps us maintain and improve the Blacksky community." -#: src/view/com/composer/Composer.tsx:1504 +#: src/view/com/composer/Composer.tsx:1505 msgid "Your thread has empty posts that will be skipped. The remaining posts will be published as a thread." msgstr "Your thread has empty posts that will be skipped. The remaining posts will be published as a thread." diff --git a/src/state/__tests__/appview-health.test.ts b/src/state/__tests__/appview-health.test.ts new file mode 100644 index 000000000..d43f72bb4 --- /dev/null +++ b/src/state/__tests__/appview-health.test.ts @@ -0,0 +1,64 @@ +import {BLUESKY_FALLBACK_PROXY_HEADER, HOME_PROXY_HEADER} from '#/lib/constants' +import { + isHomeAppviewOutage, + reportProxiedFetch, + resetForTesting, +} from '../appview-health' + +jest.mock('#/analytics/metrics', () => ({ + metrics: {track: jest.fn()}, +})) + +const HOME = {headers: {'atproto-proxy': HOME_PROXY_HEADER}} +const FALLBACK = {headers: {'atproto-proxy': BLUESKY_FALLBACK_PROXY_HEADER}} + +function fail(init: RequestInit, times: number, status: number | null = 503) { + for (let i = 0; i < times; i++) reportProxiedFetch(init, status) +} + +describe('home appview circuit breaker', () => { + beforeEach(() => { + resetForTesting() + }) + + it('trips after 8 consecutive home-bound failures', () => { + fail(HOME, 7) + expect(isHomeAppviewOutage()).toBe(false) + fail(HOME, 1) + expect(isHomeAppviewOutage()).toBe(true) + }) + + it('network errors (null status) count as failures', () => { + fail(HOME, 8, null) + expect(isHomeAppviewOutage()).toBe(true) + }) + + it('4xx responses mean the appview answered — no trip', () => { + fail(HOME, 20, 400) + expect(isHomeAppviewOutage()).toBe(false) + }) + + it('a success resets the streak and clears an active outage', () => { + fail(HOME, 7) + reportProxiedFetch(HOME, 200) + fail(HOME, 7) + expect(isHomeAppviewOutage()).toBe(false) + + fail(HOME, 8) + expect(isHomeAppviewOutage()).toBe(true) + reportProxiedFetch(HOME, 200) + expect(isHomeAppviewOutage()).toBe(false) + }) + + it('ignores fallback-bound and unproxied requests', () => { + fail(FALLBACK, 20) + fail({}, 20) + expect(isHomeAppviewOutage()).toBe(false) + }) + + it('reads the header from Headers instances too', () => { + const headers = new Headers({'atproto-proxy': HOME_PROXY_HEADER}) + fail({headers}, 8) + expect(isHomeAppviewOutage()).toBe(true) + }) +}) diff --git a/src/state/appview-fallback-controller.tsx b/src/state/appview-fallback-controller.tsx index c226d85e5..2c5ec73c7 100644 --- a/src/state/appview-fallback-controller.tsx +++ b/src/state/appview-fallback-controller.tsx @@ -4,6 +4,10 @@ import {useQueryClient} from '@tanstack/react-query' import {type FallbackMode, setFallbackActive} from '#/state/appview-fallback' import {probeFallbackEligibility} from '#/state/appview-fallback-probe' +import { + isHomeAppviewOutage, + subscribe as subscribeOutage, +} from '#/state/appview-health' import { decide, type DeciderState, @@ -43,6 +47,8 @@ export function AppviewFallbackController() { let wantsFallback: boolean if (mode === 'force-fallback') { wantsFallback = true + } else if (isHomeAppviewOutage()) { + wantsFallback = true } else { const sample = await fetchStatusSample() deciderRef.current = decide(deciderRef.current, sample, getThresholds()) @@ -65,9 +71,11 @@ export function AppviewFallbackController() { const sub = AppState.addEventListener('change', state => { if (state === 'active') void evaluate() }) + const unsubOutage = subscribeOutage(() => void evaluate()) return () => { clearInterval(interval) sub.remove() + unsubOutage() } }, [evaluate]) diff --git a/src/state/appview-health.ts b/src/state/appview-health.ts new file mode 100644 index 000000000..f575e3f1c --- /dev/null +++ b/src/state/appview-health.ts @@ -0,0 +1,85 @@ +import {useSyncExternalStore} from 'react' + +import {HOME_PROXY_HEADER} from '#/lib/constants' +import {logger} from '#/logger' +import {metrics} from '#/analytics/metrics' + +const OUTAGE_CONSECUTIVE_FAILURES = 8 + +let consecutiveFailures = 0 +let outage = false +const listeners = new Set<() => void>() + +export function isHomeAppviewOutage(): boolean { + return outage +} + +export function subscribe(fn: () => void): () => void { + listeners.add(fn) + return () => { + listeners.delete(fn) + } +} + +export function useHomeAppviewOutage(): boolean { + return useSyncExternalStore( + subscribe, + isHomeAppviewOutage, + isHomeAppviewOutage, + ) +} + +function getProxyHeader(init: RequestInit | undefined): string | null { + if (!init?.headers) return null + if (init.headers instanceof Headers) { + return init.headers.get('atproto-proxy') + } + if (Array.isArray(init.headers)) { + const entry = init.headers.find( + ([k]) => k.toLowerCase() === 'atproto-proxy', + ) + return entry?.[1] ?? null + } + const record = init.headers + return record['atproto-proxy'] ?? record['Atproto-Proxy'] ?? null +} + +/** + * Circuit breaker over home-appview-bound requests. Only 5xx and network + * failures count — 4xx means the appview answered. Only requests whose + * proxy header targets the home appview are relevant; during fallback, + * pinned calls (community, notifications) keep feeding this, and the + * 30-second notifications unread poll gives it a steady heartbeat. + */ +export function reportProxiedFetch( + init: RequestInit | undefined, + status: number | null, +): void { + if (getProxyHeader(init) !== HOME_PROXY_HEADER) return + + const failed = status === null || status >= 500 + if (!failed) { + consecutiveFailures = 0 + setOutage(false) + return + } + + consecutiveFailures++ + if (consecutiveFailures >= OUTAGE_CONSECUTIVE_FAILURES) { + setOutage(true) + } +} + +function setOutage(next: boolean): void { + if (next === outage) return + outage = next + logger.info('home appview outage state changed', {outage: next}) + metrics.track('appviewFallback:outage', {active: next}) + listeners.forEach(fn => fn()) +} + +export function resetForTesting(): void { + consecutiveFailures = 0 + outage = false + listeners.clear() +} diff --git a/src/state/session/agent.ts b/src/state/session/agent.ts index 17c36892b..f21750f8b 100644 --- a/src/state/session/agent.ts +++ b/src/state/session/agent.ts @@ -30,6 +30,7 @@ import { } from '#/lib/constants' import {getAge} from '#/lib/strings/time' import {logger} from '#/logger' +import {reportProxiedFetch} from '#/state/appview-health' import {snoozeEmailConfirmationPrompt} from '#/state/shell/reminders' import {features} from '#/analytics' import {emitNetworkConfirmed, emitNetworkLost} from '../events' @@ -500,9 +501,11 @@ class BskyAppAgent extends BskyAgent { try { const result = await realFetch(input, init) success = true + reportProxiedFetch(init, result.status) return result } catch (e) { success = false + reportProxiedFetch(init, null) throw e } finally { if (success) { diff --git a/src/state/session/oauth-agent.ts b/src/state/session/oauth-agent.ts index 0bbb2f854..3b0ddeb6c 100644 --- a/src/state/session/oauth-agent.ts +++ b/src/state/session/oauth-agent.ts @@ -8,6 +8,7 @@ import {type OAuthSession} from '@atproto/oauth-client' import {BLUESKY_PROXY_HEADER, BSKY_SERVICE} from '#/lib/constants' import {logger} from '#/logger' +import {reportProxiedFetch} from '#/state/appview-health' import { sessionAccountToSession, stripAppviewProxyForPdsLocalMethods, @@ -128,9 +129,16 @@ export class OauthBskyAppAgent extends Agent { return session.did }, fetchHandler(url, init) { - return session.fetchHandler( - url, - stripAppviewProxyForPdsLocalMethods(url, init) ?? init, + const finalInit = stripAppviewProxyForPdsLocalMethods(url, init) ?? init + return session.fetchHandler(url, finalInit).then( + res => { + reportProxiedFetch(finalInit, res.status) + return res + }, + err => { + reportProxiedFetch(finalInit, null) + throw err + }, ) }, }) diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index 67b9df53e..e83db8211 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -80,6 +80,7 @@ import {type NavigationProp} from '#/lib/routes/types' import {cleanError} from '#/lib/strings/errors' import {colors} from '#/lib/styles' import {logger} from '#/logger' +import {useHomeAppviewOutage} from '#/state/appview-health' import {useDialogStateControlContext} from '#/state/dialogs' import {emitPostCreated} from '#/state/events' import { @@ -1996,6 +1997,7 @@ function ComposerPills({ const t = useTheme() const {t: l} = useLingui() const {data: isCommunityMember = false} = useCommunityMembership() + const homeAppviewOutage = useHomeAppviewOutage() const media = post.embed.media const hasMedia = media?.type === 'images' || @@ -2039,7 +2041,7 @@ function ComposerPills({ name="blacksky_only" label={l`Blacksky Only`} value={thread.blackskyOnly} - disabled={isForcedBlackskyOnly} + disabled={isForcedBlackskyOnly || homeAppviewOutage} onChange={() => { const next = !thread.blackskyOnly dispatch({type: 'toggle_blacksky_only'}) @@ -2047,7 +2049,11 @@ function ComposerPills({ }} style={[a.flex_row, a.align_center, a.gap_xs]}> - Blacksky Only + {homeAppviewOutage ? ( + Blacksky Only (temporarily unavailable) + ) : ( + Blacksky Only + )} diff --git a/src/view/com/feeds/CommunityFeedPage.tsx b/src/view/com/feeds/CommunityFeedPage.tsx index d1713e2cf..6d2207cd6 100644 --- a/src/view/com/feeds/CommunityFeedPage.tsx +++ b/src/view/com/feeds/CommunityFeedPage.tsx @@ -20,6 +20,7 @@ import {List, type ListMethods} from '#/view/com/util/List' import {LoadLatestBtn} from '#/view/com/util/load-latest/LoadLatestBtn' import {MainScrollProvider} from '#/view/com/util/MainScrollProvider' import {atoms as a, useTheme} from '#/alf' +import {HomeAppviewOutageNotice} from '#/components/HomeAppviewOutageNotice' import {useHeaderOffset} from '#/components/hooks/useHeaderOffset' import {EditBig_Stroke2_Corner2_Rounded as EditBigIcon} from '#/components/icons/EditBig' import {Text} from '#/components/Typography' @@ -245,6 +246,7 @@ export function CommunityFeedPage({isPageFocused}: {isPageFocused: boolean}) { data={rows} renderItem={renderItem} keyExtractor={keyExtractor} + ListHeaderComponent={HomeAppviewOutageNotice} ListEmptyComponent={renderEmpty} ListFooterComponent={renderFooter} onEndReached={onEndReached}