inspector icon indicating copy to clipboard operation
inspector copied to clipboard

Handle task completion notifications to skip polling delay

Open Christian-Sidak opened this issue 6 months ago • 0 comments

Summary

  • Adds a taskNotificationResolverRef that holds the in-progress poll's { taskId, resolve } while the polling loop is running
  • The notifications/tasks/status handler now calls resolve() when a terminal status (completed, failed, or cancelled) arrives for the task being polled
  • The polling loop now uses Promise.race between the poll-interval timer and the notification signal, so whichever fires first unblocks the loop

Problem

The task polling loop in callTool waited a full pollInterval milliseconds via setTimeout before every tasks/get call. Even when the server sent a notifications/tasks/status notification indicating the task was done, the inspector ignored it and continued sleeping until the timer expired. With long poll intervals this caused a noticeable (or very long) delay before the result appeared.

Test plan

  • [x] New test: App.taskNotification.test.tsx — verifies that tasks/get is called promptly after a terminal notification arrives, even when pollInterval is 10 s (well above waitFor's 1 s timeout, so the test would time out without the fix)
  • [x] Second test verifies a notification for a different task does not interfere with the current poll
  • [x] All 517 tests pass locally

Fixes #1037

Christian-Sidak avatar May 14 '26 08:05 Christian-Sidak