Skip to content

callTool does not retry on transient network errors (socket closed during concurrent requests) #114

@icebear0828

Description

@icebear0828

Description

When multiple callTool() requests run concurrently (e.g. generating variants with Pro model), the Stitch server occasionally closes the underlying socket. The SDK surfaces this as an unrecoverable TypeError: fetch failed to the caller, even though the operation would succeed on a simple retry with a fresh connection.

Steps to reproduce

const client = new StitchToolClient({ apiKey: "..." });
const project = await client.callTool("create_project", { title: "test" });
const projectId = project.name.replace("projects/", "");

const screen = await client.callTool("generate_screen_from_text", {
  projectId,
  prompt: "a dashboard",
  modelId: "GEMINI_3_PRO",
});
const screenId = screen.outputComponents[0].design.screens[0].id;

// Fire 3 concurrent variant requests — one or more will fail
await Promise.allSettled([
  client.callTool("generate_variants", {
    projectId,
    selectedScreenIds: [screenId],
    prompt: "dark theme",
    variantOptions: { variantCount: 2, creativeRange: "EXPLORE" },
    modelId: "GEMINI_3_PRO",
  }),
  client.callTool("generate_variants", { /* ... */ }),
  client.callTool("generate_variants", { /* ... */ }),
]);

Actual behavior

Stitch Transport Error: TypeError: fetch failed
  [cause]: SocketError: other side closed

One or more requests fail with no retry attempt. The transport's onerror sets isConnected = false, but the in-flight request is already lost.

Expected behavior

callTool should detect transient network errors (e.g. fetch failed, ECONNRESET, socket), reconnect, and retry the request once before throwing.

Environment

  • @google/stitch-sdk 0.0.3
  • Node.js 22
  • macOS
  • Reproducible with GEMINI_3_PRO model under concurrent variant generation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions