#14402: fix(feishu): chunk large documents for write/append to avoid API 400 errors
channel: feishu
stale
size: S
Cluster:
Memory Management Enhancements
## 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
#16409: fix(feishu): preserve docx block order via sequential inserts
by ciberponk · 2026-02-14
80.4%
#16592: feat(feishu): add write mode import for markdown documents
by ciberponk · 2026-02-14
78.9%
#20304: feat(feishu): support Docx table create/write + image/file upload a...
by xuhao1 · 2026-02-18
78.0%
#16438: feat(feishu): add create_from_markdown import action
by ciberponk · 2026-02-14
77.6%
#12755: feat(feishu): render post rich text as markdown
by WilsonLiu95 · 2026-02-09
76.1%
#16428: fix(feishu): retry docx block insertion on rate limits
by ciberponk · 2026-02-14
75.8%
#13917: fix(feishu): card rendering for tables, blockquotes, images, and ou...
by yaoting · 2026-02-11
74.7%
#9089: feat(memory): semantic markdown chunking for better recall
by Kuroro92100 · 2026-02-04
73.6%
#19027: fix(feishu): keep chunked messages in topic/thread context
by qiangu · 2026-02-17
73.5%
#16647: feat(feishu_doc): allow optional initial content on create
by ciberponk · 2026-02-15
72.5%