[PR #630] [MERGED] Fix stale PR translation revert issue #636

Closed
opened 2026-02-16 06:16:12 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langgenius/dify-docs/pull/630
Author: @guchenhe
Created: 12/23/2025
Status: Merged
Merged: 12/24/2025
Merged by: @guchenhe

Base: mainHead: fix/stale-pr-translation-revert


📝 Commits (4)

  • 22e2e8f Fix stale PR translation revert issue
  • 1c396e3 Fix: Use PR's docs.json for finding file positions in navigation
  • d9558d4 Fix EN section not updated when using reference_sha
  • 861917e Also remove deleted files from EN section in stale PR scenario

📊 Changes

2 files changed (+202 additions, -56 deletions)

View changed files

📝 tools/translate/sync_and_translate.py (+90 -4)
📝 tools/translate/translate_pr.py (+112 -52)

📄 Description

Summary

Fixes the issue where translation PRs for stale source PRs would revert changes from PRs that were merged after the source PR was created.

Reported scenario:

  1. PR A is created before PR B
  2. PR B deletes content a, adds content b, modifies content c
  3. PR B is merged first
  4. When processing PR A, the translation PR reverts all of PR B's changes

Example from PR #593:

  • PR #593 only added one file (plugin-logging.mdx)
  • Translation PR #611 attempted to:
    • Delete 11 files (that were added by other PRs)
    • Revert massive docs.json changes (175 deletions)
    • This was because it used PR #593's stale state from before other PRs merged

Root Cause

The translation workflow was using the source PR's complete working directory state (which is a snapshot from when that PR branch was created) rather than applying only the PR's net changes on top of the current main branch.

Problematic code in setup_translation_branch():

# For new branches (buggy):
self.run_git("checkout", "-b", self.sync_branch)
self.run_git("reset", "--soft", "origin/main")
self.run_git("reset")
# This kept PR's working directory which could be stale

For incremental branches: merge_docs_json_for_incremental_update() took the English section from PR HEAD, which was also stale for old PRs.

Fix

  1. For NEW branches: Create branch directly from origin/main instead of from PR's working directory

    self.run_git("checkout", "-b", self.sync_branch, "origin/main")
    
  2. For EXISTING branches: Replace merge_docs_json_for_incremental_update() with _merge_docs_json_from_main() which:

    • Uses main's full structure (includes all recent changes)
    • Preserves translation sections from the translation branch
  3. For BOTH: Selectively checkout only the files that the PR actually changed via new _checkout_pr_changed_files() method, rather than bringing in the entire working directory

Changes

  • _merge_docs_json_from_main(): New method that merges main's structure with branch's translations
  • _checkout_pr_changed_files(): New method that checkouts only PR's changed source files
  • setup_translation_branch(): Updated to start from main for new branches, use new merge logic for existing
  • run_translation_from_sync_plan(): Added call to selective checkout

Testing

  • Syntax validation:
  • Import test:
  • Full testing should be done with a test PR that simulates the stale PR scenario

Test Plan

  • Create a test branch that adds a new file
  • Before merging, make changes to main via another PR
  • Verify the translation PR for the test branch doesn't revert the other changes

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langgenius/dify-docs/pull/630 **Author:** [@guchenhe](https://github.com/guchenhe) **Created:** 12/23/2025 **Status:** ✅ Merged **Merged:** 12/24/2025 **Merged by:** [@guchenhe](https://github.com/guchenhe) **Base:** `main` ← **Head:** `fix/stale-pr-translation-revert` --- ### 📝 Commits (4) - [`22e2e8f`](https://github.com/langgenius/dify-docs/commit/22e2e8fd2c115ac0c5acb8dd2a7e9215da3ef538) Fix stale PR translation revert issue - [`1c396e3`](https://github.com/langgenius/dify-docs/commit/1c396e3e9a4e8672951339c35c12ac7965c43372) Fix: Use PR's docs.json for finding file positions in navigation - [`d9558d4`](https://github.com/langgenius/dify-docs/commit/d9558d4d6b9507d0c34c8574e167ae7d529e641b) Fix EN section not updated when using reference_sha - [`861917e`](https://github.com/langgenius/dify-docs/commit/861917e1bcf864a809ecd3b0f401c2ff0c75ac2c) Also remove deleted files from EN section in stale PR scenario ### 📊 Changes **2 files changed** (+202 additions, -56 deletions) <details> <summary>View changed files</summary> 📝 `tools/translate/sync_and_translate.py` (+90 -4) 📝 `tools/translate/translate_pr.py` (+112 -52) </details> ### 📄 Description ## Summary Fixes the issue where translation PRs for stale source PRs would revert changes from PRs that were merged after the source PR was created. **Reported scenario:** 1. PR A is created before PR B 2. PR B deletes content a, adds content b, modifies content c 3. PR B is merged first 4. When processing PR A, the translation PR reverts all of PR B's changes **Example from PR #593:** - PR #593 only added one file (`plugin-logging.mdx`) - Translation PR #611 attempted to: - Delete 11 files (that were added by other PRs) - Revert massive docs.json changes (175 deletions) - This was because it used PR #593's stale state from before other PRs merged ## Root Cause The translation workflow was using the source PR's complete working directory state (which is a snapshot from when that PR branch was created) rather than applying only the PR's net changes on top of the current main branch. **Problematic code in `setup_translation_branch()`:** ```python # For new branches (buggy): self.run_git("checkout", "-b", self.sync_branch) self.run_git("reset", "--soft", "origin/main") self.run_git("reset") # This kept PR's working directory which could be stale ``` **For incremental branches:** `merge_docs_json_for_incremental_update()` took the English section from PR HEAD, which was also stale for old PRs. ## Fix 1. **For NEW branches:** Create branch directly from `origin/main` instead of from PR's working directory ```python self.run_git("checkout", "-b", self.sync_branch, "origin/main") ``` 2. **For EXISTING branches:** Replace `merge_docs_json_for_incremental_update()` with `_merge_docs_json_from_main()` which: - Uses main's full structure (includes all recent changes) - Preserves translation sections from the translation branch 3. **For BOTH:** Selectively checkout only the files that the PR actually changed via new `_checkout_pr_changed_files()` method, rather than bringing in the entire working directory ## Changes - `_merge_docs_json_from_main()`: New method that merges main's structure with branch's translations - `_checkout_pr_changed_files()`: New method that checkouts only PR's changed source files - `setup_translation_branch()`: Updated to start from main for new branches, use new merge logic for existing - `run_translation_from_sync_plan()`: Added call to selective checkout ## Testing - Syntax validation: ✅ - Import test: ✅ - Full testing should be done with a test PR that simulates the stale PR scenario ## Test Plan - [ ] Create a test branch that adds a new file - [ ] Before merging, make changes to main via another PR - [ ] Verify the translation PR for the test branch doesn't revert the other changes 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 06:16:12 -05:00
yindo closed this issue 2026-02-16 06:16:12 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-docs#636