Skip to content

[Bug] AgentsSection fetchAgentMeta has unhandled Promise.all rejection and leaks loading state #401

@samzong

Description

@samzong

Problem

AgentsSection fires Promise.all(ids.map((id) => fetchAgentMeta(id))) inside a useEffect with no await and no .catch. fetchAgentMeta itself contains await window.clawwork.listAgentFiles(...) without a try/catch — if that IPC throws, two things break:

  1. The unhandled promise rejection propagates out of the Promise.all and becomes a renderer-wide console error (or crashes the tab in strict settings).
  2. setLoadingFilesFor(null) is never called, so the agent stays in "loading files" state indefinitely with no way to recover short of switching gateways.

Location

File: packages/desktop/src/renderer/layouts/Settings/sections/AgentsSection.tsx:751-755 (caller) and 698-713 (callee)

// Caller
useEffect(() => {
  if (!selectedGatewayId || agents.length === 0) return;
  const ids = agents.map((a) => a.id);
  Promise.all(ids.map((id) => fetchAgentMeta(id)));  // no await, no catch
}, [selectedGatewayId, agents, fetchAgentMeta]);

// Callee
const fetchAgentMeta = useCallback(
  async (agentId: string) => {
    if (!selectedGatewayId) return;
    setLoadingFilesFor(agentId);
    const res = await window.clawwork.listAgentFiles(selectedGatewayId, agentId);  // throw → state leak
    setLoadingFilesFor(null);
    // ...
  },
  [selectedGatewayId],
);

Fix Approach

  1. In fetchAgentMeta, wrap the IPC in try/finally so setLoadingFilesFor(null) always runs:
setLoadingFilesFor(agentId);
try {
  const res = await window.clawwork.listAgentFiles(selectedGatewayId, agentId);
  // ... handle result
} catch (err) {
  console.error('[AgentsSection] listAgentFiles failed:', err);
} finally {
  setLoadingFilesFor((current) => (current === agentId ? null : current));
}
  1. In the caller useEffect, attach .catch to the Promise.all so unhandled rejections are logged explicitly.

Verification

  1. Run pnpm check — must pass.
  2. Manual: simulate listAgentFiles throwing — the agent row should stop showing a loading spinner and the console should log the error.

Context

  • WG: UI & Design System
  • Priority: Low (good first issue)
  • Estimated effort: 15-20 minutes

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/uiUI & Design System WGgood first issueGood for newcomerskind/bugCategorizes issue or PR as related to a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions