Skip to content

fix(feishu): feishu_doc create action now populates content when provided - #48377

Closed
wzx011011 wants to merge 5 commits into
openclaw:mainfrom
wzx011011:fix/feishu-doc-create-content
Closed

wzx011011 wants to merge 5 commits into
openclaw:mainfrom
wzx011011:fix/feishu-doc-create-content

Conversation

@wzx011011

Copy link
Copy Markdown

Summary

Fixes #48373

The feishu_doc create action was silently ignoring the content parameter, creating an empty document with only the title. Agents had to make a separate write call to populate the document.

Root Cause

In extensions/feishu/src/docx.ts, the create case only called createDoc(), which does not accept a content parameter. The p.content value was never referenced.

Fix

The create case now:

  1. Creates the document as before
  2. If content is provided, calls writeDoc() to populate it
  3. Returns merged results (document_id + URL + blocks_added + images_processed)

Changes

- case "create":
-   return json(
-     await createDoc(client, p.title, p.folder_token, {
-       grantToRequester: p.grant_to_requester,
-       requesterOpenId: trustedRequesterOpenId,
-     }),
-   );
+ case "create": {
+   const created = await createDoc(client, p.title, p.folder_token, {
+     grantToRequester: p.grant_to_requester,
+     requesterOpenId: trustedRequesterOpenId,
+   });
+   if (p.content) {
+     const writeResult = await writeDoc(
+       client,
+       created.document_id,
+       p.content,
+       getMediaMaxBytes(p, defaultAccountId),
+       api.logger,
+     );
+     return json({ ...created, ...writeResult });
+   }
+   return json(created);
+ }

Testing

  • Verified locally that createDoc() signature and writeDoc() parameters match the existing codebase
  • The fix reuses the existing writeDoc() function which handles markdown conversion, chunked insertion, and image processing
  • No changes to the schema or public API — this is purely a behavior fix

🤖 Submitted by 小欧 🦊

Copilot AI review requested due to automatic review settings March 16, 2026 17:02
@openclaw-barnacle openclaw-barnacle Bot added channel: feishu Channel integration: feishu size: XL labels Mar 16, 2026
@greptile-apps

greptile-apps Bot commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug in the feishu_doc create action where the content parameter was silently ignored, resulting in documents that were always created empty. The fix correctly calls writeDoc() after createDoc() when content is supplied, and merges both results into the response.

Key observations:

  • The core fix is correct and well-scoped — it reuses the existing writeDoc() function which already handles markdown conversion, chunked insertion, and image processing.
  • The spread merge { ...created, ...writeResult } is safe; there are no key conflicts between the two return objects.
  • writeDoc() unconditionally calls clearDocumentContent() first (an extra list + potential batch-delete API call). For a brand-new document this is a no-op, but it adds unnecessary API roundtrips on every create + content call.
  • The merged response will include a blocks_deleted: 0 field, which may confuse callers of the create action since no blocks were ever deleted from a new document.

Confidence Score: 4/5

  • This PR is safe to merge — it is a targeted behavior fix with no schema or API changes.
  • The fix is logically correct and directly addresses the stated bug. The only concern is a minor inefficiency: writeDoc() calls clearDocumentContent() unnecessarily for a new document, and the resulting response includes a misleading blocks_deleted: 0 field. No critical logic errors or security issues were found.
  • No files require special attention beyond the single changed file extensions/feishu/src/docx.ts.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/feishu/src/docx.ts
Line: 1322-1330

Comment:
**Unnecessary `clearDocumentContent` call and misleading `blocks_deleted` in response**

`writeDoc()` always calls `clearDocumentContent()` as its first step (line 825), which lists the document's blocks and then issues a batch-delete request. For a freshly-created document this produces zero deletions, but it still fires two extra API calls (a list + a no-op delete) on every `create` + `content` invocation.

Additionally, the spread `{ ...created, ...writeResult }` will include `blocks_deleted: 0` in the returned JSON. Callers of the `create` action are likely to find this field confusing or misleading, since no blocks were ever deleted.

Two possible improvements:
1. Exclude `blocks_deleted` from the merged result when calling from `create`:
```suggestion
                  if (p.content) {
                    const writeResult = await writeDoc(
                      client,
                      created.document_id,
                      p.content,
                      getMediaMaxBytes(p, defaultAccountId),
                      api.logger,
                    );
                    const { blocks_deleted: _bd, ...writeResultWithoutDeleted } = writeResult;
                    return json({ ...created, ...writeResultWithoutDeleted });
                  }
```
2. Alternatively, extract an `appendOnlyDoc` helper (similar to `appendDoc`) that skips the clear step, and call that from `create` instead of `writeDoc`.

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: 4d6accc

Comment thread extensions/feishu/src/docx.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes feishu_doc’s create action so that when content is provided, the tool immediately writes the provided markdown into the newly created Feishu Doc (instead of creating a title-only document and requiring a second write call).

Changes:

  • Update feishu_doc create action to call writeDoc() after createDoc() when content is provided.
  • Return a merged response containing both document metadata (id/url) and write results (e.g., blocks/images processed).

You can also share your feedback on Copilot code review. Take the survey.

Comment thread extensions/feishu/src/docx.ts Resolved
Comment thread extensions/feishu/src/docx.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4d6accc891

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread extensions/feishu/src/docx.ts Resolved
Comment thread extensions/feishu/src/docx.ts Resolved
@wzx011011
wzx011011 force-pushed the fix/feishu-doc-create-content branch from 332be61 to b82fc86 Compare March 24, 2026 10:03
@clawsweeper

clawsweeper Bot commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Latest ClawSweeper review: 2026-05-22 08:52 UTC / May 22, 2026, 4:52 AM ET.

Workflow note: Future ClawSweeper reviews update this same comment in place.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

Summary
The PR updates feishu_doc create to accept optional initial markdown content, writes it through writeDoc, and updates Feishu schema, skill docs, mocked tests, and changelog text.

Reproducibility: yes. Source inspection on current main gives a high-confidence path: pass action: "create", title, and content; the dispatcher reaches the create branch and returns after createDoc without writing or rejecting the content.

PR rating
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🦐 gold shrimp
Summary: The branch addresses the right code path with tests, but missing real Feishu proof and an unresolved partial-write failure contract keep it below merge-ready.

Rank-up moves:

  • Add redacted live Feishu proof showing a create call with content and the populated document result.
  • Preserve created document metadata or roll back the new document when the follow-up write fails.
  • Refresh the branch against current main and rerun focused Feishu validation after the repair.
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Real behavior proof
Needs real behavior proof before merge: The PR has mocked tests and validation comments, but no redacted live Feishu screenshot, recording, terminal output, linked artifact, or log showing create-with-content after the patch; redact private details and update the PR body to trigger re-review, or ask a maintainer to comment @clawsweeper re-review.

Mantis proof suggestion
A visible Feishu document or redacted terminal/log proof would materially verify that create-with-content populates a real document. A maintainer can ask Mantis to capture proof by posting a new PR comment that starts with the OpenClaw Mantis account mention, followed by:

visual task: verify that feishu_doc create with content creates a Feishu document whose initial markdown appears in the document.

Risk before merge

  • No redacted live Feishu proof shows that create-with-content populates a real document after this patch; current proof is mocked tests, PR text, and CI metadata only.
  • If writeDoc fails after createDoc succeeds, callers can receive only { error } and lose the new document id and URL, encouraging duplicate retry-created documents.
  • The branch is currently conflicting with main and has stale failed checks, so conflict repair and fresh validation are required before merge.
  • Merging changes create-with-content from a metadata-only success into additional Feishu write/media calls; that is likely the right bug fix, but the partial-failure contract needs to be explicit.

Maintainer options:

  1. Repair and prove create-with-content (recommended)
    Preserve created document metadata or roll back on write failure, refresh the branch against main, rerun focused Feishu validation, and attach redacted real Feishu proof before merge.
  2. Accept the new create-time write contract
    Maintainers can intentionally accept that create-with-content performs write/media API calls, but should do so only after the partial-failure behavior is documented or considered acceptable.
  3. Pause or replace the branch
    Keep this PR unmerged or replace it if no one can provide live Feishu proof and bring the branch current with main.

Next step before merge
Manual review/proof remains the right lane because this external PR lacks real-behavior proof, conflicts with main, and needs a maintainer-visible decision or repair for the create-then-write partial-failure contract.

Security
Cleared: The diff stays within Feishu plugin runtime, schema, skill docs, tests, and changelog text, with no new dependencies, CI, secrets, publishing, or third-party execution surfaces.

Review findings

  • [P2] Preserve created metadata when content write fails — extensions/feishu/src/docx.ts:1481-1487
Review details

Best possible solution:

Land a refreshed Feishu plugin change that writes create-time markdown through the existing write path, preserves created metadata or rolls back on write failure, and includes redacted real Feishu proof; otherwise reject content on create with a clear error.

Do we have a high-confidence way to reproduce the issue?

Yes. Source inspection on current main gives a high-confidence path: pass action: "create", title, and content; the dispatcher reaches the create branch and returns after createDoc without writing or rejecting the content.

Is this the best way to solve the issue?

No, not yet. Create-plus-write through the existing writeDoc path is the maintainable direction, but this branch should preserve created metadata or roll back if the follow-up write fails, resolve conflicts, and include real Feishu proof before merge.

Label justifications:

  • P2: This is a normal-priority Feishu plugin bug fix with user-visible silently dropped document content and limited channel-specific blast radius.
  • merge-risk: 🚨 compatibility: The PR changes create-with-content from a successful metadata-only response into additional Feishu write/media calls that can fail after creating a document unless the partial-failure contract is repaired.
  • rating: 🧂 unranked krab: Current PR rating is 🧂 unranked krab because proof is 🧂 unranked krab, patch quality is 🦐 gold shrimp, and The branch addresses the right code path with tests, but missing real Feishu proof and an unresolved partial-write failure contract keep it below merge-ready.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR has mocked tests and validation comments, but no redacted live Feishu screenshot, recording, terminal output, linked artifact, or log showing create-with-content after the patch; redact private details and update the PR body to trigger re-review, or ask a maintainer to comment @clawsweeper re-review.

Full review comments:

  • [P2] Preserve created metadata when content write fails — extensions/feishu/src/docx.ts:1481-1487
    This branch creates the Feishu document before awaiting writeDoc. If clearing, conversion, insertion, or media handling throws, the outer catch returns only { error }, hiding the already-created document_id and URL and encouraging duplicate retries; return the created metadata with the write error, or roll back the new document if Feishu supports it.
    Confidence: 0.87

Overall correctness: patch is incorrect
Overall confidence: 0.87

Acceptance criteria:

  • node scripts/run-vitest.mjs extensions/feishu/src/docx.test.ts
  • node scripts/crabbox-wrapper.mjs run --shell -- "pnpm check:changed"
  • Redacted live Feishu create-with-content proof from a real setup

