Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit347ab5b

Browse files
fix(coderd/taskname): ensure generated name is within 32 byte limit (#19612)
The previous logic verified a generated name was valid, _and thenappended a suffix to it_. This was flawed as it would allow a 32character name, and then append an extra 5 characters to it.Instead we now append the suffix _and then_ verify it is valid.
1 parent8c731a0 commit347ab5b

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

‎coderd/taskname/taskname.go‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
Requirements:
2525
- Only lowercase letters, numbers, and hyphens
2626
- Start with "task-"
27-
- Maximum28 characters total
27+
- Maximum27 characters total
2828
- Descriptive of the main task
2929
3030
Examples:
@@ -145,17 +145,23 @@ func Generate(ctx context.Context, prompt string, opts ...Option) (string, error
145145
return"",ErrNoNameGenerated
146146
}
147147

148-
generatedName:=acc.Messages()[0].Content
149-
150-
iferr:=codersdk.NameValid(generatedName);err!=nil {
151-
return"",xerrors.Errorf("generated name %v not valid: %w",generatedName,err)
148+
taskName:=acc.Messages()[0].Content
149+
iftaskName=="task-unnamed" {
150+
return"",ErrNoNameGenerated
152151
}
153152

154-
ifgeneratedName=="task-unnamed" {
155-
return"",ErrNoNameGenerated
153+
// We append a suffix to the end of the task name to reduce
154+
// the chance of collisions. We truncate the task name to
155+
// to a maximum of 27 bytes, so that when we append the
156+
// 5 byte suffix (`-` and 4 byte hex slug), it should
157+
// remain within the 32 byte workspace name limit.
158+
taskName=taskName[:min(len(taskName),27)]
159+
taskName=fmt.Sprintf("%s-%s",taskName,generateSuffix())
160+
iferr:=codersdk.NameValid(taskName);err!=nil {
161+
return"",xerrors.Errorf("generated name %v not valid: %w",taskName,err)
156162
}
157163

158-
returnfmt.Sprintf("%s-%s",generatedName,generateSuffix()),nil
164+
returntaskName,nil
159165
}
160166

161167
funcanthropicDataStream(ctx context.Context,client anthropic.Client,model anthropic.Model,input []aisdk.Message) (aisdk.DataStream,error) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp