Skip to content

Go: fix context - #17277

Merged
JinHai-CN merged 24 commits into
infiniflow:mainfrom
JinHai-CN:fix576
Jul 23, 2026
Merged

JinHai-CN merged 24 commits into
infiniflow:mainfrom
JinHai-CN:fix576

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

Summary

Continue to add context

Signed-off-by: Jin Hai <[email protected]>
@JinHai-CN
JinHai-CN marked this pull request as ready for review July 23, 2026 04:18
@JinHai-CN JinHai-CN added the ci Continue Integration label Jul 23, 2026
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

DAO methods now accept explicit database handles and execute with request contexts. Services and tests use the updated signatures, canvas seeding and migrations honor context cancellation, the no-CGO PDF parser accepts context, and the exported LLM database alias is removed.

Changes

Database and context propagation

Layer / File(s) Summary
Context-aware DAO contracts and execution
internal/dao/api_token.go, internal/dao/chat.go, internal/dao/chat_channel.go, internal/dao/canvas_template.go
DAO operations use explicit *gorm.DB handles with db.WithContext(ctx).
Service integration and chat flows
internal/admin/service.go, internal/service/{api_token,agent,agent_sessions,bot_completion,chat,chat_channel,stats,user}.go
Service call sites pass the shared database handle to updated DAO methods; chat validation and authorization messages are standardized.
Context-aware migrations and canvas seeding
internal/dao/database.go, internal/dao/canvas_template_seed.go
Migrations and canvas-template schema, transactions, upserts, and stale-row deletion use the supplied context and database handle.
Compatibility updates and cleanup
internal/parser/parser/pdf_parser_nocgo.go, internal/dao/*_test.go, internal/service/*_test.go, internal/service/llm.go
Parser and test call signatures are updated, persistence assertions reflect revised contracts, and the package-level LLM DB alias is removed.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: ☯️ refactor

Suggested reviewers: hz-186

Poem

I’m a rabbit with a database key,
Passing context carefully.
Queries hop through handles bright,
Migrations pause when canceled right.
Clean burrows bloom tonight.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (1 warning, 2 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 24.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is related to the change set, but it's too vague to show that it refactors DAO calls to thread context and DB handles. Use a specific title like "Go: thread context and DB handles through DAOs" to reflect the main change.
Description check ❓ Inconclusive The description is only a vague placeholder and does not explain the PR's purpose, scope, or background required by the template. Expand the summary with the problem being solved, why the context/DB changes were needed, and the main areas touched.
✅ Passed checks (2 passed)
Check name Status Explanation
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.

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.

@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 `@internal/parser/parser/pdf_parser_nocgo.go`:
- Line 9: Update PDFParser.ParseWithResult and its no-CGO callers to pass ctx to
parsePDFWithMinerU, parsePDFWithPaddleOCR, parsePDFWithDocling,
parsePDFWithOpenDataLoader, parsePDFWithSoMark, and parsePDFWithTCADP. Add the
required context import in this package and update stale tests or other callers
to supply a context argument consistently.
🪄 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 Plus

Run ID: fca3d7b6-59e4-4cea-a303-6e0a638e1178

📥 Commits

Reviewing files that changed from the base of the PR and between 5478f95 and 0ea84ec.

📒 Files selected for processing (3)
  • internal/dao/api_token.go
  • internal/dao/database.go
  • internal/parser/parser/pdf_parser_nocgo.go

)

func (p *PDFParser) ParseWithResult(filename string, data []byte) ParseResult {
func (p *PDFParser) ParseWithResult(ctx context.Context, filename string, data []byte) ParseResult {

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail
bash build.sh --test ./internal/parser/parser

Repository: infiniflow/ragflow

Length of output: 849


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '--- locate relevant files ---\n'
git ls-files 'internal/parser/parser/**/*.go' | sed -n '1,120p'

printf '\n--- pdf parser nocgo outline ---\n'
ast-grep outline internal/parser/parser/pdf_parser_nocgo.go --view expanded || true

printf '\n--- pdf parser nocgo relevant lines ---\n'
cat -n internal/parser/parser/pdf_parser_nocgo.go | sed -n '1,260p'

printf '\n--- pdf parser cgo relevant lines ---\n'
if [ -f internal/parser/parser/pdf_parser.go ]; then
  cat -n internal/parser/parser/pdf_parser.go | sed -n '1,260p'
fi

printf '\n--- ParseResultProducer / ParseWithResult definitions and calls ---\n'
rg -n "type ParseResultProducer|func \\(.*\\) ParseWithResult|ParseWithResult\\(" internal/parser/parser internal -g '*.go' | sed -n '1,240p'

printf '\n--- parsePDF helper signatures ---\n'
rg -n "parsePDF(MinerU|PaddleOCR|Docling|OpenDataLoader|With.*OCR)" internal/parser/parser internal/parser -g '*.go' | sed -n '1,240p'

printf '\n--- Go parse-only diagnostics for internal/parser/parser/*.go (with cgo config set) ---\n'
CGO_ENABLED=0 go vet -tags cgo ./internal/parser/parser/... 2>&1 | sed -n '1,240p'

Repository: infiniflow/ragflow

Length of output: 247


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf -- '%s\n' '--- locate relevant files ---'
git ls-files 'internal/parser/parser/**/*.go' | sed -n '1,120p'

printf -- '%s\n' ''
printf -- '%s\n' '--- pdf parser nocgo outline ---'
ast-grep outline internal/parser/parser/pdf_parser_nocgo.go --view expanded || true

printf -- '%s\n' ''
printf -- '%s\n' '--- pdf parser nocgo relevant lines ---'
cat -n internal/parser/parser/pdf_parser_nocgo.go | sed -n '1,260p'

printf -- '%s\n' ''
printf -- '%s\n' '--- pdf parser cgo relevant lines ---'
if [ -f internal/parser/parser/pdf_parser.go ]; then
  cat -n internal/parser/parser/pdf_parser.go | sed -n '1,260p'
fi

printf -- '%s\n' ''
printf -- '%s\n' '--- ParseResultProducer / ParseWithResult definitions and calls ---'
rg -n "type ParseResultProducer|func \\(.*\\) ParseWithResult|ParseWithResult\\(" internal/parser/parser internal -g '*.go' | sed -n '1,240p'

printf -- '%s\n' ''
printf -- '%s\n' '--- parsePDF helper signatures ---'
rg -n "parsePDF(MinerU|PaddleOCR|Docling|OpenDataLoader|With.*OCR)" internal/parser/parser internal/parser -g '*.go' | sed -n '1,240p'

printf -- '%s\n' ''
printf -- '%s\n' '--- Go parse-only diagnostics for internal/parser/parser/*.go (with cgo config set) ---'
CGO_ENABLED=0 go vet -tags cgo ./internal/parser/parser/... 2>&1 | sed -n '1,240p'

Repository: infiniflow/ragflow

Length of output: 28074


Update the no-CGO PDF parser helpers and stale callers.

pdf_parser_nocgo.go already adds ctx to ParseWithResult, but it still calls the context-aware PDF helpers without passing it (parsePDFWithMinerU, parsePDFWithPaddleOCR, parsePDFWithDocling, parsePDFWithOpenDataLoader, parsePDFWithSoMark, and parsePDFWithTCADP). A few tests still call ParseWithResult without the context argument too, so add context to this package and pass ctx consistently.

🧰 Tools
🪛 golangci-lint (2.12.2)

[error] 9-9: : # ragflow/internal/parser/parser [ragflow/internal/parser/parser.test]
internal/parser/parser/pdf_parser_nocgo.go:9:41: undefined: context
internal/parser/parser/pdf_parser_nocgo.go:17:45: not enough arguments in call to parsePDFWithMinerU
have (string, []byte, *PDFParser)
want ("context".Context, string, []byte, *PDFParser)
internal/parser/parser/pdf_parser_nocgo.go:19:48: not enough arguments in call to parsePDFWithPaddleOCR
have (string, []byte, *PDFParser)
want ("context".Context, string, []byte, *PDFParser)
internal/parser/parser/pdf_parser_nocgo.go:21:46: not enough arguments in call to parsePDFWithDocling
have (string, []byte, *PDFParser)
want ("context".Context, string, []byte, *PDFParser)
internal/parser/parser/pdf_parser_nocgo.go:23:53: not enough arguments in call to parsePDFWithOpenDataLoader
have (string, []byte, *PDFParser)
want ("context".Context, string, []byte, *PDFParser)
internal/parser/parser/parser_type.go:34:10: cannot use NewPPTXParser() (value of type *PPTXParser) as ParseResultProducer value in return statement: *PPTXParser does not implement ParseResultProducer (wrong type for method ParseWithResult)
have ParseWithResult(string, []byte) ParseResult
want ParseWithResult("context".Context, string, []byte) ParseResult
internal/parser/parser/parser_type.go:36:10: cannot use NewPPTParser() (value of type *PPTParser) as ParseResultProducer value in return statement: *PPTParser does not implement ParseResultProducer (wrong type for method ParseWithResult)
have ParseWithResult(string, []byte) ParseResult
want ParseWithResult("context".Context, string, []byte) ParseResult
internal/parser/parser/parser_type.go:44:10: cannot use NewDOCXParser() (value of type *DOCXParser) as ParseResultProducer value in return statement: *DOCXParser does not implement ParseResultProducer (wrong type for method ParseWithResult)
have ParseWithResult(string, []byte) ParseResult
want ParseWithResult("context".Context, string, []byte) ParseResult
internal/parser/parser/parser_type.go:46:10: cannot use NewDOCParser() (value of type *DOCParser) as ParseResultProducer value in return statement: *DOCParser does not implement ParseResultProducer (wrong type for method ParseWithResult)
have ParseWithResult(string, []byte) ParseResult
want ParseWithResult("context".Context, string, []byte) ParseResult
internal/parser/parser/pdf_parser_nocgo_test.go:13:44: not enough arguments in call to pdf.ParseWithResult
have (string, nil)
want (unknown type, string, []byte)
internal/parser/parser/pdf_parser_nocgo_test.go:13:44: too many errors

