fix(setup): 开放平台页面读取偶发 fetch failed 自动重试并透出真实网络错误 - #913
Merged
Conversation
宿主机到 open.feishu.cn 的偶发网络抖动会让 undici 把请求抛成一句
TypeError('fetch failed'),一次失败就中断整条 console 自动化链路——
dashboard 改头像/改名、VC 事件订阅检查都实测偶发中招,且真实原因
(ECONNRESET / EAI_AGAIN 等)藏在 err.cause 里被丢弃,无法排障。
- MutableCookieJar.fetchRaw:幂等 GET/HEAD 每跳对瞬态网络错误小步退避
重试(300ms/900ms,共 3 次);POST 全是 console 写操作,传输错误时
结果未知,保持单次绝不重试
- safeErrorMessage:展开 err.cause 链(含 happy-eyeballs AggregateError),
报错带上真实网络错误码,长 token 脱敏保持不变
- open-platform-rename failureFromError 复用 safeErrorMessage,改名/改
头像的 POST 阶段网络错误同样透出 cause
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改了什么、为什么
用户在 dashboard 改机器人头像时报错「✗ 改头像失败:读取开放平台页面失败: fetch failed」。
排查结论:宿主机到 open.feishu.cn 的偶发网络抖动会让 undici 把请求直接抛成一句
TypeError('fetch failed')。daemon 日志显示同链路的 VC 事件订阅检查过去几天也多次偶发同样报错,而前一天同链路改头像又成功过;当前复现窗口外用同款 Node(v22.21.1)连续 30 次直连全部成功,确认是瞬态故障。现有代码对 console 入口页 GET 只请求一次、失败即中断,且真实原因(ECONNRESET/EAI_AGAIN等,藏在err.cause)被safeErrorMessage丢弃,用户和排障方只能看到一句 "fetch failed"。修复两点:
MutableCookieJar.fetchRaw对每一跳的 GET/HEAD 在识别为瞬态网络错误(按错误码白名单 + undicifetch failed形态判定,主动 abort/timeout 不算)时小步退避重试(300ms/900ms,共 3 次)。POST 绝不重试——console POST 全是写操作(建版/发布/base_info 等),传输错误时服务端可能已 commit,重试等于重复提交(与既有「outcome unknown 不得重建」的 fail-closed 语义一致,有测试守护)。safeErrorMessage展开err.cause(含 happy-eyeballs 的AggregateError),报错形如fetch failed: connect ETIMEDOUT 1.2.3.4:443;长 token 脱敏保持不变。open-platform-rename的failureFromError复用之,改名/改头像 POST 阶段的网络错误同样受益。影响面
改动集中在
src/setup/open-platform-automation.ts的共用 HTTP 层(MutableCookieJar)+src/services/open-platform-rename.ts错误信息,波及所有走 console 自动化的路径:botmux setup开放平台自动配置、已有应用列表/凭证读取、onboardingqrlogin/init/qrlogin/polling),不受重试影响;登录后的 cross-login GET 跳转幂等,可安全重试不涉及 CLI 适配器 / 后端 / 会话类型分支,纯 Node 网络层,Linux/macOS 行为一致。
测试验证
pnpm build通过pnpm vitest run test/setup-open-platform-automation.test.ts test/open-platform-rename.test.ts test/open-platform-avatar.test.ts test/setup-open-platform-outcome.test.ts— 82 passed;引用方test/feishu-login-manager.test.ts test/setup-pickers.test.ts test/dashboard-bot-onboarding.test.ts— 78 passednetwork且 message 含ECONNRESET;POST 传输错误只请求一次立刻抛出;非网络错误不重试;safeErrorMessagecause 链展开(普通 cause / AggregateError / code 补全 / 长 token 脱敏)pnpm switch:here && pnpm daemon:restart部署 live,等待 dashboard 改头像实测确认Made with Cursor