Skip to content

fix(feishu): insert document blocks sequentially to preserve order (#26022)#26172

Merged
Takhoffman merged 3 commits intoopenclaw:mainfrom
echoVic:fix/feishu-doc-block-ordering
Feb 28, 2026
Merged

fix(feishu): insert document blocks sequentially to preserve order (#26022)#26172
Takhoffman merged 3 commits intoopenclaw:mainfrom
echoVic:fix/feishu-doc-block-ordering

Conversation

@echoVic
Copy link
Contributor

@echoVic echoVic commented Feb 25, 2026

Problem

When using feishu_doc with action: "append" or action: "write", blocks appear in random order instead of the order specified in the Markdown content.

Fixes #26022

Root Cause

documentBlockChildren.create batch 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 batch insertBlocks with sequential per-block insertion
  • extensions/feishu/src/docx.test.ts: Add test verifying sequential insertion order

Testing

  • Existing test passes (image fetch hardening)
  • New test verifies: 3 blocks → 3 sequential API calls, each with exactly 1 block in correct order

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.create with 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:

  • Replaced single batch API call with a loop that makes one API call per block
  • Added clear inline comments explaining why sequential insertion is necessary
  • Added comprehensive test coverage verifying the sequential behavior
  • Error handling remains intact (throws on first failure)

Confidence Score: 4/5

  • This PR is safe to merge with one minor consideration around partial failures
  • The fix correctly addresses the ordering issue with a well-tested solution. However, there's a potential edge case: if insertion fails mid-sequence, the document will be left in a partially-inserted state (some blocks added, others not), whereas the batch approach would be all-or-nothing. This is a minor trade-off for correctness, but worth noting for production scenarios with large documents.
  • No files require special attention

Last reviewed commit: 276b393

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines 124 to 133
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 ?? []));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@echoVic
Copy link
Contributor Author

echoVic commented Feb 25, 2026

CI failures are pre-existing on main — run.skill-filter.test.ts (missing setSessionRuntimeModel mock), model-fallback.test.ts, and web-tools.enabled-defaults.test.ts. None related to this PR's changes.

@learnpythontheew
Copy link

This bug is blocking our documentation workflow. Please consider merging soon. Happy to test if needed.

echoVic and others added 3 commits February 27, 2026 22:25
…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.
@Takhoffman Takhoffman force-pushed the fix/feishu-doc-block-ordering branch 2 times, most recently from c73174d to bb28231 Compare February 28, 2026 04:46
@Takhoffman Takhoffman merged commit b28344e into openclaw:main Feb 28, 2026
20 of 21 checks passed
@Takhoffman
Copy link
Contributor

PR #26172 - fix(feishu): insert document blocks sequentially to preserve order (#26022) (#26172)

Merged via squash.

  • Merge commit: b28344e
  • Verified: pnpm build, pnpm check, pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/docx.test.ts
  • Changes made:
  • CHANGELOG.md\n- extensions/feishu/src/docx.ts\n- extensions/feishu/src/docx.test.ts
  • Why these changes were made:
  • Rebased onto current main and resolved insertBlocks conflict by preserving sequential block inserts while retaining optional index handling.\n- Added changelog entry required by merge policy.\n- Fixed docx test registration lookup so the new sequential-order test executes correctly and does not leak one-time mocks into subsequent tests.
  • Changelog: CHANGELOG.md updated=true required=true opt_out=false

Thanks @echoVic!

r4jiv007 pushed a commit to r4jiv007/openclaw that referenced this pull request Feb 28, 2026
…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>
mylukin pushed a commit to mylukin/openclaw that referenced this pull request Feb 28, 2026
…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>
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 28, 2026
…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>
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 28, 2026
…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)
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 28, 2026
…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)
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Feb 28, 2026
…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)
vincentkoc pushed a commit to Sid-Qin/openclaw that referenced this pull request Feb 28, 2026
…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>
vincentkoc pushed a commit to rylena/rylen-openclaw that referenced this pull request Feb 28, 2026
…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>
newtontech pushed a commit to newtontech/openclaw-fork that referenced this pull request Feb 28, 2026
…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>
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Mar 1, 2026
…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>
wanjizheng pushed a commit to wanjizheng/openclaw that referenced this pull request Mar 1, 2026
…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>
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 1, 2026
…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)
ansh pushed a commit to vibecode/openclaw that referenced this pull request Mar 2, 2026
…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>
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
…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>
safzanpirani pushed a commit to safzanpirani/clawdbot that referenced this pull request Mar 2, 2026
…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>
steipete pushed a commit to Sid-Qin/openclaw that referenced this pull request Mar 2, 2026
…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>
venjiang pushed a commit to venjiang/openclaw that referenced this pull request Mar 2, 2026
…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>
robertchang-ga pushed a commit to robertchang-ga/openclaw that referenced this pull request Mar 2, 2026
…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>
execute008 pushed a commit to execute008/openclaw that referenced this pull request Mar 2, 2026
…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>
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 3, 2026
…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)
dorgonman pushed a commit to kanohorizonia/openclaw that referenced this pull request Mar 3, 2026
…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>
sachinkundu pushed a commit to sachinkundu/openclaw that referenced this pull request Mar 6, 2026
…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>
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…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>
Mateljan1 pushed a commit to Mateljan1/openclaw that referenced this pull request Mar 7, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Feishu Doc: Block ordering is non-deterministic when appending content

3 participants