What I checked:

  • Current main create dispatcher ignores content: On current main, the create branch returns createDoc(...) directly; it does not read p.content, call writeDoc, or reject a supplied content key. (extensions/feishu/src/docx.ts:1450, 25e489395ab0)
  • Create schema omits content on main: The current create variant declares title, folder_token, and grant_to_requester; content is only declared on other actions. (extensions/feishu/src/doc-schema.ts:42, 25e489395ab0)
  • Flattened tool schemas can still carry broad fields: The agent tool schema flattener merges union properties and defaults top-level additionalProperties to true, so broad agent-facing calls can carry a content field to the dispatcher. (src/agents/pi-tools-parameter-schema.ts:831, 25e489395ab0)
  • PR head implements the intended create-time write path: At PR head, the create branch creates the document, checks for an own content key, calls writeDoc, strips blocks_deleted, and returns merged create/write metadata. (extensions/feishu/src/docx.ts:1474, 46c89af33496)
  • PR adds mocked regression coverage: The PR adds tests for non-empty create content, explicit empty content, and omitting blocks_deleted from create responses. (extensions/feishu/src/docx.test.ts:434, 46c89af33496)
  • Partial write failure can hide created metadata: The PR awaits writeDoc after createDoc; if clear, conversion, insertion, or media handling fails, the surrounding dispatcher catch returns only { error }, hiding the already-created document id and URL. (extensions/feishu/src/docx.ts:1481, 46c89af33496)

Likely related people:

  • xuhao1: Authored the merged Feishu Docx action expansion that added the central feishu_doc create/write runtime, schema, tests, and skill documentation touched by this PR. (role: introduced behavior; confidence: high; commits: 56fa05838a03; files: extensions/feishu/src/docx.ts, extensions/feishu/src/doc-schema.ts, extensions/feishu/src/docx.test.ts)
  • Takhoffman: Authored trusted-requester create-grant hardening in the same create branch area and was explicitly pulled into the earlier create-with-content discussion. (role: adjacent contributor and prior discussion participant; confidence: high; commits: bbab94c1fead; files: extensions/feishu/src/docx.ts, extensions/feishu/src/doc-schema.ts, extensions/feishu/src/docx.test.ts)
  • Elarwei001: Authored the merged markdown/table/insert refactor that shaped the writeDoc path reused by this create-with-content fix. (role: major write-path refactor author; confidence: medium; commits: 0740fb83d761; files: extensions/feishu/src/docx.ts, extensions/feishu/src/doc-schema.ts, extensions/feishu/src/docx.test.ts)
  • vincentkoc: Pushed the latest narrow repair commit on this PR branch and commented that the original contributor path should stay canonical. (role: recent branch repairer; confidence: medium; commits: 46c89af33496; files: extensions/feishu/src/docx.ts, extensions/feishu/src/doc-schema.ts, extensions/feishu/src/docx.test.ts)

Codex review notes: model gpt-5.5, reasoning high; reviewed against 25e489395ab0.

wzx011011 and others added 5 commits April 28, 2026 18:38
…ided

- Create case now calls writeDoc() if content is provided
- Strips blocks_deleted from merged response (new doc has no deletions)
- Rebased onto latest upstream/main

Co-authored-by: 小欧 🦊 <[email protected]>
Lint/check step rejects bare underscore _ as unused variable.
Rename to 'omitted' and use void to suppress the warning.
TS2339: Property 'content' does not exist on type.
The create action schema was missing the optional content field.
Break long Type.Optional line to match project convention.
@vincentkoc
vincentkoc force-pushed the fix/feishu-doc-create-content branch from 93630c1 to 46c89af Compare April 28, 2026 18:38
@vincentkoc

Copy link
Copy Markdown
Member

ProjectClownfish pushed a narrow repair to this branch so the original contributor path can stay canonical.

Source PR: #48377
Validation: pnpm check:changed; pnpm test:extensions
Contributor credit is preserved in the branch history and PR context.

@vincentkoc vincentkoc added clawsweeper Tracked by ClawSweeper automation and removed clownfish:merge-ready labels Apr 28, 2026
@clawsweeper clawsweeper Bot added the P2 Normal backlog priority with limited blast radius. label May 17, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 17, 2026
@clawsweeper clawsweeper Bot added impact:data-loss Can lose, corrupt, or silently drop user/session/config data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed impact:data-loss Can lose, corrupt, or silently drop user/session/config data. labels May 17, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jun 6, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu clawsweeper Tracked by ClawSweeper automation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feishu_doc create action silently ignores content parameter — creates empty document

3 participants