(typecheck)

🤖 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/parser/parser/pdf_parser_nocgo.go` at line 9, Update
PDFParser.ParseWithResult and its no-CGO callers to pass ctx to
parsePDFWithMinerU, parsePDFWithPaddleOCR, parsePDFWithDocling,
parsePDFWithOpenDataLoader, parsePDFWithSoMark, and parsePDFWithTCADP. Add the
required context import in this package and update stale tests or other callers
to supply a context argument consistently.

Sources: Coding guidelines, Linters/SAST tools

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:S This PR changes 10-29 lines, ignoring generated files. labels Jul 23, 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 `@internal/dao/api_token.go`:
- Around line 123-130: Update internal/dao/api_token.go:123-130 in
API4ConversationDAO.Update to perform an ID-scoped update instead of Save,
returning or propagating ErrRecordNotFound when no row is affected. In
internal/service/bot_completion.go:584-590, make persistChatbotTurn stop and
return nil when the stale-conversation re-read finds no fresh row; at
internal/service/bot_completion.go:636, propagate any update failure. In
internal/service/agent.go:1598 and 1625, make persistAgentRunSession handle
session-load misses and update failures explicitly rather than ignoring results.
🪄 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 Plus

Run ID: 24b43549-6a7f-4fae-820b-8c09ccd59efb

📥 Commits

Reviewing files that changed from the base of the PR and between 0ea84ec and ebbcbd9.

📒 Files selected for processing (12)
  • internal/admin/service.go
  • internal/dao/api_token.go
  • internal/dao/api_token_beta_test.go
  • internal/dao/api_token_test.go
  • internal/service/agent.go
  • internal/service/agent_sessions.go
  • internal/service/api_token.go
  • internal/service/bot_completion.go
  • internal/service/bot_completion_history_test.go
  • internal/service/llm.go
  • internal/service/stats.go
  • internal/service/user.go

Comment thread internal/dao/api_token.go
Comment on lines +123 to +130
func (dao *API4ConversationDAO) Update(ctx context.Context, db *gorm.DB, conv *entity.API4Conversation) error {
if conv == nil {
return errors.New("api4 conversation: nil row")
}
if conv.ID == "" {
return errors.New("api4 conversation: empty id")
}
return DB.WithContext(ctx).Save(conv).Error
return db.WithContext(ctx).Save(conv).Error

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== files =="
git ls-files | rg '(^|/)api_token\.go$|(^|/)bot_completion\.go$|(^|/)agent\.go$' || true

echo "== dao outline =="
for f in $(git ls-files | rg '(^|/)api_token\.go$'); do
  echo "--- $f"
  wc -l "$f"
  ast-grep outline "$f" --view expanded || true
done

echo "== relevant dao lines =="
for f in $(git ls-files | rg '(^|/)api_token\.go$'); do
  sed -n '1,220p' "$f" | nl -ba
done

echo "== relevant service snippets =="
for f in $(git ls-files | rg '(^|/)bot_completion\.go$|(^|/)agent\.go$'); do
  echo "--- $f"
  wc -l "$f"
  rg -n "api4ConversationDAO|GetBySessionID|Update\\(|fresh|SessionID" "$f" || true
done

echo "== GORM Save docs in vendor? =="
rg -n "func \\(db \\*DB\\) Save|Save\\(" vendor 2>/dev/null | head -50 || true

Repository: infiniflow/ragflow

Length of output: 6219


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== dao implementation =="
sed -n '85,145p' internal/dao/api_token.go

echo "== bot_completion relevant sections =="
sed -n '560,650p' internal/service/bot_completion.go

echo "== agent relevant sections =="
sed -n '1570,1635p' internal/service/agent.go

echo "== all API4ConversationDAO callers =="
rg -n "API4ConversationDAO|api4ConversationDAO|GetBySessionID\\(|Update\\(ctx, dao\.DB" internal || true

echo "== gorm dependency version =="
rg -n 'gorm\.io/gorm' go.mod go.sum 2>/dev/null | head -20 || true

Repository: infiniflow/ragflow

Length of output: 14565


🌐 Web query:

GORM v1.25 Save zero affected rows fallback to Create behavior

💡 Result:

In GORM v1.25, the Save method is designed as an "upsert" function that guarantees either an update or an insertion will occur [1][2]. When you call Save on a struct: 1. If the value does not contain a primary key, GORM executes a Create operation [1][3]. 2. If the value contains a primary key, GORM first attempts to execute an Update of all fields [1][3]. 3. If that Update operation results in zero rows affected (e.g., because no matching record was found, or the data being updated is identical to what is already in the database), GORM automatically falls back to a Create operation [1][3][4]. Specifically, the implementation in finisher_api.go checks the outcome of the initial Update execution [3][5]: if updateTx.Error == nil && updateTx.RowsAffected == 0 &&!updateTx.DryRun &&!selectedUpdate { return tx.Session(&Session{SkipHooks: true}).Clauses(clause.OnConflict{UpdateAll: true}).Create(value) } This fallback behavior can lead to unexpected results, such as attempting to create a record that already exists, which may trigger a primary key or unique constraint violation error if the database does not correctly handle the implied ON CONFLICT clause [6][7]. To avoid this unintended "create" behavior when no rows match, official documentation recommends using Select and Updates instead of Save, as Save is intentionally designed to ensure an operation succeeds even if the initial update finds nothing [1][2]. Furthermore, the Save method has been removed from the GORM Generics API to prevent ambiguity and potential concurrency issues [1][2].

Citations:


Prevent deleted conversation rows from being recreated by stale persistence.

API4ConversationDAO.Update uses Save, which upserts when the id-keyed UPDATE affects zero rows. This means persistChatbotTurn and persistAgentRunSession can recreate a session that was deleted after the re-read/load, because the stale object still has a primary key.

  • Replace Save with an ID-scoped update and propagate ErrRecordNotFound / zero rows.
  • Return nil/stop early when the stale-conversation re-read in persistChatbotTurn finds no fresh row.
  • Make persistAgentRunSession return or fail clearly on session-load miss/update failure instead of ignoring the result.
📍 Affects 3 files
  • internal/dao/api_token.go#L123-L130 (this comment)
  • internal/service/bot_completion.go#L584-L590
  • internal/service/bot_completion.go#L636-L636
  • internal/service/agent.go#L1598-L1598
  • internal/service/agent.go#L1625-L1625
🤖 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/dao/api_token.go` around lines 123 - 130, Update
internal/dao/api_token.go:123-130 in API4ConversationDAO.Update to perform an
ID-scoped update instead of Save, returning or propagating ErrRecordNotFound
when no row is affected. In internal/service/bot_completion.go:584-590, make
persistChatbotTurn stop and return nil when the stale-conversation re-read finds
no fresh row; at internal/service/bot_completion.go:636, propagate any update
failure. In internal/service/agent.go:1598 and 1625, make persistAgentRunSession
handle session-load misses and update failures explicitly rather than ignoring
results.

