Skip to content

refactor(go): replace GenerateUUID1 with GenerateToken for entity IDs - #16010

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
Harry-Hz-Zhang:replace-generateUUID1-with-generatetoken
Jun 15, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
Harry-Hz-Zhang:replace-generateUUID1-with-generatetoken

Conversation

@Harry-Hz-Zhang

Copy link
Copy Markdown
Contributor

Description

  • Refactor: Replaced utility.GenerateUUID1 (UUID v1) with utility.GenerateToken (UUID v4) for generating entity IDs (userID, kbID, modelID, etc.).

  • Cleanup: Removed the unused GenerateUUID1 function from utility package.

  • Improvement: Simplified ID generation logic and eliminated unnecessary error handling boilerplate since GenerateToken cannot fail.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. ☯️ refactor Pull request that refactor/refine code labels Jun 15, 2026
@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

GenerateUUID1() (string, error) is removed from internal/utility/token.go and replaced with GenerateToken() string, which calls uuid.New() and strips dashes. All ID generation call sites in dataset.go, model_service.go, and user.go are updated to use the new function, removing the associated UUID error-handling branches.

Changes

UUID Generation Refactor

Layer / File(s) Summary
GenerateToken utility replacement
internal/utility/token.go
Removes GenerateUUID1() (string, error) and adds GenerateToken() string, which uses uuid.New() and strips dashes, eliminating the error return path entirely.
Service call-site updates
internal/service/dataset.go, internal/service/model_service.go, internal/service/user.go
Replaces all utility.GenerateUUID1() calls (and their error-handling blocks) with utility.GenerateToken() in CreateDataset, AddModelProvider, CreateProviderInstance, UpdateModelStatus, AddModel, and UserService.Register.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 A UUID once returned two things,
A string and an error with stings.
Now GenerateToken just hops along free,
No error to catch — just a plain UUID!
Less code, less fuss, more hoppity glee. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description is missing the required 'Type of change' section with checkboxes from the template, though it provides clear context about the refactoring work. Add the 'Type of change' section to the description and select 'Refactoring' as the appropriate category to fully comply with the repository template.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: replacing GenerateUUID1 with GenerateToken for entity ID generation.
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.

✏️ 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.

@Harry-Hz-Zhang Harry-Hz-Zhang added the ci Continue Integration label Jun 15, 2026
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft June 15, 2026 03:58
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review June 15, 2026 03:58

@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/service/dataset.go`:
- Line 859: The CreateDataset function generates UUIDv4 IDs using
utility.GenerateToken, but downstream functions including ListDatasets,
DeleteDatasets, and GetDataset all validate IDs through normalizeDatasetUUID1,
which explicitly rejects non-v1 UUIDs at Lines 1416-1418. This causes newly
created datasets to fail validation in lookup and delete operations. Either
change the ID generation in CreateDataset to use a UUIDv1-compatible approach
instead of utility.GenerateToken, or refactor the normalization function to
accept both UUID versions and update all callers of normalizeDatasetUUID1 (in
ListDatasets, DeleteDatasets, GetDataset, and any other locations) to use a new
normalization function that handles both UUID v1 and v4 formats.
🪄 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: 1c0423e9-978e-43af-b64f-9a86e82dde06

📥 Commits

Reviewing files that changed from the base of the PR and between 400dfd5 and cd81a99.

📒 Files selected for processing (4)
  • internal/service/dataset.go
  • internal/service/model_service.go
  • internal/service/user.go
  • internal/utility/token.go
💤 Files with no reviewable changes (1)
  • internal/utility/token.go

if err != nil {
return nil, common.CodeServerError, errors.New("Internal server error")
}
kbID := utility.GenerateToken()

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

UUID version contract mismatch breaks ID-based dataset flows.

At Line 859, CreateDataset now generates a UUIDv4-based ID, but ListDatasets (Line 580), DeleteDatasets (Line 913), and GetDataset (Line 993) still normalize through normalizeDatasetUUID1, which rejects non-v1 IDs at Lines 1416–1418. New datasets created here can fail lookup/delete paths that validate IDs through that function.

💡 Suggested fix
-func normalizeDatasetUUID1(id string) (string, error) {
+func normalizeDatasetID(id string) (string, error) {
 	parsedUUID, err := uuid.Parse(id)
 	if err != nil {
-		return "", errors.New("Invalid UUID1 format")
-	}
-	if parsedUUID.Version() != 1 {
-		return "", errors.New("Must be a UUID1 format")
+		return "", errors.New("Invalid UUID format")
 	}
 	return strings.ReplaceAll(parsedUUID.String(), "-", ""), nil
}
- normalizedID, err := normalizeDatasetUUID1(datasetID)
+ normalizedID, err := normalizeDatasetID(datasetID)

(Apply similarly at the other UUID1-only normalization call sites in this file.)

🤖 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/dataset.go` at line 859, The CreateDataset function
generates UUIDv4 IDs using utility.GenerateToken, but downstream functions
including ListDatasets, DeleteDatasets, and GetDataset all validate IDs through
normalizeDatasetUUID1, which explicitly rejects non-v1 UUIDs at Lines 1416-1418.
This causes newly created datasets to fail validation in lookup and delete
operations. Either change the ID generation in CreateDataset to use a
UUIDv1-compatible approach instead of utility.GenerateToken, or refactor the
normalization function to accept both UUID versions and update all callers of
normalizeDatasetUUID1 (in ListDatasets, DeleteDatasets, GetDataset, and any
other locations) to use a new normalization function that handles both UUID v1
and v4 formats.

@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 (83e2180) to head (cd81a99).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16010   +/-   ##
=======================================
  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 bc963f8 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:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants