Skip to content

Go: refactor UUID functions - #16695

Merged
JinHai-CN merged 4 commits into
infiniflow:mainfrom
JinHai-CN:fix521
Jul 7, 2026
Merged

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

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

As title

@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8c97d280-8e80-4b44-b459-a07413daf580

📥 Commits

Reviewing files that changed from the base of the PR and between 04c205f and 932c452.

📒 Files selected for processing (1)
  • internal/service/agent.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/service/agent.go

📝 Walkthrough

Walkthrough

This PR standardizes ID and token generation across many DAO and service paths, changes beta API token generation to a no-argument form, removes several local UUID helpers, and makes one SSE error-scope adjustment.

Changes

Token and ID generation standardization

Layer / File(s) Summary
Token helpers and API tokens
internal/utility/token.go, internal/admin/service.go, internal/service/api_token.go
Adds a shared UUID helper, changes beta token generation to take no input, and updates admin/API-key flows to use the new helper.
Agent, chat, and research IDs
internal/agent/canvas/runner.go, internal/service/agent.go, internal/service/agent_sessions.go, internal/service/bot_completion.go, internal/service/chat.go, internal/service/chat_session.go, internal/service/deep_researcher.go
Replaces UUID-derived session, message, and result IDs with shared utility-generated values across agent, chat, canvas runner, and deep research paths.
DAO and storage IDs
internal/dao/connector.go, internal/dao/file.go, internal/dao/file_commit.go, internal/dao/ingestion.go, internal/ingestion/ingestion_service.go
Switches persistence-layer row and file/document identifiers to shared utility helpers and removes the obsolete local generators.
Service entity IDs
cmd/ragflow_server.go, internal/admin/handler.go, internal/service/chat_channel.go, internal/service/chunk/chunk.go, internal/service/dataset.go, internal/service/mcp.go, internal/service/memory.go, internal/service/memory_message_service.go, internal/service/search.go, internal/service/tenant.go, internal/syncer/syncer.go
Updates service-layer creation paths to assign new entity and task identifiers through shared utility helpers.
Document and file linking IDs
internal/service/document.go, internal/service/file.go, internal/service/file2document.go
Moves document, file, and file-link record IDs onto shared utility generators and removes the file-local UUID helper.
Skill and helper cleanup
internal/common/app_name.go, internal/dao/skill_search_config.go, internal/dao/skill_space.go, internal/service/skill_search.go, internal/service/skill_space.go, internal/harness/graph/graph/compiled.go
Removes file-local UUID helpers, updates skill-space/search ID generation, and changes checkpoint ID prefixes.
SSE error assignment
internal/entity/models/302ai.go
Changes ParseSSEStream error assignment from := to = while preserving the same nil-check and return path.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

Suggested labels: ☯️ refactor

Suggested reviewers: yingfeng, yuzhichang

Poem

A rabbit hops through tokens new,
No more UUID dashes to chew 🐰
Shared helpers hum, neat and bright,
IDs now spring from one clear light,
And burrow paths stay tidy, true.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description is only 'As title' and omits the required Summary and background context. Add a Summary that explains the PR purpose, background context, and what changed at a high level.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main change: refactoring UUID generation functions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

@JinHai-CN JinHai-CN added the ci Continue Integration label Jul 7, 2026
@JinHai-CN
JinHai-CN marked this pull request as ready for review July 7, 2026 07:39
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 7, 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

🧹 Nitpick comments (2)
internal/utility/token.go (1)

144-144: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

GenerateToken32 is identical to GenerateToken; the [:32] slice is a no-op.

A canonical UUID string is 36 characters; removing the 4 hyphens always yields exactly 32 characters, so [:32] never truncates anything. This makes GenerateToken32() behaviorally identical to GenerateToken() (line 141), and the 32 suffix/slice misleadingly implies a length constraint that isn't being enforced.

Consider dropping the redundant slice and delegating to avoid duplication.

