Repository navigation
Fix one data source can be synced to multiple dataset - #16023
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
| @@ -0,0 +1,98 @@ | |||
| #!/bin/bash | |||
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
rag/svr/sync_data_source.py (1)
235-238: ⚡ Quick winAdd 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
📒 Files selected for processing (4)
api/db/services/connector_service.pydocker/launch_backend_service.shdocker/launch_data_sync_service.shrag/svr/sync_data_source.py
| #!/bin/bash | ||
|
|
||
| # Exit immediately if a command exits with a non-zero status | ||
| set -e |
There was a problem hiding this comment.
🧩 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 -100Repository: 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
doneAlso 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.
| 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 | ||
| } |
There was a problem hiding this comment.
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Fix one data source can be synced to multiple dataset
Test add/delete - worked.