Skip to content

Go: add more start server parameters - #16093

Merged
JinHai-CN merged 7 commits into
infiniflow:mainfrom
JinHai-CN:fix466
Jun 16, 2026
Merged

JinHai-CN merged 7 commits into
infiniflow:mainfrom
JinHai-CN:fix466

Conversation

@JinHai-CN

@JinHai-CN JinHai-CN commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

What problem does this PR solve?

$ ./bin/ragflow_server --version 
RAGFlow version: v0.26.0-65-g549f6109c

$ ./bin/ragflow_server --debug # start server with debug log level

$ ./bin/admin_server --version 
RAGFlow version: v0.26.0-65-g549f6109c

$ ./bin/admin_server --debug # start server with debug log level

$ ./bin/admin_server --init-superuser # init default superuser

$ ./bin/ingestor --version
RAGFlow version: v0.26.0-68-g6f6c39706

$ ./bin/ingestor --debug

Type of change

  • New Feature (non-breaking change which adds functionality)

@coderabbitai

coderabbitai Bot commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Both server entry points (cmd/admin_server.go and cmd/server_main.go) gain --debug, --version, and (for admin) --init-superuser CLI flags, a custom printHelp(), and log-level reinitialization driven by config and the debug flag. The ingestor binary receives the same flag and logging treatment. Default admin creation is gated behind --init-superuser. InitDefaultAdmin adds informational log messages on completion in both branches. The build system integrates ingestor binary compilation, validation, cleanup, and background execution alongside the existing server processes.

CLI flag expansions and logging control

Layer / File(s) Summary
Admin server: CLI flags, help, conditional init, and debug override
cmd/admin_server.go
printHelp() documents --debug, --version, and --init-superuser; main() defines the flags and handles --version early exit. Effective log level is derived from cfg.Log.Level and overridden to "debug" when the flag is set. InitDefaultAdmin() is wrapped in an if initSuperuser conditional.
Main and ingestor servers: CLI flags, help, and debug override
cmd/server_main.go, cmd/ingestor.go
Both files update printHelp() to document the new flags and extend main() flag parsing. Each derives effective log level from config and debug flag, overriding to "debug" when set, then reinitializes the logger. Both handle --version as an early exit.
Admin service initialization logging
internal/admin/service.go
InitDefaultAdmin() emits common.Info("Init default super user successfully") after tenant setup completes in both the create-new and superuser-already-exists branches.

Ingestor build and runtime integration

Layer / File(s) Summary
Ingestor compilation and build validation
build.sh
INGESTOR_BINARY path is defined; the build step compiles cmd/ingestor.go with CGO flags matching the server, validates the binary exists post-build, and reports success.
Ingestor cleanup and background execution
build.sh
The clean target removes the ingestor binary, the run() function checks that the ingestor binary exists (exiting with build instructions if missing), starts it as a background process with a captured PID, and registers signal-based cleanup. Build completion output now includes ingestor and ragflow_cli alongside server binaries.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐇 Hop hop, a flag for debug at last,
--init-superuser runs only when asked,
The version prints quick and then exits with grace,
Log levels now shimmy right into place,
The ingestor hops quiet through build and through space! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Go: add more start server parameters' accurately summarizes the main change—adding new CLI flags (--version, --debug, --init-superuser) across multiple server binaries.
Description check ✅ Passed The description includes the required 'What problem does this PR solve?' section with practical examples and specifies the correct type of change, but the examples section could be more structured and detailed.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

@JinHai-CN JinHai-CN added the ci Continue Integration label Jun 16, 2026
@JinHai-CN
JinHai-CN marked this pull request as ready for review June 16, 2026 10:48
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 💞 feature Feature request, pull request that fullfill a new feature. labels Jun 16, 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)
internal/admin/service.go (1)

1842-1842: 💤 Low value

Consider clarifying the log message for the existing-admin branch.

This log message appears in the branch where the default superuser already exists (lines 1818-1840), and the code only ensures the tenant exists rather than initializing a new user. A message like "Default super user verified successfully" or "Default super user and tenant initialized successfully" would more accurately reflect what's happening in this branch.

🤖 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 `@internal/admin/service.go` at line 1842, The log message in the common.Info
call at line 1842 uses "Init default super user successfully" which is
misleading because this log statement is in the code branch where the default
superuser already exists (verified in the preceding conditional logic). Update
the message to more accurately reflect what is actually happening in this
branch, such as "Default super user verified successfully" or "Default super
user and tenant initialized successfully", to clarify that the code is verifying
an existing user and ensuring the tenant exists rather than initializing a new
superuser.
🤖 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 `@cmd/admin_server.go`:
- Around line 146-152: The change to conditionally call InitDefaultAdmin() only
when the --init-superuser flag is set represents a breaking change from the
previous behavior where this initialization happened unconditionally. Document
this breaking change by adding clear comments in the initSuperuser conditional
block explaining why InitDefaultAdmin() is now behind a flag, and ensure release
notes or migration guides clearly explain that users relying on automatic admin
initialization on first startup must now explicitly pass the --init-superuser
flag to maintain the same behavior.
- Around line 70-74: In the versionFlag handling block, replace the os.Exit(0)
call with return instead. This improves consistency with the same version flag
handling in the other binary, makes the code more testable, and follows a
cleaner pattern for early function exits.

---

