Conversation
The live duration calculator worked for SSE-arrived requests (where durationMs is undefined) but showed ∅ on page refresh because the backend REST API coerced null→0 via ?? 0, and the frontend's != null check treated 0 as a valid duration. - Backend: stop coercing durationMs null→0 in REST API response - Frontend: change durationMs type to number | null to reflect reality - Frontend: use != null && > 0 guard so both null and 0 fall through to the live Date.now() - startTime calculation - Frontend: add null guards in useModels/useProviderForm reduce calls
micookie2
pushed a commit
to micookie2/plexus
that referenced
this pull request
May 21, 2026
…sh (mcowger#434) ## Problem The live duration calculator in the Logs page showed **Duration: ∅** for in-flight requests after a page refresh, even though it worked correctly for requests arriving via the SSE event stream. ## Root Cause Two issues compounded: 1. **Backend**: The REST API response coerced `durationMs: null` → `0` via `?? 0` in `usage-storage.ts`. The DB correctly stores `null` for pending requests, but the API response lost that signal. 2. **Frontend**: The live duration check used `log.durationMs != null` to decide whether to use the stored value or compute live. When `durationMs` was `0` (from the backend coercion), `0 != null` is `true`, so `formatMs(0)` was called — which returns `'∅'`. This only manifested on page refresh (REST API path). For SSE-arrived requests, `durationMs` was `undefined` (not in the partial record), so `!= null` correctly fell through to the live calculation. ## Changes - **Backend** (`usage-storage.ts`): Stop coercing `durationMs` null→0 in REST API response; let `null` flow through - **Frontend** (`api.ts`): Change `durationMs` type from `number` to `number | null` to reflect reality - **Frontend** (`Logs.tsx`): Use `!= null && > 0` guard so both `null` and `0` fall through to `Date.now() - startTime` - **Frontend** (`useModels.ts`, `useProviderForm.tsx`): Add null guards on `reduce` calls for the new nullable type
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.
Problem
The live duration calculator in the Logs page showed Duration: ∅ for in-flight requests after a page refresh, even though it worked correctly for requests arriving via the SSE event stream.
Root Cause
Two issues compounded:
Backend: The REST API response coerced
durationMs: null→0via?? 0inusage-storage.ts. The DB correctly storesnullfor pending requests, but the API response lost that signal.Frontend: The live duration check used
log.durationMs != nullto decide whether to use the stored value or compute live. WhendurationMswas0(from the backend coercion),0 != nullistrue, soformatMs(0)was called — which returns'∅'.This only manifested on page refresh (REST API path). For SSE-arrived requests,
durationMswasundefined(not in the partial record), so!= nullcorrectly fell through to the live calculation.Changes
usage-storage.ts): Stop coercingdurationMsnull→0 in REST API response; letnullflow throughapi.ts): ChangedurationMstype fromnumbertonumber | nullto reflect realityLogs.tsx): Use!= null && > 0guard so bothnulland0fall through toDate.now() - startTimeuseModels.ts,useProviderForm.tsx): Add null guards onreducecalls for the new nullable type