Skip to content

Commit a0e41c1

Browse files
fix: increase suffix length to 4 chars to reduce collision risk
1 parent 74bfabc commit a0e41c1

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

coderd/taskname/taskname.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,27 @@ func GetAnthropicModelFromEnv() anthropic.Model {
6969
return anthropic.Model(os.Getenv("ANTHROPIC_MODEL"))
7070
}
7171

72-
// generateSuffix generates a random hex string between `000` and `fff`.
72+
// generateSuffix generates a random hex string between `0000` and `ffff`.
7373
func generateSuffix() string {
74-
numMin := 0x0000
75-
numMax := 0x1000
74+
numMin := 0x00000
75+
numMax := 0x10000
7676
//nolint:gosec // We don't need a cryptographically secure random number generator for generating a task name suffix.
7777
num := rand.IntN(numMax-numMin) + numMin
7878

79-
return fmt.Sprintf("%03x", num)
79+
return fmt.Sprintf("%04x", num)
8080
}
8181

8282
func GenerateFallback() string {
8383
// We have a 32 character limit for the name.
8484
// We have a 5 character prefix `task-`.
85-
// We have a 4 character suffix `-fff`.
86-
// This leaves us with 23 characters for the middle.
85+
// We have a 5 character suffix `-ffff`.
86+
// This leaves us with 22 characters for the middle.
8787
//
8888
// Unfortunately, `namesgenerator.GetRandomName(0)` will
89-
// generate names that are longer than 23 characters, so
89+
// generate names that are longer than 22 characters, so
9090
// we just trim these down to length.
9191
name := strings.ReplaceAll(namesgenerator.GetRandomName(0), "_", "-")
92-
name = name[:min(len(name), 23)]
92+
name = name[:min(len(name), 22)]
9393
name = strings.TrimSuffix(name, "-")
9494

9595
return fmt.Sprintf("task-%s-%s", name, generateSuffix())

0 commit comments

Comments
 (0)