Nitpick comments:
In `@internal/admin/service.go`:
- Line 1842: The log message in the common.Info call at line 1842 uses "Init
default super user successfully" which is misleading because this log statement
is in the code branch where the default superuser already exists (verified in
the preceding conditional logic). Update the message to more accurately reflect
what is actually happening in this branch, such as "Default super user verified
successfully" or "Default super user and tenant initialized successfully", to
clarify that the code is verifying an existing user and ensuring the tenant
exists rather than initializing a new superuser.
🪄 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: 2637706a-f148-4633-bd4c-d3ff2f10b33e

📥 Commits

Reviewing files that changed from the base of the PR and between abca767 and 6f6c397.

📒 Files selected for processing (3)
  • cmd/admin_server.go
  • cmd/server_main.go
  • internal/admin/service.go

Comment thread cmd/admin_server.go Resolved
Comment thread cmd/admin_server.go
Comment on lines +146 to 152
if initSuperuser {
// Initialize default admin user
if err := adminService.InitDefaultAdmin(); err != nil {
common.Error("Failed to initialize default admin user", err)
}

}

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

Document the breaking change in default admin initialization behavior.

The --init-superuser flag changes the default behavior: InitDefaultAdmin() is now only called when the flag is set, whereas it was previously called unconditionally. Deployments that rely on automatic admin initialization on first startup will need to explicitly pass --init-superuser.

While this change aligns with the PR objectives, ensure it's clearly documented in release notes or migration guides to prevent unexpected behavior for existing users.

🤖 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 `@cmd/admin_server.go` around lines 146 - 152, The change to conditionally call
InitDefaultAdmin() only when the --init-superuser flag is set represents a
breaking change from the previous behavior where this initialization happened
unconditionally. Document this breaking change by adding clear comments in the
initSuperuser conditional block explaining why InitDefaultAdmin() is now behind
a flag, and ensure release notes or migration guides clearly explain that users
relying on automatic admin initialization on first startup must now explicitly
pass the --init-superuser flag to maintain the same behavior.

Signed-off-by: Jin Hai <[email protected]>
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 16, 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: 1

🤖 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 `@build.sh`:
- Around line 341-345: The trap handler being set for INGESTOR_PID at line 344
replaces the earlier trap handler for ADMIN_PID instead of adding to it, causing
the admin_server process to leak and remain running after script exit. Modify
the trap command to clean up both ADMIN_PID and INGESTOR_PID processes together
in a single trap handler that catches the EXIT INT TERM signals. This can be
done by either combining both kill commands into the existing trap statement or
by appending to the existing trap using the trap -p command to retrieve and
merge the previous trap behavior.
🪄 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: 17991ac5-c206-42d3-8473-66591a077406

📥 Commits

Reviewing files that changed from the base of the PR and between 6f6c397 and 857d422.

📒 Files selected for processing (3)
  • build.sh
  • cmd/admin_server.go
  • cmd/ingestor.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/admin_server.go

Comment thread build.sh
Comment on lines +341 to +345
print_section "Starting ingestor (background)"
"$INGESTOR_BINARY" &
INGESTOR_PID=$!
trap 'kill "$INGESTOR_PID" 2>/dev/null || true' EXIT INT TERM
sleep 1

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

Trap handler override leaks admin_server on exit.

The trap at Line 344 replaces the earlier trap for ADMIN_PID, so only ingestor is cleaned up and admin_server can remain running after script exit.

Suggested fix
-    "$ADMIN_SERVER_BINARY" &
-    ADMIN_PID=$!
-    trap 'kill "$ADMIN_PID" 2>/dev/null || true' EXIT INT TERM
+    "$ADMIN_SERVER_BINARY" &
+    ADMIN_PID=$!

@@
     "$INGESTOR_BINARY" &
     INGESTOR_PID=$!
-    trap 'kill "$INGESTOR_PID" 2>/dev/null || true' EXIT INT TERM
+    cleanup() {
+        kill "$INGESTOR_PID" 2>/dev/null || true
+        kill "$ADMIN_PID" 2>/dev/null || true
+    }
+    trap cleanup EXIT INT TERM
     sleep 1
🤖 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 `@build.sh` around lines 341 - 345, The trap handler being set for INGESTOR_PID
at line 344 replaces the earlier trap handler for ADMIN_PID instead of adding to
it, causing the admin_server process to leak and remain running after script
exit. Modify the trap command to clean up both ADMIN_PID and INGESTOR_PID
processes together in a single trap handler that catches the EXIT INT TERM
signals. This can be done by either combining both kill commands into the
existing trap statement or by appending to the existing trap using the trap -p
command to retrieve and merge the previous trap behavior.

@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (a15e667) to head (857d422).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16093   +/-   ##
=======================================
  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.

@JinHai-CN
JinHai-CN merged commit 6865039 into infiniflow:main Jun 16, 2026
1 check passed
Harry-Hz-Zhang pushed a commit to Harry-Hz-Zhang/ragflow that referenced this pull request Jun 17, 2026
### What problem does this PR solve?

```
$ ./bin/ragflow_server --version 
RAGFlow version: v0.26.0-65-g549f6109c

$ ./bin/ragflow_server --debug # start server with debug log level

$ ./bin/admin_server --version 
RAGFlow version: v0.26.0-65-g549f6109c

$ ./bin/admin_server --debug # start server with debug log level

$ ./bin/admin_server --init-superuser # init default superuser

$ ./bin/ingestor --version
RAGFlow version: v0.26.0-68-g6f6c39706

$ ./bin/ingestor --debug
```


### Type of change

- [x] New Feature (non-breaking change which adds functionality)

---------

Signed-off-by: Jin Hai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant