jlcodes99/cockpit-tools · warning

No task found for notification ${notificationId}

Error message

No task found for notification ${notificationId}

What it means

initWakeupNotificationListener registers a handler for Tauri 'notification://action' events. When the user clicks a wakeup notification, the handler looks up notificationId in the module-level notificationTaskMap to find which task scheduled it. If the mapping is missing, it warns and returns early — the click has no effect and the stale notification is left on screen.

Source

Thrown at src/utils/wakeupNotificationListener.ts:28

  taskId: string;
  notificationId: number;
}

// 存储通知 ID 到任务 ID 的映射
const notificationTaskMap = new Map<number, string>();

export function mapNotificationToTask(notificationId: number, taskId: string): void {
  notificationTaskMap.set(notificationId, taskId);
}

export function initWakeupNotificationListener(): void {
  // 监听通知动作事件
  listen<NotificationAction>('notification://action', async (event) => {
    const { actionId, notificationId } = event.payload;

    const taskId = notificationTaskMap.get(notificationId);
    if (!taskId) {
      console.warn(`No task found for notification ${notificationId}`);
      return;
    }

    // 清理映射
    notificationTaskMap.delete(notificationId);

    if (actionId === 'confirm') {
      try {
        await invoke('confirm_wakeup_task', { taskId });
        console.log(`Wakeup task ${taskId} confirmed and executed`);
      } catch (error) {
        console.error(`Failed to confirm wakeup task: ${error}`);
      }
    } else if (actionId === 'cancel') {
      try {
        await invoke('cancel_wakeup_task', { taskId });
        console.log(`Wakeup task ${taskId} cancelled`);
      } catch (error) {

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Dismiss the stale notification manually; it refers to a task the current session no longer tracks.
  2. Persist notificationTaskMap (or the task schedule) so mappings survive app restarts.
  3. On startup, cancel previously scheduled OS notifications so old ones can't be clicked.
  4. If the task should still exist, verify the code path that deleted the map entry (or the task) didn't run prematurely.

Example fix

// before
const taskId = notificationTaskMap.get(notificationId);
if (!taskId) {
  console.warn(`No task found for notification ${notificationId}`);
  return;
}
// after
const taskId = notificationTaskMap.get(notificationId);
if (!taskId) {
  console.warn(`No task found for notification ${notificationId}`);
  cancelNotification(notificationId); // dismiss stale notification
  return;
}
Defensive patterns

Strategy: fallback

Validate before calling

// before firing a notification, register its mapping and verify it
notificationTaskMap.set(notificationId, taskId);
if (notificationTaskMap.get(notificationId) !== taskId) {
  throw new Error('failed to register notification mapping');
}

Type guard

function isRegisteredNotification(id: string): boolean {
  return notificationTaskMap.has(id);
}

Try / catch

listen<NotificationAction>('notification://action', async (event) => {
  const taskId = notificationTaskMap.get(event.payload.notificationId);
  if (!taskId) {
    console.warn(`No task found for notification ${event.payload.notificationId}`);
    await cancelNotification(event.payload.notificationId); // dismiss stale
    return;
  }
  // ... handle task
});

Prevention

When it happens

Trigger: User clicks a wakeup/scheduled notification whose id is not in notificationTaskMap: the app restarted since the notification was posted, the task was deleted before firing, or the notification was created by a previous session/app version.

Common situations: OS delivers a scheduled notification after an app reboot (map is in-memory and empty), duplicate notifications from an earlier session, or the task completed and its mapping was cleaned before the click arrived.

Related errors


AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05). Data as JSON: /api/errors/04b02a1411d8fd81. Report an issue: GitHub.