← Back to PRs

#14402: fix(feishu): chunk large documents for write/append to avoid API 400 errors

by lml2468 open 2026-02-12 02:25 View on GitHub →
channel: feishu stale size: S
## Problem When writing long documents via `feishu_doc` tool (`action: "write"` or `action: "append"`), the Feishu API returns HTTP 400 errors because: 1. `documentBlockChildren.create` is limited to **50 blocks per request** 2. `document.convert` has content size limits for large markdown input This makes it impossible to write comprehensive reports or long-form content to Feishu docs in a single operation — users must manually split content and call `append` multiple times. ## Solution Added three helper functions to `extensions/feishu/src/docx.ts`: - **`splitMarkdownByHeadings()`** — Splits markdown at `#`/`##` headings into smaller chunks - **`chunkedConvertMarkdown()`** — Converts each chunk independently via the convert API, combining all blocks - **`chunkedInsertBlocks()`** — Batches blocks into groups of ≤50 for the insert API Updated `writeDoc` and `appendDoc` to use the chunked helpers. Small documents work exactly as before (single chunk, single batch). Image processing correctly receives all inserted blocks across batches. ## Testing - [x] AI-assisted (Claude Code) - [x] Lightly tested — verified with real Feishu documents that previously failed with 400 errors - [x] Understand what the code does ## Changes - `extensions/feishu/src/docx.ts`: +61/-4 lines <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR updates the Feishu `feishu_doc` write/append implementation to handle large inputs by: - splitting markdown into heading-based chunks before calling `docx.document.convert`, and - inserting converted blocks in batches of 50 to comply with `documentBlockChildren.create` limits. The batching approach fits into the existing `convertMarkdown` → `insertBlocks` flow in `extensions/feishu/src/docx.ts`, with `writeDoc`/`appendDoc` now delegating to chunked helpers and passing the aggregated inserted blocks to `processImages`. <h3>Confidence Score: 3/5</h3> - This PR is mergeable after addressing a markdown-splitting edge case that can corrupt output for some inputs. - The core change (batching inserts to ≤50 blocks) is straightforward, but the heading-based markdown splitter is not fence-aware and can change conversion output for long markdown containing fenced code blocks with `#`/`##` lines. - extensions/feishu/src/docx.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs