@@ -24,7 +24,7 @@ const (
24
24
Requirements:
25
25
- Only lowercase letters, numbers, and hyphens
26
26
- Start with "task-"
27
- - Maximum28 characters total
27
+ - Maximum27 characters total
28
28
- Descriptive of the main task
29
29
30
30
Examples:
@@ -145,17 +145,23 @@ func Generate(ctx context.Context, prompt string, opts ...Option) (string, error
145
145
return "" ,ErrNoNameGenerated
146
146
}
147
147
148
- generatedName := acc .Messages ()[0 ].Content
149
-
150
- if err := codersdk .NameValid (generatedName );err != nil {
151
- return "" ,xerrors .Errorf ("generated name %v not valid: %w" ,generatedName ,err )
148
+ taskName := acc .Messages ()[0 ].Content
149
+ if taskName == "task-unnamed" {
150
+ return "" ,ErrNoNameGenerated
152
151
}
153
152
154
- if generatedName == "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 sulg), 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
+ if err := codersdk .NameValid (taskName );err != nil {
161
+ return "" ,xerrors .Errorf ("generated name %v not valid: %w" ,taskName ,err )
156
162
}
157
163
158
- return fmt . Sprintf ( "%s-%s" , generatedName , generateSuffix ()) ,nil
164
+ return taskName ,nil
159
165
}
160
166
161
167
func anthropicDataStream (ctx context.Context ,client anthropic.Client ,model anthropic.Model ,input []aisdk.Message ) (aisdk.DataStream ,error ) {