#16428: fix(feishu): retry docx block insertion on rate limits
channel: feishu
size: S
Cluster:
Memory Management Enhancements
## Summary
- fix(feishu): retry docx block insertion on rate limits
- Split from our `v2026.2.13` patch train as a single-purpose change for easier review.
## Why
- Keep the diff focused and low-risk so it can be merged or reverted independently.
## Scope
- Branch: `fix/feishu-docx-rate-limit-retry-en`
- Files changed: 2
- Key files:
- `extensions/feishu/src/docx.test.ts`
- `extensions/feishu/src/docx.ts`
## Test Plan
- Suggested local command:
- `./node_modules/.bin/vitest run extensions/feishu/src/docx.test.ts`
- Validation status:
- [ ] CI checks pass
- [ ] Maintainer re-ran local tests
## Risk & Rollback
- Risk: low to medium; impact limited to touched module(s).
- Rollback: revert this PR commit(s) cleanly.
## Co-authorship
- Co-authored by @ciberponk and Codex (GPT-5).
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds retry logic for Feishu docx block insertion when the API returns rate-limit responses (HTTP 429 or rate-limit-related error messages). The implementation introduces a `runWithRateLimitRetry` wrapper that retries up to 3 times with a 300ms fixed delay, applied to the `documentBlockChildren.create` call in `insertBlocks`. The rate-limit detection handles both numeric code 429 and message-based matching (including Chinese strings for the Feishu domestic API).
- **Retry wrapper**: New `runWithRateLimitRetry` generic function with correct early-return on success, break on non-rate-limit errors, and throw after exhausting retries
- **Rate-limit detection**: `isRateLimited` checks code 429 and multiple message patterns covering English and Chinese API responses
- **Tests**: Two new test cases cover the happy path (retry succeeds on second attempt) and the failure path (all retries exhausted), both using fake timers to handle the sleep delay
- **Scope**: Change is limited to block insertion; other Feishu API calls (convert, list, patch, delete) are not wrapped with retry logic
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — it adds a narrowly scoped retry wrapper with correct logic and comprehensive tests.
- The retry logic is straightforward and correctly implemented. The function preserves existing error-throwing behavior for non-rate-limit failures. The change is limited to a single API call site (`documentBlockChildren.create`) within the feishu extension. Both the success-after-retry and exhausted-retries paths are tested. No breaking changes to the public API or existing behavior.
- No files require special attention.
<sub>Last reviewed commit: bd8acbb</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#16409: fix(feishu): preserve docx block order via sequential inserts
by ciberponk · 2026-02-14
79.8%
#14402: fix(feishu): chunk large documents for write/append to avoid API 40...
by lml2468 · 2026-02-12
75.8%
#23497: feat(retry): add retryHttpAsync utility with comprehensive coverage
by thinstripe · 2026-02-22
70.1%
#16647: feat(feishu_doc): allow optional initial content on create
by ciberponk · 2026-02-15
70.0%
#16239: fix: retry on transient API errors (overloaded, rate-limit, timeout)
by zerone0x · 2026-02-14
69.2%
#19027: fix(feishu): keep chunked messages in topic/thread context
by qiangu · 2026-02-17
68.8%
#16438: feat(feishu): add create_from_markdown import action
by ciberponk · 2026-02-14
68.8%
#16195: feat(infra): add unified retry utility with exponential backoff
by bianbiandashen · 2026-02-14
68.1%
#16592: feat(feishu): add write mode import for markdown documents
by ciberponk · 2026-02-14
68.1%
#20304: feat(feishu): support Docx table create/write + image/file upload a...
by xuhao1 · 2026-02-18
68.1%