Skip to content

fix(samples): retry shell agent-card discovery during startup#830

Open
stablegenius49 wants to merge 1 commit intogoogle:mainfrom
stablegenius49:fix/587-agent-card-startup-retry
Open

fix(samples): retry shell agent-card discovery during startup#830
stablegenius49 wants to merge 1 commit intogoogle:mainfrom
stablegenius49:fix/587-agent-card-startup-retry

Conversation

@stablegenius49
Copy link

Summary

  • add a shared retry/backoff helper for A2A Agent Card discovery in the lit shell sample
  • reuse the same extension-aware fetch wrapper in both the browser client and dev middleware
  • show a clearer first-load waiting message while the sample waits for agents to finish booting
  • add focused retry unit tests for the new helper

Closes #587

How did you test this change?

  • npm run build in samples/client/lit/shell
  • node --test dist/tests/client-factory.test.js in samples/client/lit/shell

@google-cla
Copy link

google-cla bot commented Mar 12, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a robust retry mechanism with exponential backoff for agent card discovery, which is a great improvement for handling startup race conditions. The new logic is well-encapsulated in a2a-client-factory.ts, thoroughly tested, and cleanly integrated into both the Lit shell client and the dev middleware. The improved loading message is also a nice touch for the user experience. I have one suggestion to enhance the error reporting for better debuggability.

Comment on lines +100 to +102
throw lastError instanceof Error
? lastError
: new Error(`Failed to connect to agent card: ${cardUrl}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When the retry loop exhausts all attempts, this logic correctly throws an error. However, if lastError is not an instance of Error (e.g., it's a plain object or a string from a library), the original error details are lost in the new generic Error message. This can make debugging more difficult.

To provide more context, you could serialize the lastError into the new error message. A simple if/else block would also improve readability over the ternary.

  if (lastError instanceof Error) {
    throw lastError;
  }
  throw new Error(
    `Failed to connect to agent card: ${cardUrl}. Last error: ${JSON.stringify(
      lastError,
    )}`,
  );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Quickstart demo shows connection errors due to race condition on startup

1 participant