fix: timeout hung stream fetches, backoff SSE reconnects, testable polling, UTC dates - #1139
Merged
ogazboiz merged 1 commit intoJul 30, 2026
Conversation
…llow test overrides, format dates in UTC - lib/api/streams.ts and lib/api/_shared.ts: add a shared fetchWithTimeout wrapper (AbortController-based, configurable) so a stalled backend surfaces a clear timeout error instead of hanging the UI forever. - hooks/useStreamEvents.ts: precompute the capped, doubled reconnect delay before scheduling the retry so exponential backoff keeps growing across consecutive SSE failures and resets on a successful connection. - hooks/useIncomingStreams.ts: accept an optional refetchInterval override so tests can disable/control polling instead of needing global timer mocks; default behavior (no polling) is unchanged. - lib/dashboard.ts: document and apply a consistent UTC date-formatting strategy via formatStreamDateUtc so a stream's displayed date/duration no longer depends on the viewer's local timezone. Also fixes two pre-existing, unrelated bugs in files these changes required touching, both of which were silently breaking tsc/lint/vitest for those files: a mismatched brace in dashboard.ts's fetchStreams try/catch, and useIncomingStreams.test.ts containing JSX under a .ts extension (renamed to .tsx). Neither changes behavior. Closes LabsCrypt#1040 Closes LabsCrypt#1041 Closes LabsCrypt#1042 Closes LabsCrypt#1043
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#1042 — lib/api/streams.ts has no timeout on its fetch calls
Added a shared
fetchWithTimeoutwrapper inlib/api/_shared.ts(AbortController-based, configurabletimeoutMs, default 10s) and switchedfetchIncomingStreamsto use it instead of a barefetch. A stalled backend now rejects with aFetchTimeoutErrorcarrying a clear message ("Request timed out after Xms") instead of leaving the query pending forever; this message already surfaces in the incoming-streams UI via the existingquery.error.messageerror path.#1041 — useStreamEvents.ts has no exponential backoff after repeated reconnect failures
Reworked the reconnect scheduling so the next (doubled, capped) delay is computed up front, before the retry timer is scheduled, so the backoff reliably grows across consecutive SSE failures instead of only doubling lazily inside the timeout callback. The delay still resets to its initial value on a successful connection.
#1040 — useIncomingStreams.ts refetch interval is hardcoded and cannot be disabled for tests
useIncomingStreamsnow accepts an optional secondoptionsargument withrefetchInterval. Default behavior is unchanged (no polling); tests (or future call sites) can now pass an explicit interval instead of needing to globally mock timers.#1043 — lib/dashboard.ts date formatting uses the browser's local timezone with no explicit UTC handling
Extracted the stream date formatting into a documented
formatStreamDateUtchelper with a comment explaining the strategy: always display in UTC so two viewers in different timezones see the same date for the same stream. The one date-formatting call site in this file now goes through it.Also fixes two small pre-existing bugs uncovered while touching these files (both silently broke
tsc/lint/vitest for the files involved, unrelated to the behavior above, no behavior change):dashboard.ts: a mismatched brace infetchStreams's try/catch block.useIncomingStreams.test.tscontained JSX but had a.tsextension; renamed to.tsx.Test plan
npx vitest run— all tests pass except one pre-existing, unrelated failure (useWithdrawIncomingStream > invalidates incomingStreamsQueryKey(publicKey) on success, which uses real timers against a slow exponential poll and was already broken before this PR, just previously masked by the.ts/.tsxtransform bug above)npx eslintclean on all changed filesstreams.test.ts, growing/capped/reset backoff delay inuseStreamEvents.test.tsx, default vs. overriddenrefetchIntervalinuseIncomingStreams.test.tsx, UTC date stability indashboard.test.tsCloses #1040
Closes #1041
Closes #1042
Closes #1043