Restart streams on error in Agent SDK#1759
Conversation
…nt fixes Adds Toxiproxy to the dev Docker setup and reconnect/restart tests to verify whether CI fails without the corresponding Agent.ts changes.
🦋 Changeset detectedLatest commit: 3c24761 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
ApprovabilityVerdict: Needs human review This PR introduces significant runtime behavior changes - automatic stream reconnection with exponential backoff retry logic. While the author owns nearly all changed files and the implementation appears reasonable, the change modifies core error handling behavior that could affect applications using the SDK. The open review comment is a minor cleanup suggestion. You can customize Macroscope's approvability policy. Learn more. |
Dismissing prior approval to re-evaluate adfaea5
Dismissing prior approval to re-evaluate aef8c77
Dismissing prior approval to re-evaluate 22077bc
Dismissing prior approval to re-evaluate 423d196
…ry fails or agent is (#1760) Fix agent lock not being released when stream recovery fails or agent is stopped Co-authored-by: macroscopeapp[bot] <170038800+macroscopeapp[bot]@users.noreply.github.com>
… exhausted retry err (#1761) Remove try-catch around #retryStreams() to propagate exhausted retry errors Co-authored-by: macroscopeapp[bot] <170038800+macroscopeapp[bot]@users.noreply.github.com>
Updated the version of @xmtp/agent-sdk to minor and added restart on error functionality for streams.
sdks/agent-sdk/src/core/Agent.ts
Outdated
| // but we must handle it for proper types | ||
| if (!(message instanceof DecodedMessage)) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
this if statement is no longer necessary
Summary
Agent.reconnect.test.tsand a new case inAgent.test.ts)Agent.tsfixes from (via bennycode): Fix locking issue in Agent.start() by clearing lock before error handlin #1756/Fix: lock not released instart()catch path blocks recovery restarts #1757/(via bennycode): fix(agent-sdk): release lock before calling start() in restart method #1758 to verify these tests fail in CI without the reconnect logicTest plan
Agent.tshas no auto-restart logic on this branchNote
Add automatic stream restart with exponential backoff to Agent SDK
Agentnow retries failed stream setup using exponential backoff (10 retries, 1s–30s delay) viats-retry-promise, re-emitting'start'on successful recovery.#retryStreamsmethod and reworked#handleStreamErrorcoordinate restart state, guarding against concurrent restarts and respectingstop()calls.stop()sets a#stoppedflag that prevents any pending or future automatic restarts from proceeding.start()failures also schedule retries instead of failing silently.Changes since #1759 opened
Agent.conversations.streamAllMessagesonValue handler [8e64c9e]DecodedMessageimport to type-only import inAgentmodule [971e41a]@xmtp/node-sdkimport statement [3c24761]Macroscope summarized 4f21526.