Bug Description
feishu_doc write action does not fully replace document content when the document has more than ~50 top-level blocks. Instead of replacing all content, it only deletes the first page of blocks and appends new content after the remaining old blocks.
Root Cause
In api.js line 1993, clearDocumentContent() calls client.docx.documentBlock.list() without pagination. The Feishu API returns results in pages (default ~50 blocks per page), but the function only processes the first page:
async function clearDocumentContent(client, docToken) {
const existing = await client.docx.documentBlock.list({ path: { document_id: docToken } });
// ^ Only fetches first page! No page_token loop
const childIds = existing.data?.items
?.filter((b) => b.parent_id === docToken && b.block_type !== 1)
.map((b) => b.block_id) ?? [];
if (childIds.length > 0) {
const res = await client.docx.documentBlockChildren.batchDelete({
path: { document_id: docToken, block_id: docToken },
data: { start_index: 0, end_index: childIds.length }
});
if (res.code !== 0) throw new Error(res.msg);
}
return childIds.length;
}
Expected Behavior
write should fully replace all document content regardless of document size.
Suggested Fix
Add pagination loop to clearDocumentContent:
async function clearDocumentContent(client, docToken) {
let items = [];
let pageToken;
do {
const res = await client.docx.documentBlock.list({
path: { document_id: docToken },
params: pageToken ? { page_token: pageToken } : {}
});
if (res.code !== 0) throw new Error(res.msg);
items.push(...(res.data?.items ?? []));
pageToken = res.data?.page_token ?? undefined;
} while (pageToken);
const childIds = items
.filter((b) => b.parent_id === docToken && b.block_type !== 1)
.map((b) => b.block_id) ?? [];
if (childIds.length > 0) {
const res = await client.docx.documentBlockChildren.batchDelete({
path: { document_id: docToken, block_id: docToken },
data: { start_index: 0, end_index: childIds.length }
});
if (res.code !== 0) throw new Error(res.msg);
}
return childIds.length;
}
Reproduction
- Create a Feishu document with 100+ top-level blocks (e.g., a long report with many sections, lists, quotes)
- Call
feishu_doc with action: "write" and new content
- Observe: old content remains in the document after the first ~50 blocks, with new content appended after it
Workaround
Create a new document and use write (for first chunk) + append (for subsequent chunks) instead of writing to an existing large document.
Environment
- OpenClaw version: 2026.4.7
- Feishu plugin: bundled
- File:
dist/extensions/feishu/api.js line 1993
Bug Description
feishu_docwriteaction does not fully replace document content when the document has more than ~50 top-level blocks. Instead of replacing all content, it only deletes the first page of blocks and appends new content after the remaining old blocks.Root Cause
In
api.jsline 1993,clearDocumentContent()callsclient.docx.documentBlock.list()without pagination. The Feishu API returns results in pages (default ~50 blocks per page), but the function only processes the first page:Expected Behavior
writeshould fully replace all document content regardless of document size.Suggested Fix
Add pagination loop to
clearDocumentContent:Reproduction
feishu_docwithaction: "write"and new contentWorkaround
Create a new document and use
write(for first chunk) +append(for subsequent chunks) instead of writing to an existing large document.Environment
dist/extensions/feishu/api.jsline 1993