♻️ Suggested simplification
-func GenerateToken32() string { return strings.ReplaceAll(uuid.New().String(), "-", "")[:32] }
+func GenerateToken32() string { return GenerateToken() }
🤖 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/utility/token.go` at line 144, GenerateToken32 is redundant because
it produces the same result as GenerateToken, since removing hyphens from
uuid.New().String() already yields 32 characters and the [:32] slice does
nothing. Update GenerateToken32 to delegate to GenerateToken (or otherwise reuse
the shared logic) so the behavior is explicit and the duplication is removed,
keeping the unique symbols GenerateToken32 and GenerateToken aligned.
internal/service/api_token.go (1)

84-87: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Stale comment: beta is no longer derived from the API key.

The comment on line 86 still describes the old derivation (generate_confirmation_token().replace("ragflow-", "")[:32]), but GenerateBetaAPIToken() now generates an independent random token unrelated to APIToken. Update the comment to avoid confusion.

🤖 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/api_token.go` around lines 84 - 87, The comment above
GenerateBetaAPIToken in api_token.go is stale and still describes the old
derivation from the API key. Update the beta comment to match the current
behavior of APIToken and betaAPIKey, making it clear that GenerateBetaAPIToken
now creates an independent random token unrelated to APIToken.
🤖 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/file.go`:
- Around line 512-517: The addFileFromKB flow creates the entity.File before
inserting the File2Document mapping, but the failure path after DB.Create(f2d)
currently returns without removing the newly created file. Update the
addFileFromKB logic in internal/dao/file.go so that when the File2Document
insert fails, it deletes the File row before returning, matching the cleanup
behavior used in internal/service/document.go. Use the existing file variable
and the mapping insert path around DB.Create(f2d) to locate the fix.

---

Nitpick comments:
In `@internal/service/api_token.go`:
- Around line 84-87: The comment above GenerateBetaAPIToken in api_token.go is
stale and still describes the old derivation from the API key. Update the beta
comment to match the current behavior of APIToken and betaAPIKey, making it
clear that GenerateBetaAPIToken now creates an independent random token
unrelated to APIToken.

In `@internal/utility/token.go`:
- Line 144: GenerateToken32 is redundant because it produces the same result as
GenerateToken, since removing hyphens from uuid.New().String() already yields 32
characters and the [:32] slice does nothing. Update GenerateToken32 to delegate
to GenerateToken (or otherwise reuse the shared logic) so the behavior is
explicit and the duplication is removed, keeping the unique symbols
GenerateToken32 and GenerateToken aligned.
🪄 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: c88ee0b7-2fda-4afa-a063-566d20f9e729

📥 Commits

Reviewing files that changed from the base of the PR and between 9eba452 and c3f366a.

📒 Files selected for processing (14)
  • internal/admin/service.go
  • internal/agent/canvas/runner.go
  • internal/dao/connector.go
  • internal/dao/file.go
  • internal/entity/models/302ai.go
  • internal/service/agent.go
  • internal/service/agent_sessions.go
  • internal/service/api_token.go
  • internal/service/chat_session.go
  • internal/service/dataset.go
  • internal/service/deep_researcher.go
  • internal/service/document.go
  • internal/service/file.go
  • internal/utility/token.go

Comment thread internal/dao/file.go
Comment on lines 512 to 517
docLocation = *doc.Location
}

fileID := generateUUID()
fileID := utility.GenerateToken()
file := &entity.File{
ID: fileID,

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

# Inspect the relevant sections with line numbers.
git ls-files internal/dao/file.go internal/service/document.go
wc -l internal/dao/file.go internal/service/document.go
sed -n '470,560p' internal/dao/file.go
printf '\n--- sibling ---\n'
sed -n '3340,3405p' internal/service/document.go

# Search for related create/delete patterns.
rg -n "Create\\(f2d\\)|Create\\(file\\)|Unscoped\\(\\).*Delete\\(&entity\\.File\\{|addFileFromKB" internal/dao/file.go internal/service/document.go

Repository: infiniflow/ragflow

Length of output: 5470


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the DAO call site and any surrounding transaction handling.
sed -n '420,455p' internal/dao/file.go
printf '\n--- nearby DAO helpers ---\n'
sed -n '180,230p' internal/dao/file.go
printf '\n--- delete helper area ---\n'
sed -n '320,345p' internal/dao/file.go

# Look for any explicit transaction usage around the knowledgebase import path.
rg -n "Transaction\\(|Begin\\(|Commit\\(|Rollback\\(|addFileFromKB\\(" internal/dao internal/service | sed -n '1,120p'

Repository: infiniflow/ragflow

Length of output: 7703


Clean up the File row if File2Document insert fails.

addFileFromKB creates the entity.File row before the mapping row, but on DB.Create(f2d) error it returns immediately without deleting the file. That leaves orphaned files behind and makes retries create duplicate file rows instead of completing the link. The sibling internal/service/document.go path already deletes the file on this failure path.

🤖 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/file.go` around lines 512 - 517, The addFileFromKB flow creates
the entity.File before inserting the File2Document mapping, but the failure path
after DB.Create(f2d) currently returns without removing the newly created file.
Update the addFileFromKB logic in internal/dao/file.go so that when the
File2Document insert fails, it deletes the File row before returning, matching
the cleanup behavior used in internal/service/document.go. Use the existing file
variable and the mapping insert path around DB.Create(f2d) to locate the fix.

JinHai-CN added 3 commits July 7, 2026 16:21
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 7df7384 into infiniflow:main Jul 7, 2026
3 checks 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.

1 participant