Skip to content

fix(logs): live duration shows ∅ for in-flight requests on page refresh#434

Merged
mcowger merged 1 commit into
mainfrom
duration
May 18, 2026
Merged

fix(logs): live duration shows ∅ for in-flight requests on page refresh#434
mcowger merged 1 commit into
mainfrom
duration

Conversation

@mcowger
Copy link
Copy Markdown
Owner

@mcowger mcowger commented May 18, 2026

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: null0 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

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
@mcowger mcowger merged commit d5cd0c6 into main May 18, 2026
1 check passed
@mcowger mcowger deleted the duration branch May 18, 2026 05:55
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant