Skip to content

fix: use node current status as fallback instead of hardcoded UNKNOWN#102

Open
TerrifiedBug wants to merge 3 commits intomainfrom
fix/status-timeline-unknown-fallback
Open

fix: use node current status as fallback instead of hardcoded UNKNOWN#102
TerrifiedBug wants to merge 3 commits intomainfrom
fix/status-timeline-unknown-fallback

Conversation

@TerrifiedBug
Copy link
Owner

Summary

  • getStatusTimeline router now returns { events, nodeStatus } — fetches the node's current DB status in parallel with events
  • getUptime router falls back to nodeForStatus?.status before "UNKNOWN" when no prior event exists
  • StatusTimeline component uses data.nodeStatus as the segment status when there are no events in range, instead of hardcoding "UNKNOWN"

Test plan

  • Open a node that has no status events in the selected time range — timeline should show the node's actual current status color, not grey/UNKNOWN
  • Open a node with events — behavior unchanged
  • Check uptime % for a node with no prior events — should reflect current status rather than defaulting UNKNOWN (0% healthy)

🤖 Generated with Claude Code

When a node has no status event history within the selected range,
the timeline and uptime router now fall back to the node's actual
current status from the DB rather than always showing "UNKNOWN".

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added the fix label Mar 14, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 14, 2026

Greptile Summary

Uses the node's current DB status as a fallback instead of hardcoding "UNKNOWN" when no status events exist. The getStatusTimeline router now returns { events, nodeStatus } (fetched in parallel), and getUptime falls back to nodeForStatus?.status before "UNKNOWN".

  • The StatusTimeline component correctly adapts to the new response shape
  • Bug: EventLog component (event-log.tsx) also consumes getStatusTimeline but was not updated for the new return shape — it will break at runtime (event log will always appear empty)

Confidence Score: 2/5

  • This PR will break the EventLog component at runtime due to an unconverted consumer of the changed API response shape.
  • The core logic changes are sound, but the getStatusTimeline return shape change was not propagated to event-log.tsx, which will silently render an empty event log for all nodes. This is a correctness bug that will manifest under normal usage.
  • src/components/fleet/event-log.tsx — needs the same destructuring update applied to status-timeline.tsx

Important Files Changed

Filename Overview
src/server/routers/fleet.ts Router changes look correct: getStatusTimeline returns { events, nodeStatus } and getUptime uses node's current status as fallback. Both use Promise.all for parallel queries. The return shape change breaks an unconverted consumer (event-log.tsx).
src/components/fleet/status-timeline.tsx Correctly adapted to the new { events, nodeStatus } response shape. Uses nodeStatus as segment status when no events exist, and properly includes it in the useMemo dependency array.

Sequence Diagram

sequenceDiagram
    participant ST as StatusTimeline
    participant EL as EventLog
    participant tRPC as fleet.getStatusTimeline
    participant DB as PostgreSQL

    ST->>tRPC: queryOptions({ nodeId, range })
    EL->>tRPC: queryOptions({ nodeId, range })
    tRPC->>DB: Promise.all([findMany events, findUnique node])
    DB-->>tRPC: [events[], node]
    tRPC-->>ST: { events, nodeStatus }
    tRPC-->>EL: { events, nodeStatus }
    Note over ST: ✅ Destructures data.events & data.nodeStatus
    Note over EL: ❌ Treats entire response as events array
Loading

Comments Outside Diff (1)

  1. src/components/fleet/event-log.tsx, line 35-38 (link)

    EventLog breaks — response shape changed

    getStatusTimeline now returns { events, nodeStatus } instead of an array, but this component still aliases data as events. On line 50, [...events].reverse() will spread the object into an empty array, so the event log will always show "No events in this time range" after this PR.

    This needs the same destructuring fix applied in status-timeline.tsx:

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/components/fleet/event-log.tsx
Line: 35-38

Comment:
**`EventLog` breaks — response shape changed**

`getStatusTimeline` now returns `{ events, nodeStatus }` instead of an array, but this component still aliases `data` as `events`. On line 50, `[...events].reverse()` will spread the object into an empty array, so the event log will **always** show "No events in this time range" after this PR.

This needs the same destructuring fix applied in `status-timeline.tsx`:

```suggestion
  const { data, isLoading } = useQuery({
    ...trpc.fleet.getStatusTimeline.queryOptions({ nodeId, range }),
    refetchInterval: 15_000,
  });
  const events = data?.events;
```

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: 05efd17

TerrifiedBug and others added 2 commits March 15, 2026 23:17
getStatusTimeline now returns { events, nodeStatus } instead of a plain
array. EventLog was still treating data as an array, causing it to always
render empty. Destructure data.events to restore correct behaviour.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Collapses three sequential DB round-trips in getUptime into a single
Promise.all, reducing latency when loading node health cards.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant