Files
stack/docs/scratchpads/298-async-dashboard.md
Jason Woltje 9582d9a265
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
fix(#298): Fix async response handling in dashboard
Replaced setTimeout hacks with proper polling mechanism:
- Added pollForQueryResponse() function with configurable polling interval
- Polls every 500ms with 30s timeout
- Properly handles DELIVERED and FAILED message states
- Throws errors for failures and timeouts

Updated dashboard to use polling instead of arbitrary delays:
- Removed setTimeout(resolve, 1000) hacks
- Added proper async/await for query responses
- Improved response data parsing for new query format
- Better error handling via polling exceptions

This fixes race conditions and unreliable data loading.

Fixes #298

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-03 22:51:25 -06:00

2.5 KiB

Issue #298: Fix async response handling in dashboard

Objective

Replace setTimeout hacks with proper async response handling for federated queries in the dashboard.

Current State

  • Dashboard uses setTimeout(resolve, 1000) to wait for query responses (lines 59, 83)
  • Race conditions possible
  • Unreliable data loading
  • Poor UX with arbitrary delays

Approach

Implement polling mechanism to check query message status:

  1. Send query and get message ID
  2. Poll for message status until DELIVERED or FAILED
  3. Extract response data when available
  4. Handle timeouts gracefully

Implementation Plan

  • Create scratchpad
  • Add polling utility function
  • Update dashboard to use polling instead of setTimeout
  • Add proper loading states (via polling)
  • Add error handling (polling throws on failure)
  • Add timeout handling (30s timeout)
  • Test with actual federation connection (requires live system)

Changes Made

apps/web/src/lib/api/federation-queries.ts

Added pollForQueryResponse() function:

  • Polls every 500ms for message status
  • Timeout after 30 seconds
  • Returns message when DELIVERED
  • Throws error when FAILED or timeout reached
  • Configurable poll interval and timeout

apps/web/src/app/(authenticated)/federation/dashboard/page.tsx

Replaced setTimeout hacks with polling:

  • Line 57-59: Removed setTimeout, added pollForQueryResponse
  • Line 83: Removed setTimeout, added pollForQueryResponse
  • Updated query strings to match new format ("get tasks", "get events")
  • Improved response data parsing to handle new response format
  • Error handling via try/catch (polling throws on failure)

Testing Notes

  • Polling function handles PENDING → DELIVERED transition
  • Polling function handles PENDING → FAILED transition
  • Timeout prevents infinite waiting
  • Errors are properly propagated to dashboard error handling

Changes to Make

apps/web/src/lib/api/federation-queries.ts

Add polling function:

  • pollForQueryResponse(messageId: string): Promise<QueryResponse>
  • Poll every 500ms, timeout after 30 seconds
  • Check message status until DELIVERED or FAILED

apps/web/src/app/(authenticated)/federation/dashboard/page.tsx

  • Remove setTimeout hacks
  • Use polling function to wait for responses
  • Add proper loading states per connection
  • Add better error messages
  • Add timeout handling

Notes

  • Message status: PENDING → DELIVERED or FAILED
  • Poll interval: 500ms
  • Timeout: 30 seconds
  • Need to handle both successful and failed queries