feat(client): GET 请求瞬态故障自动重试(指数退避),非幂等方法不重试 #339

Open
Taoyouce wants to merge 4 commits from Taoyouce/gitlink-cli:feat/get-retry-backoff into master
Contributor

背景

CLI 目前对任何网络抖动(连接失败、网关 502/503/504、限流 429)都直接失败。在 AI Agent / CI 门禁等自动化场景下,一次瞬态故障就会中断整条工作流。成熟 CLI(如 gh)默认对幂等请求做有限次重试。

变更内容

  • internal/client:GET(幂等)请求遇到以下瞬态故障自动重试,最多 2 次,指数退避(300ms → 600ms):
    • 网络层错误(连接失败、读响应失败)
    • HTTP 429 / 502 / 503 / 504
  • 非幂等方法(POST/PUT/DELETE/PATCH)一律不重试,避免重复副作用。
  • 其他 4xx/5xx 状态不重试(非瞬态)。
  • --debug 下打印每次重试的原因与退避时长。

测试

  • internal/client/retry_test.go 5 个用例:503 两次后成功、超过重试上限停止、POST 不重试、404 不重试、连接拒绝重试后报错。
  • go test ./... / go vet / gofmt 全绿。
  • 生产冒烟:repo +info 正常。
## 背景 CLI 目前对任何网络抖动(连接失败、网关 502/503/504、限流 429)都直接失败。在 AI Agent / CI 门禁等自动化场景下,一次瞬态故障就会中断整条工作流。成熟 CLI(如 gh)默认对幂等请求做有限次重试。 ## 变更内容 - `internal/client`:GET(幂等)请求遇到以下瞬态故障自动重试,最多 2 次,指数退避(300ms → 600ms): - 网络层错误(连接失败、读响应失败) - HTTP 429 / 502 / 503 / 504 - 非幂等方法(POST/PUT/DELETE/PATCH)一律**不重试**,避免重复副作用。 - 其他 4xx/5xx 状态不重试(非瞬态)。 - `--debug` 下打印每次重试的原因与退避时长。 ## 测试 - `internal/client/retry_test.go` 5 个用例:503 两次后成功、超过重试上限停止、POST 不重试、404 不重试、连接拒绝重试后报错。 - `go test ./...` / `go vet` / `gofmt` 全绿。 - 生产冒烟:`repo +info` 正常。
Taoyouce added 4 commits 2026-07-06 06:24:17 +08:00
Taoyouce added 1 commit 2026-07-06 06:27:02 +08:00
20f988bf5b feat(client): 错误建议统一透传 + HTML 回落判错(non_api_response)
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Taoyouce added 1 commit 2026-07-06 06:52:37 +08:00
7128960529 feat(client): 429 重试遵循 Retry-After 头(5s 上限护栏)+ 6 表驱动单测
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Taoyouce added 1 commit 2026-07-07 22:36:14 +08:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
You can also view command line instructions.

Step 1:

From your project repository, check out a new branch and test the changes.
git checkout -b Taoyouce-feat/get-retry-backoff master
git pull feat/get-retry-backoff

Step 2:

Merge the changes and update on Gitea.
git checkout master
git merge --no-ff Taoyouce-feat/get-retry-backoff
git push origin master
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Gitlink/gitlink-cli#339
No description provided.