← Back to PRs

#16428: fix(feishu): retry docx block insertion on rate limits

by ciberponk open 2026-02-14 18:59 View on GitHub →
channel: feishu size: S
## 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