Skip to content

feat(docx): refine history restore flow with revision-fetch fallback - #2127

Open
yballul-bytedance wants to merge 1 commit into
larksuite:mainfrom
yballul-bytedance:auto-research-sync/01KYSRNXC7EG74JKVFN4BKMMKA/mr-1340-d83cc2d5
Open

feat(docx): refine history restore flow with revision-fetch fallback#2127
yballul-bytedance wants to merge 1 commit into
larksuite:mainfrom
yballul-bytedance:auto-research-sync/01KYSRNXC7EG74JKVFN4BKMMKA/mr-1340-d83cc2d5

Conversation

@yballul-bytedance

@yballul-bytedance yballul-bytedance commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

Refines the Docx history restore guidance in skills/lark-doc/references/lark-doc-history.md so the restore path is an explicit, bounded either/or decision instead of an unconditional history-revert sequence. When an exact history entry exists, the flow still uses +history-revert; when no exact entry exists but the target revision is readable, it adds a safe docs +fetchoverwrite → verify fallback.

Changes

  • Rewrote the 安全流程 (safe flow) steps to branch on whether an exact history entry is found: exact entry → +history-revert with polling; no exact entry → revision-fetch fallback with faithful content replay, or stop honestly on unreadable/error revisions.
  • Documented that overwrite clears and rebuilds the body (block IDs invalidated, non-body objects such as comments may be lost) and required explicit confirmation before claiming lossless restore.
  • Added a final verification step that re-fetches the full document and compares content plus a replayable reference_map against the target revision.
  • Extended the 按 revision_id 或时间点回滚 section with a fail-closed bash recipe: isolated mktemp -d working dirs, target/current document_id guard, current revision_id as an optimistic lock, reference_map sidecar replay, and a Python content/reference-map comparison that fails closed on mismatch.
  • Added guidance that the restore path is strictly binary and must not guess neighboring versions or substitute large probe scripts / repeated help reads for the bounded flow.

Test Plan

  • Documentation-only change to a skill reference Markdown file; no code paths affected.
  • git diff --check passes (no whitespace errors or conflict markers).

Related Issues

Auto research task: 01KYSRNXC7EG74JKVFN4BKMMKA

Summary by CodeRabbit

  • Documentation
    • Updated rollback guidance to distinguish exact history matches from revision-fetch fallback.
    • Added safeguards for validating documents and revisions before restoration.
    • Documented temporary workspace isolation, optimistic locking, and safe reference handling.
    • Clarified verification steps and how failures or partial preservation are handled.

Clarify the bounded restore path in the lark-doc history reference:
prefer an exact history entry for +history-revert, and when no exact
entry exists but the target revision is readable, fall back to fetching
the target revision and overwriting the current document with faithful
content/reference_map replay, optimistic revision locking, and
post-write verification against the target revision.

Co-authored-by: TRAE CLI <noreply@bytedance.com>
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The rollback guidance now distinguishes exact history reverts from revision-based fallback restoration. The fallback fetches and validates target data, applies an optimistic-locked overwrite, verifies content and references, and handles conflicts or fidelity failures.

Changes

Rollback restoration

Layer / File(s) Summary
History matching and rollback selection
skills/lark-doc/references/lark-doc-history.md
The procedure matches exact history entries, polls running history-revert-status tasks, and selects revision fallback when needed.
Revision fetch and validation
skills/lark-doc/references/lark-doc-history.md
The fallback creates isolated temporary directories, fetches readable target revisions, and preserves content with its reference map.
Locked overwrite and restoration verification
skills/lark-doc/references/lark-doc-history.md
The fallback validates document identity and revision state, overwrites through supported arguments, verifies content and references, rejects path escapes or mismatches, and cleans up temporary files.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: liangshuo-1

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the refined history restore flow and its revision-fetch fallback.
Description check ✅ Passed The description includes all required sections and clearly explains the documentation changes and verification performed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added domain/ccm PR touches the ccm domain size/M Single-domain feat or fix with limited business impact labels Jul 31, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@skills/lark-doc/references/lark-doc-history.md`:
- Around line 10-15: Update the history restore flow around +history-revert and
+history-revert-status so only status: done proceeds to post-restore
verification; failed, partial_failed, and other terminal non-success statuses
must stop without reporting restoration. For the exact-entry path, obtain and
retain the target document snapshot, including content and reference_map, so the
final docs +fetch verification can compare against it.
- Around line 47-51: Strengthen target response validation before the extraction
commands: in the revision-check jq expression, require that
.data.document.content is a string in addition to matching target_revision_id.
Keep the existing failure behavior so jq -j does not run when content is missing
or null, preventing target-content.xml from being overwritten with invalid data.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e0bbf0ce-5236-46ad-930f-a36659385a23

📥 Commits

Reviewing files that changed from the base of the PR and between fa9c30c and 779b47e.

📒 Files selected for processing (1)
  • skills/lark-doc/references/lark-doc-history.md

Comment on lines +10 to +15
4. **有精确 history entry**:用该条目的 `history_version_id` 调用 `+history-revert`。不要猜测或使用邻近条目。默认最多等待 30 秒;如果返回 `status: running`,记录 `task_id`,再用 `+history-revert-status` 轮询到终态。
5. **没有精确 history entry**:不要直接停止。若用户给出了目标 `revision_id`,尝试一次 `docs +fetch --revision-id <revision_id> --detail full --format json`:
- 成功返回目标 revision 的真实完整内容:将同一次响应的 `data.document.content` 与 `data.document.reference_map` 配套保存并用于 `docs +update --command overwrite`,不得根据摘要、缓存、模型记忆或硬编码重建正文。
- 目标 revision 明确不可读或返回业务错误:停止并如实说明。权限、网络或临时系统错误保持原分类,不要据此声称 revision 不存在,也不要绕过身份、权限或确认门禁。
6. `overwrite` 会清空并重建正文,旧 block ID 会失效,当前版本中未包含在目标 fetch 响应里的评论等非正文对象可能丢失。用户明确要求整篇版本恢复时可以替换正文;若还要求保留当前评论或其它未包含在 fetch 响应里的对象,先说明该 fallback 无法保证保留并确认,不得宣称无损恢复。
7. 恢复完成后,用 `docs +fetch --detail full --format json` 读取最新完整文档,验证 `content` 和可回放的 `reference_map` 均与目标 revision 的真实返回一致。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Only treat status: done as a successful history restore.

The flow currently polls any terminal status and then proceeds to post-restore verification. partial_failed and failed must stop the success flow and must not be reported as restored. The exact-entry path also needs a defined target document snapshot if verification must compare content and reference_map with the target revision.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@skills/lark-doc/references/lark-doc-history.md` around lines 10 - 15, Update
the history restore flow around +history-revert and +history-revert-status so
only status: done proceeds to post-restore verification; failed, partial_failed,
and other terminal non-success statuses must stop without reporting restoration.
For the exact-entry path, obtain and retain the target document snapshot,
including content and reference_map, so the final docs +fetch verification can
compare against it.

Comment on lines +47 to +51
jq -e --arg revision_id "$target_revision_id" \
'.data.document.revision_id | tostring == $revision_id' \
"$doc_restore_tmp/target/target-revision.json" > /dev/null
jq -j '.data.document.content' "$doc_restore_tmp/target/target-revision.json" > "$doc_restore_tmp/target/target-content.xml"
jq '.data.document.reference_map // {}' "$doc_restore_tmp/target/target-revision.json" > "$doc_restore_tmp/target/target-reference-map.json"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Reject incomplete target responses before overwrite.

The revision check validates only revision_id. jq -j can still succeed when content is missing or null, which can write the literal null into target-content.xml and start a destructive overwrite. Require a string content value before extracting it.

Proposed validation
-jq -j '.data.document.content' "$doc_restore_tmp/target/target-revision.json" > "$doc_restore_tmp/target/target-content.xml"
+jq -er '.data.document.content | select(type == "string")' \
+  "$doc_restore_tmp/target/target-revision.json" > "$doc_restore_tmp/target/target-content.xml"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
jq -e --arg revision_id "$target_revision_id" \
'.data.document.revision_id | tostring == $revision_id' \
"$doc_restore_tmp/target/target-revision.json" > /dev/null
jq -j '.data.document.content' "$doc_restore_tmp/target/target-revision.json" > "$doc_restore_tmp/target/target-content.xml"
jq '.data.document.reference_map // {}' "$doc_restore_tmp/target/target-revision.json" > "$doc_restore_tmp/target/target-reference-map.json"
jq -e --arg revision_id "$target_revision_id" \
'.data.document.revision_id | tostring == $revision_id' \
"$doc_restore_tmp/target/target-revision.json" > /dev/null
jq -er '.data.document.content | select(type == "string")' \
"$doc_restore_tmp/target/target-revision.json" > "$doc_restore_tmp/target/target-content.xml"
jq '.data.document.reference_map // {}' "$doc_restore_tmp/target/target-revision.json" > "$doc_restore_tmp/target/target-reference-map.json"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@skills/lark-doc/references/lark-doc-history.md` around lines 47 - 51,
Strengthen target response validation before the extraction commands: in the
revision-check jq expression, require that .data.document.content is a string in
addition to matching target_revision_id. Keep the existing failure behavior so
jq -j does not run when content is missing or null, preventing
target-content.xml from being overwritten with invalid data.

@github-actions

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@779b47e764a8fd88900a19955376273b8218931b

🧩 Skill update

npx skills add yballul-bytedance/cli#auto-research-sync/01KYSRNXC7EG74JKVFN4BKMMKA/mr-1340-d83cc2d5 -y -g

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

Labels

domain/ccm PR touches the ccm domain size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant