Skip to content

Move REDIS to engine dir - #16006

Merged
JinHai-CN merged 4 commits into
infiniflow:mainfrom
JinHai-CN:fix459
Jun 15, 2026
Merged

JinHai-CN merged 4 commits into
infiniflow:mainfrom
JinHai-CN:fix459

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

What problem does this PR solve?

as title.

Type of change

  • Refactoring

@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

internal/engine/redis/redis.go has its package declaration corrected from cache to redis. All files previously importing ragflow/internal/cache are updated to import ragflow/internal/engine/redis instead, replacing every cache.Get() call with redis.Get() across services, handlers, agent canvas components, and entry points. Two OAuthLoginInitiate/OAuthCallback method signatures are updated to accept *redis.RedisClient. The ForgotResetPassword handler additionally strips password and access_token from its response.

Changes

Cache-to-Redis Package Migration

Layer / File(s) Summary
Redis engine package declaration fix
internal/engine/redis/redis.go
Package declaration corrected from package cache to package redis, enabling correct import references throughout the codebase.
Service layer migration to redis.Get()
internal/service/oauth_login.go, internal/service/system.go, internal/service/tag.go, internal/service/user.go, internal/service/connector.go, internal/service/document.go, internal/admin/service.go
All service files replace cache.Get() with redis.Get(). OAuthLoginInitiate and OAuthCallback method signatures change their Redis parameter type from *cache.RedisClient to *redis.RedisClient. Health checks, tag caching, forgot-password OTP/captcha flows, OAuth session storage, document cancel signals, and admin Redis info all updated.
Handler layer migration to redis.Get()
internal/admin/handler.go, internal/handler/oauth_login.go, internal/handler/user.go, internal/handler/agent.go
HTTP handlers switch secret-key retrieval and Redis data access to redis.Get() across user auth (Register, Login, LoginByEmail, ForgotResetPassword), admin login, OAuth login/callback, and agent log retrieval. ForgotResetPassword response also drops password and access_token fields.
Agent canvas migration to redis2.Get()
internal/agent/canvas/cancel.go, internal/agent/canvas/checkpoint_store.go, internal/agent/canvas/run_tracker.go
Cancel watcher/publisher, checkpoint store, and run tracker constructors replace cache.Get() with redis2.Get() (aliased internal/engine/redis import).
Entry point wiring
cmd/admin_server.go, cmd/ingestor.go, cmd/server_main.go
Startup lifecycle switches from cache.Init/cache.Close to redis.Init/redis.Close, server.InitVariables receives redis.Get(), and the per-tenant admin runtime selector in server_main.go guards on redis.Get().GetClient().

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • infiniflow/ragflow#15290: Introduced the forgot-password flow (captcha/OTP/reset) that stores state in Redis keys, directly overlapping with this PR's migration of those same ForgotIssueCaptcha, ForgotSendOTP, ForgotVerifyOTP, and ForgotResetPassword calls from cache.Get() to redis.Get().

Suggested reviewers

  • Hz-186

Poem

🐇 Hop hop, the cache has gone away,
A Redis engine rules the day!
From package cache to package redis true,
One little fix, the whole codebase flew.
Each cache.Get() now calls redis.Get() instead—
The bunny refactored, then hopped off to bed. 🌙

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is largely incomplete and provides minimal detail. While it identifies the change type as refactoring, the explanation 'as title' is insufficient and the description lacks depth about rationale, impact, and testing. Expand the description to explain why Redis is being moved to the engine directory, what benefits this organization provides, and any migration considerations for users of the cache package.
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Move REDIS to engine dir' is directly related to the main change in the changeset, which reorganizes the Redis package from internal/cache to internal/engine/redis across multiple files.
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 marked this pull request as ready for review June 15, 2026 02:51
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 15, 2026
@JinHai-CN JinHai-CN added ci Continue Integration and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jun 15, 2026
@dosubot dosubot Bot added the ☯️ refactor Pull request that refactor/refine code label Jun 15, 2026
@JinHai-CN
JinHai-CN marked this pull request as draft June 15, 2026 02:51
@JinHai-CN
JinHai-CN marked this pull request as ready for review June 15, 2026 02:51
@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

🤖 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 `@internal/handler/agent.go`:
- Line 922: Both locations chain method calls on redis.Get() without nil guards,
violating the established codebase pattern. In internal/handler/agent.go at line
922, store the result of redis.Get() in a variable, check if it is nil, and if
so return the empty-log response as a fallback before calling .Get(key). In
cmd/server_main.go at line 260, guard the redis.Get() call itself (not just the
result of .GetClient()) to ensure that adminRuntimeSelector remains safely nil
if Redis is unavailable at startup.

In `@internal/service/user.go`:
- Around line 1221-1223: The code is calling redis.Get() and immediately
invoking methods like Set() on the result without checking if redis.Get()
returns nil. When Redis initialization is skipped (when the host is unset),
redis.Get() can return nil, causing a panic instead of a controlled error
response. Add a nil check after calling redis.Get() in the captcha storage
operation and all other Redis operations in the forgot-password flow, returning
an appropriate error response (common.CodeServerError with a descriptive error
message) if redis.Get() is nil, similar to how other error conditions are
handled in this function.
🪄 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: dd1d600c-6be4-4b19-981f-fd674d3c3c60

📥 Commits

Reviewing files that changed from the base of the PR and between 83e2180 and a09dbc0.

📒 Files selected for processing (18)
  • cmd/admin_server.go
  • cmd/ingestor.go
  • cmd/server_main.go
  • internal/admin/handler.go
  • internal/admin/service.go
  • internal/agent/canvas/cancel.go
  • internal/agent/canvas/checkpoint_store.go
  • internal/agent/canvas/run_tracker.go
  • internal/engine/redis/redis.go
  • internal/handler/agent.go
  • internal/handler/oauth_login.go
  • internal/handler/user.go
  • internal/service/connector.go
  • internal/service/document.go
  • internal/service/oauth_login.go
  • internal/service/system.go
  • internal/service/tag.go
  • internal/service/user.go

Comment thread internal/handler/agent.go

key := fmt.Sprintf("%s-%s-logs", canvasID, messageID)
payload, rerr := cache.Get().Get(key)
payload, rerr := redis.Get().Get(key)

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:

# Check the exact code at both locations
echo "=== internal/handler/agent.go around line 922 ==="
sed -n '915,930p' internal/handler/agent.go

echo -e "\n=== cmd/server_main.go around line 260 ==="
sed -n '255,265p' cmd/server_main.go

# Find the redis.Get() function definition to understand its signature
echo -e "\n=== Looking for redis.Get() definition ==="
rg -A 10 "func Get\(\)" --type go | head -30

Repository: infiniflow/ragflow

Length of output: 2183


🏁 Script executed:

# Get more context around each usage to understand the full picture
echo "=== Broader context for internal/handler/agent.go line 922 ==="
sed -n '910,935p' internal/handler/agent.go

echo -e "\n=== Broader context for cmd/server_main.go line 260 ==="
sed -n '250,270p' cmd/server_main.go

Repository: infiniflow/ragflow

Length of output: 2155


🏁 Script executed:

# Search for redis package to understand the implementation
rg "package redis" --type go
rg -B 2 -A 10 "func Get\(\)" --type go

Repository: infiniflow/ragflow

Length of output: 1321


🏁 Script executed:

# Check globalClient initialization and type
echo "=== globalClient definition and initialization ==="
rg -B 5 -A 5 "var globalClient" internal/engine/redis/redis.go

# Check how other parts of the code handle redis.Get()
echo -e "\n=== Other redis.Get() usages in codebase ==="
rg "redis\.Get\(\)" --type go -B 2 -A 2 | head -50

# Look for pattern of nil-guarding redis.Get()
echo -e "\n=== Checking if redis.Get() is ever nil-guarded ==="
rg "redis\.Get\(\)" --type go -B 2 -A 2 | grep -A 2 "!= nil\|if.*redis\.Get"

Repository: infiniflow/ragflow

Length of output: 5072


🏁 Script executed:

# Check the RedisClient type definition to understand what methods it has
echo "=== RedisClient type definition ==="
rg -B 5 -A 15 "type RedisClient struct" internal/engine/redis/redis.go

Repository: infiniflow/ragflow

Length of output: 605


Add nil guard before chaining methods on redis.Get() at both locations.
The established pattern in the codebase (internal/service/tag.go, system.go, connector.go) nil-checks redis.Get() before calling methods on it, but both flagged sites omit this guard:

  • internal/handler/agent.go#L922: Store result in a variable and check for nil before calling .Get(key); if nil, return the empty-log response as fallback.
  • cmd/server_main.go#L260: Guard redis.Get() itself (not just the result of .GetClient()) so adminRuntimeSelector remains safely nil if Redis is unavailable at startup.
📍 Affects 2 files
  • internal/handler/agent.go#L922-L922 (this comment)
  • cmd/server_main.go#L260-L260
🤖 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/handler/agent.go` at line 922, Both locations chain method calls on
redis.Get() without nil guards, violating the established codebase pattern. In
internal/handler/agent.go at line 922, store the result of redis.Get() in a
variable, check if it is nil, and if so return the empty-log response as a
fallback before calling .Get(key). In cmd/server_main.go at line 260, guard the
redis.Get() call itself (not just the result of .GetClient()) to ensure that
adminRuntimeSelector remains safely nil if Redis is unavailable at startup.

Comment thread internal/service/user.go
Comment on lines +1221 to 1223
if ok := redis.Get().Set(utility.CaptchaIDRedisKey(captchaID), text, 60*time.Second); !ok {
return "", "", common.CodeServerError, fmt.Errorf("failed to store captcha")
}

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

Guard forgot-password Redis paths when Redis is uninitialized.

Line 1221 calls redis.Get().Set(...) directly, and Lines 1241, 1340, and 1410 use rc := redis.Get() without a nil check before dereference. Since Redis init is skipped when host is unset, these flows can panic instead of returning a controlled error response.

Suggested fix
 func (s *UserService) ForgotIssueCaptcha(email string) (captchaID, imageDataURL string, code common.ErrorCode, err error) {
+	rc := redis.Get()
+	if rc == nil {
+		return "", "", common.CodeServerError, fmt.Errorf("redis is not initialized")
+	}
 	...
-	if ok := redis.Get().Set(utility.CaptchaIDRedisKey(captchaID), text, 60*time.Second); !ok {
+	if ok := rc.Set(utility.CaptchaIDRedisKey(captchaID), text, 60*time.Second); !ok {
 		return "", "", common.CodeServerError, fmt.Errorf("failed to store captcha")
 	}
 }

 func (s *UserService) ForgotSendOTP(email, captchaID, captcha string) (common.ErrorCode, error) {
 	rc := redis.Get()
+	if rc == nil {
+		return common.CodeServerError, fmt.Errorf("redis is not initialized")
+	}
 	...
 }

 func (s *UserService) ForgotVerifyOTP(email, otp string) (common.ErrorCode, error) {
 	rc := redis.Get()
+	if rc == nil {
+		return common.CodeServerError, fmt.Errorf("redis is not initialized")
+	}
 	...
 }

 func (s *UserService) ForgotResetPassword(req *ForgotResetPasswordRequest) (*entity.User, common.ErrorCode, error) {
 	rc := redis.Get()
+	if rc == nil {
+		return nil, common.CodeServerError, fmt.Errorf("redis is not initialized")
+	}
 	...
 }

Also applies to: 1241-1244, 1340-1344, 1410-1413

🤖 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/service/user.go` around lines 1221 - 1223, The code is calling
redis.Get() and immediately invoking methods like Set() on the result without
checking if redis.Get() returns nil. When Redis initialization is skipped (when
the host is unset), redis.Get() can return nil, causing a panic instead of a
controlled error response. Add a nil check after calling redis.Get() in the
captcha storage operation and all other Redis operations in the forgot-password
flow, returning an appropriate error response (common.CodeServerError with a
descriptive error message) if redis.Get() is nil, similar to how other error
conditions are handled in this function.

@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 (400dfd5) to head (c75e5c7).
⚠️ Report is 1 commits behind head on main.

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

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cmd/server_main.go (1)

261-263: ⚠️ Potential issue | 🔴 Critical

Guard redis.Get() before calling GetClient() to avoid startup panic.

Line 261 directly dereferences redis.Get() without a nil-check. When Redis is not configured (cfg.Host is empty), redis.Init() successfully skips initialization, leaving redis.Get() returning nil. Calling .GetClient() on nil will panic during bootstrap, preventing the server from starting.

Proposed fix
 var adminRuntimeSelector *runtime.Selector
-if rdb := redis.Get().GetClient(); rdb != nil {
-	adminRuntimeSelector = runtime.NewSelector(rdb, common.Logger)
-}
+if rc := redis.Get(); rc != nil {
+	if rdb := rc.GetClient(); rdb != nil {
+		adminRuntimeSelector = runtime.NewSelector(rdb, common.Logger)
+	}
+}
 adminRuntimeHandler := handler.NewAdminRuntimeHandler(adminRuntimeSelector)
🤖 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/server_main.go` around lines 261 - 263, The code at line 261 calls
redis.Get().GetClient() without verifying that redis.Get() returns a non-nil
value. When Redis is not configured, redis.Get() returns nil, which causes a
panic when attempting to call GetClient() on it. Add a nil-check for redis.Get()
first before calling GetClient() on the result. The condition should verify that
redis.Get() is not nil, and only then call GetClient() on that returned client,
assigning the result to rdb within the inner block.
🤖 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.

Outside diff comments:
In `@cmd/server_main.go`:
- Around line 261-263: The code at line 261 calls redis.Get().GetClient()
without verifying that redis.Get() returns a non-nil value. When Redis is not
configured, redis.Get() returns nil, which causes a panic when attempting to
call GetClient() on it. Add a nil-check for redis.Get() first before calling
GetClient() on the result. The condition should verify that redis.Get() is not
nil, and only then call GetClient() on that returned client, assigning the
result to rdb within the inner block.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 613de9a4-f782-4dd6-ae99-fdf740a9fcca

📥 Commits

Reviewing files that changed from the base of the PR and between a09dbc0 and 7e423bc.

📒 Files selected for processing (1)
  • cmd/server_main.go

@JinHai-CN
JinHai-CN merged commit fcebceb 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 ☯️ refactor Pull request that refactor/refine code 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