@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

Caution

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

⚠️ Outside diff range comments (1)
internal/dao/chat.go (1)

193-203: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Use the passed handle for the not-found probe too.

UpdateByID updates through db, but the RowsAffected == 0 fallback at Line 209 queries the package-global DB. With a transaction or alternate handle, this can produce a false gorm.ErrRecordNotFound and ignores ctx.

Proposed fix
-		if err := DB.Model(&entity.Chat{}).Where("id = ?", id).Count(&count).Error; err != nil {
+		if err := db.WithContext(ctx).Model(&entity.Chat{}).Where("id = ?", id).Count(&count).Error; err != nil {
🤖 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/dao/chat.go` around lines 193 - 203, Update the not-found fallback
in ChatDAO.UpdateByID to query through the passed db handle with the request
context, matching the update’s db.WithContext(ctx) path. Replace the
package-global DB usage while preserving the existing RowsAffected and
gorm.ErrRecordNotFound behavior.
🤖 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/service/chat.go`:
- Around line 321-330: Update Create’s ExistsByNameTenantStatus lookup to use
case-insensitive name matching, consistent with updateChatREST’s
strings.EqualFold behavior, so differently cased duplicate names are rejected.
Add a regression test covering creation of a name differing only by case from an
existing valid chat.

---

Outside diff comments:
In `@internal/dao/chat.go`:
- Around line 193-203: Update the not-found fallback in ChatDAO.UpdateByID to
query through the passed db handle with the request context, matching the
update’s db.WithContext(ctx) path. Replace the package-global DB usage while
preserving the existing RowsAffected and gorm.ErrRecordNotFound 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 Plus

Run ID: fd0feb88-a4e8-4e30-95c2-6a74cf502385

📥 Commits

Reviewing files that changed from the base of the PR and between 4a444a6 and dbdd2b7.

📒 Files selected for processing (6)
  • internal/dao/chat.go
  • internal/service/chat.go
  • internal/service/chat_channel.go
  • internal/service/chat_channel_test.go
  • internal/service/chat_delete_test.go
  • internal/service/chat_rest_update_test.go

Comment thread internal/service/chat.go
Comment on lines 321 to 330
applyCreatePromptDefaults(req)
filterCreateChatPersistedFields(req)

exists, err := s.chatDAO.ExistsByNameTenantStatus(ctx, name, userID, string(entity.StatusValid))
exists, err := s.chatDAO.ExistsByNameTenantStatus(ctx, dao.DB, name, userID, string(entity.StatusValid))
if err != nil {
return nil, common.CodeServerError, err
}
if exists {
return nil, common.CodeDataError, errors.New("Duplicated chat name in creating chat.")
return nil, common.CodeDataError, errors.New("duplicated chat name in creating chat")
}

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== candidate files =="
fd -a '^(chat|dao)' . | sed 's#^\./##' | head -200

echo "== locate chat.go and dao =="
git ls-files | grep -E '(^|/)chat\.go$|(^|/)dao|dao\.go$|database|db' | head -300

echo "== outline internal/service/chat.go =="
if [ -f internal/service/chat.go ]; then
  wc -l internal/service/chat.go
  ast-grep outline internal/service/chat.go | sed -n '1,220p'
fi

echo "== relevant create/update lines =="
if [ -f internal/service/chat.go ]; then
  sed -n '300,345p' internal/service/chat.go
  sed -n '930,975p' internal/service/chat.go
fi

echo "== search ExistsByNameTenantStatus and duplicate checks =="
rg -n "ExistsByNameTenantStatus|EqualFold|duplicated chat name|duplicate.*name|chatDAO|DB\\.Exec|Where.*name|name =" internal -S

Repository: infiniflow/ragflow

Length of output: 50375


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== internal/dao/chat.go =="
wc -l internal/dao/chat.go
ast-grep outline internal/dao/chat.go | sed -n '1,260p'
echo "== ExistsByNameTenantStatus definitions/usages =="
rg -n "func .*ExistsByNameTenantStatus|ExistsByNameTenantStatus|name = \\?|LOWER\\(name\\)|EqualFold" internal/dao/chat.go internal/service/chat.go internal/dao -g '*.go' --max-count 80
sed -n '1,240p' internal/dao/chat.go

echo "== targeted creation/behavior tests mentioning duplicate names =="
rg -n "duplicated chat name|duplicate.*chat|chat name|Name.*Foo|Foo|foo|strings\.EqualFold|ToLower|ExistsByNameTenantStatus" internal test -g '*.go' | sed -n '1,220p'

Repository: infiniflow/ragflow

Length of output: 38001


Preserve case-insensitive duplicate-name behavior.

Create checks name = ?, while updateChatREST checks existing names with strings.EqualFold. On a case-sensitive collation, creation can allow Foo after foo; make ExistsByNameTenantStatus use case-insensitive semantics and cover it with a regression test.

🤖 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/chat.go` around lines 321 - 330, Update Create’s
ExistsByNameTenantStatus lookup to use case-insensitive name matching,
consistent with updateChatREST’s strings.EqualFold behavior, so differently
cased duplicate names are rejected. Add a regression test covering creation of a
name differing only by case from an existing valid chat.

Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jul 23, 2026
Signed-off-by: Jin Hai <[email protected]>
@codecov

codecov Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (8af2467) to head (6c4446b).
⚠️ Report is 19 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #17277   +/-   ##
=======================================
  Coverage   90.65%   90.65%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          650      650           
  Misses         39       39           
  Partials       28       28           

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

Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
@JinHai-CN
JinHai-CN merged commit 61201e4 into infiniflow:main Jul 23, 2026
5 checks passed
This was referenced Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant