Skip to content

Fix one data source can be synced to multiple dataset - #16023

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
wangq8:bugfix/fix-data-source-sync-issues
Jun 15, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
wangq8:bugfix/fix-data-source-sync-issues

Conversation

@wangq8

@wangq8 wangq8 commented Jun 15, 2026 •

Copy link
Copy Markdown
Collaborator

Fix one data source can be synced to multiple dataset
Test add/delete - worked.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e1a9f466-6935-4f7e-8aa6-b1bfb1e8e8fd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)

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 and usage tips.

@@ -0,0 +1,98 @@
#!/bin/bash

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ignore this file.

Comment thread docker/launch_backend_service.sh Resolved
@wangq8 wangq8 added the ci Continue Integration label Jun 15, 2026
@wangq8
wangq8 requested a review from buua436 June 15, 2026 08:07
@wangq8
wangq8 marked this pull request as ready for review June 15, 2026 08:07
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 15, 2026

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
rag/svr/sync_data_source.py (1)

235-238: ⚡ Quick win

Add migration visibility logs for legacy-vs-new document ID selection.

The dual-ID migration branch is new behavior, but there’s no telemetry showing how often legacy IDs are still selected or matched in fingerprint lookups. Add lightweight counters and log them per task to make rollout health observable.

As per coding guidelines, **/*.py: Add logging for new flows.

Also applies to: 406-409

🤖 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 `@rag/svr/sync_data_source.py` around lines 235 - 238, The dual-ID migration
logic in the document ID selection does not have visibility into how often
legacy IDs versus new IDs are being chosen. Add lightweight counters to track
legacy ID selection versus new ID selection, and log these counters per task to
make the migration rollout health observable. This applies at the site where
legacy_doc_id and new_doc_id are compared in the conditional (around lines
235-238) and also at the sibling location (around lines 406-409) where similar
ID selection logic exists. For each site, increment appropriate counters based
on whether legacy_doc_id is found in existing_doc_ids or not, and ensure
task-level logging includes these migration metrics.

Source: Coding guidelines

🤖 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 `@docker/launch_data_sync_service.sh`:
- Around line 54-65: The cleanup() function always exits with status 0, causing
the script to report success even when called due to hard failures. Modify
cleanup() to accept an exit code parameter (defaulting to 0 for normal
termination), and use that parameter in the exit statement instead of hardcoding
0. Then update all call sites of cleanup() - particularly those in the error
handling around lines 87-90 that are triggered on hard failures - to pass an
appropriate non-zero exit code (such as 1) to cleanup() when invoked due to
failures, ensuring supervisors correctly interpret failed launcher executions as
unsuccessful.
- Line 4: The `set -e` option at line 4 causes the script to immediately exit
when sync_data_source.py returns a non-zero exit code, preventing the retry loop
logic from executing and capturing the EXIT_CODE. Remove or refactor the `set
-e` to allow the script to continue execution after failures so the retry count
increment and loop logic can evaluate. Additionally, modify the cleanup()
function to exit with a non-zero status code when max retries have been
exhausted rather than exiting with code 0, so orchestrators receive proper
failure signals when the data sync ultimately fails.

---

Nitpick comments:
In `@rag/svr/sync_data_source.py`:
- Around line 235-238: The dual-ID migration logic in the document ID selection
does not have visibility into how often legacy IDs versus new IDs are being
chosen. Add lightweight counters to track legacy ID selection versus new ID
selection, and log these counters per task to make the migration rollout health
observable. This applies at the site where legacy_doc_id and new_doc_id are
compared in the conditional (around lines 235-238) and also at the sibling
location (around lines 406-409) where similar ID selection logic exists. For
each site, increment appropriate counters based on whether legacy_doc_id is
found in existing_doc_ids or not, and ensure task-level logging includes these
migration metrics.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 219f3b2f-6116-4233-94f9-ac6de2e58af2

📥 Commits

Reviewing files that changed from the base of the PR and between e3cb86d and 24a7e47.

📒 Files selected for processing (4)
  • api/db/services/connector_service.py
  • docker/launch_backend_service.sh
  • docker/launch_data_sync_service.sh
  • rag/svr/sync_data_source.py

#!/bin/bash

# Exit immediately if a command exits with a non-zero status
set -e

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.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verifies that `set -e` aborts before manual `$?` retry handling when command fails.
set -euo pipefail
tmp="$(mktemp)"
cat > "$tmp" <<'EOF'
#!/bin/bash
set -e
retry=0
while [ "$retry" -lt 3 ]; do
  echo "attempt:$retry"
  false
  code=$?
  retry=$((retry+1))
  echo "code:$code"
done
EOF
bash "$tmp"

Repository: infiniflow/ragflow

Length of output: 72


🏁 Script executed:

cat docker/launch_data_sync_service.sh | head -100

Repository: infiniflow/ragflow

Length of output: 2625


set -e prevents the retry loop from executing.

At line 75, a non-zero exit from sync_data_source.py causes immediate script termination before EXIT_CODE can be captured and retry logic evaluated. The script never reaches the retry count increment or loop re-entry.

Additionally, when max retries are exhausted, cleanup() exits with code 0 (line 64), masking the hard failure from orchestrators.

Proposed fix
 run_server(){
     local retry_count=0
     while ! $STOP && [ $retry_count -lt $MAX_RETRIES ]; do
         echo "Starting sync_data_source.py (Attempt $((retry_count+1)))"
-        $PY rag/svr/sync_data_source.py
-        EXIT_CODE=$?
-        if [ $EXIT_CODE -eq 0 ]; then
+        if $PY rag/svr/sync_data_source.py; then
             echo "sync_data_source.py exited successfully."
             break
         else
+            EXIT_CODE=$?
             echo "sync_data_source.py failed with exit code $EXIT_CODE. Retrying..." >&2
             retry_count=$((retry_count + 1))
             sleep 2
         fi
     done

Also consider exiting with non-zero status when max retries fail to signal orchestrators of the failure.

🤖 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 `@docker/launch_data_sync_service.sh` at line 4, The `set -e` option at line 4
causes the script to immediately exit when sync_data_source.py returns a
non-zero exit code, preventing the retry loop logic from executing and capturing
the EXIT_CODE. Remove or refactor the `set -e` to allow the script to continue
execution after failures so the retry count increment and loop logic can
evaluate. Additionally, modify the cleanup() function to exit with a non-zero
status code when max retries have been exhausted rather than exiting with code
0, so orchestrators receive proper failure signals when the data sync ultimately
fails.

Comment on lines +54 to +65
cleanup() {
echo "Termination signal received. Shutting down..."
STOP=true
# Terminate all child processes
for pid in "${PIDS[@]}"; do
if kill -0 "$pid" 2>/dev/null; then
echo "Killing process $pid"
kill "$pid"
fi
done
exit 0
}

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Failure after max retries should not exit with status 0.

cleanup() always exits 0, and Line 89 calls it on hard failure, so supervisors can misclassify a failed launcher as successful.

Proposed fix
 cleanup() {
+  local exit_code="${1:-0}"
   echo "Termination signal received. Shutting down..."
   STOP=true
   # Terminate all child processes
   for pid in "${PIDS[@]}"; do
@@
       kill "$pid"
     fi
   done
-  exit 0
+  exit "$exit_code"
 }
@@
     if [ $retry_count -ge $MAX_RETRIES ]; then
         echo "sync_data_source.py failed after $MAX_RETRIES attempts. Exiting..." >&2
-        cleanup
+        cleanup 1
     fi
 }

Also applies to: 87-90

🤖 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 `@docker/launch_data_sync_service.sh` around lines 54 - 65, The cleanup()
function always exits with status 0, causing the script to report success even
when called due to hard failures. Modify cleanup() to accept an exit code
parameter (defaulting to 0 for normal termination), and use that parameter in
the exit statement instead of hardcoding 0. Then update all call sites of
cleanup() - particularly those in the error handling around lines 87-90 that are
triggered on hard failures - to pass an appropriate non-zero exit code (such as
1) to cleanup() when invoked due to failures, ensuring supervisors correctly
interpret failed launcher executions as unsuccessful.

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (de06c9a) to head (24a7e47).
⚠️ Report is 30 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16023   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8
wangq8 merged commit f6a2075 into infiniflow:main Jun 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants