fix(feishu): insert document blocks sequentially to preserve order (#26022)#26172
Conversation
extensions/feishu/src/docx.ts
Outdated
| for (const block of cleaned) { | ||
| const res = await client.docx.documentBlockChildren.create({ | ||
| path: { document_id: docToken, block_id: blockId }, | ||
| data: { children: [block] }, | ||
| }); | ||
| if (res.code !== 0) { | ||
| throw new Error(res.msg); | ||
| } | ||
| allInserted.push(...(res.data?.children ?? [])); | ||
| } |
There was a problem hiding this comment.
If an insertion fails mid-sequence, the document will contain partial content (some blocks inserted, remaining blocks skipped). The batch approach would have been all-or-nothing. Consider wrapping in try/catch to clean up partial inserts on failure, or document this behavior for callers.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/feishu/src/docx.ts
Line: 124-133
Comment:
If an insertion fails mid-sequence, the document will contain partial content (some blocks inserted, remaining blocks skipped). The batch approach would have been all-or-nothing. Consider wrapping in try/catch to clean up partial inserts on failure, or document this behavior for callers.
How can I resolve this? If you propose a fix, please make it concise.|
CI failures are pre-existing on main — |
|
This bug is blocking our documentation workflow. Please consider merging soon. Happy to test if needed. |
…penclaw#26022) The batch documentBlockChildren.create API does not guarantee insertion order, causing blocks to appear in random positions when appending or writing structured content. Switch to sequential single-block inserts so each block is appended in the order it appears in the source markdown.
c73174d to
bb28231
Compare
|
PR #26172 - fix(feishu): insert document blocks sequentially to preserve order (#26022) (#26172) Merged via squash.
Thanks @echoVic! |
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> (cherry picked from commit 41d3e77)
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> (cherry picked from commit 41d3e77)
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> (cherry picked from commit 41d3e77)
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> (cherry picked from commit b28344e)
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> (cherry picked from commit b28344e)
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…penclaw#26022) (openclaw#26172) thanks @echoVic Verified: - pnpm build - pnpm check - pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts Co-authored-by: echoVic <16428813+echoVic@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
Problem
When using
feishu_docwithaction: "append"oraction: "write", blocks appear in random order instead of the order specified in the Markdown content.Fixes #26022
Root Cause
documentBlockChildren.createbatch API does not guarantee insertion order when multiple blocks are sent in a single call. Feishu processes the batch asynchronously, resulting in non-deterministic block positions.Fix
Switch from batch insertion (all blocks in one API call) to sequential single-block inserts. Each block is appended one at a time, preserving the source markdown order.
Changes
extensions/feishu/src/docx.ts: Replace batchinsertBlockswith sequential per-block insertionextensions/feishu/src/docx.test.ts: Add test verifying sequential insertion orderTesting
Greptile Summary
This PR fixes block insertion order in Feishu documents by switching from batch API insertion to sequential single-block inserts. The batch API (
documentBlockChildren.createwith multiple children) processes blocks asynchronously without guaranteed ordering. The fix inserts blocks one at a time, appending each to the end, which produces deterministic results that match the source markdown order.The implementation is straightforward:
Confidence Score: 4/5
Last reviewed commit: 276b393