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

Commit4cb1621

Browse files
fix(coderd/agentapi): make sub agent slugs more unique
The incorrect assumption that slugs were unique per-agent was made whenthe subagent API was implemented. Whilst this PR doesn't completelyenforce that, we instead compute a stable hash to prefix the slug thatshould provide a reasonable level of probability that the slug will beunique.
1 parent3c4d920 commit4cb1621

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

‎coderd/agentapi/subagent.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"database/sql"
66
"errors"
77
"fmt"
8+
"hash/crc32"
89
"strings"
910

1011
"github.com/google/uuid"
@@ -165,11 +166,19 @@ func (a *SubAgentAPI) CreateSubAgent(ctx context.Context, req *agentproto.Create
165166
}
166167
}
167168

169+
// NOTE(DanielleMaywood):
170+
// Slugs must be unique PER workspace/template. As of 2025-06-25,
171+
// there is no database-layer enforcement of this constraint.
172+
// We can get around this by creating a slug that *should* be
173+
// unique (at least highly probable).
174+
slugHash:=fmt.Sprintf("%08x",crc32.ChecksumIEEE([]byte(subAgent.Name+"/"+app.Slug)))
175+
computedSlug:=slugHash+"-"+app.Slug
176+
168177
_,err:=a.Database.UpsertWorkspaceApp(ctx, database.UpsertWorkspaceAppParams{
169178
ID:uuid.New(),// NOTE: we may need to maintain the app's ID here for stability, but for now we'll leave this as-is.
170179
CreatedAt:createdAt,
171180
AgentID:subAgent.ID,
172-
Slug:app.Slug,
181+
Slug:computedSlug,
173182
DisplayName:app.GetDisplayName(),
174183
Icon:app.GetIcon(),
175184
Command: sql.NullString{

‎coderd/agentapi/subagent_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func TestSubAgentAPI(t *testing.T) {
216216
},
217217
expectApps: []database.WorkspaceApp{
218218
{
219-
Slug:"code-server",
219+
Slug:"d2b537b8-code-server",
220220
DisplayName:"VS Code",
221221
Icon:"/icon/code.svg",
222222
Command: sql.NullString{},
@@ -234,7 +234,7 @@ func TestSubAgentAPI(t *testing.T) {
234234
DisplayGroup: sql.NullString{},
235235
},
236236
{
237-
Slug:"vim",
237+
Slug:"9c813024-vim",
238238
DisplayName:"Vim",
239239
Icon:"/icon/vim.svg",
240240
Command: sql.NullString{Valid:true,String:"vim"},
@@ -377,7 +377,7 @@ func TestSubAgentAPI(t *testing.T) {
377377
},
378378
expectApps: []database.WorkspaceApp{
379379
{
380-
Slug:"valid-app",
380+
Slug:"7f9e8fef-valid-app",
381381
DisplayName:"Valid App",
382382
SharingLevel:database.AppSharingLevelOwner,
383383
Health:database.WorkspaceAppHealthDisabled,
@@ -410,19 +410,19 @@ func TestSubAgentAPI(t *testing.T) {
410410
},
411411
expectApps: []database.WorkspaceApp{
412412
{
413-
Slug:"authenticated-app",
413+
Slug:"51f592de-authenticated-app",
414414
SharingLevel:database.AppSharingLevelAuthenticated,
415415
Health:database.WorkspaceAppHealthDisabled,
416416
OpenIn:database.WorkspaceAppOpenInSlimWindow,
417417
},
418418
{
419-
Slug:"owner-app",
419+
Slug:"cad4f019-owner-app",
420420
SharingLevel:database.AppSharingLevelOwner,
421421
Health:database.WorkspaceAppHealthDisabled,
422422
OpenIn:database.WorkspaceAppOpenInSlimWindow,
423423
},
424424
{
425-
Slug:"public-app",
425+
Slug:"9e367a4c-public-app",
426426
SharingLevel:database.AppSharingLevelPublic,
427427
Health:database.WorkspaceAppHealthDisabled,
428428
OpenIn:database.WorkspaceAppOpenInSlimWindow,
@@ -443,13 +443,13 @@ func TestSubAgentAPI(t *testing.T) {
443443
},
444444
expectApps: []database.WorkspaceApp{
445445
{
446-
Slug:"tab-app",
446+
Slug:"6cb5ae2b-tab-app",
447447
SharingLevel:database.AppSharingLevelOwner,
448448
Health:database.WorkspaceAppHealthDisabled,
449449
OpenIn:database.WorkspaceAppOpenInTab,
450450
},
451451
{
452-
Slug:"window-app",
452+
Slug:"11675927-window-app",
453453
SharingLevel:database.AppSharingLevelOwner,
454454
Health:database.WorkspaceAppHealthDisabled,
455455
OpenIn:database.WorkspaceAppOpenInSlimWindow,
@@ -479,7 +479,7 @@ func TestSubAgentAPI(t *testing.T) {
479479
},
480480
expectApps: []database.WorkspaceApp{
481481
{
482-
Slug:"full-app",
482+
Slug:"1067629f-full-app",
483483
Command: sql.NullString{Valid:true,String:"echo hello"},
484484
DisplayName:"Full Featured App",
485485
External:true,
@@ -507,7 +507,7 @@ func TestSubAgentAPI(t *testing.T) {
507507
},
508508
expectApps: []database.WorkspaceApp{
509509
{
510-
Slug:"no-health-app",
510+
Slug:"3290f004-no-health-app",
511511
Health:database.WorkspaceAppHealthDisabled,
512512
SharingLevel:database.AppSharingLevelOwner,
513513
OpenIn:database.WorkspaceAppOpenInSlimWindow,
@@ -531,7 +531,7 @@ func TestSubAgentAPI(t *testing.T) {
531531
},
532532
expectApps: []database.WorkspaceApp{
533533
{
534-
Slug:"duplicate-app",
534+
Slug:"6977f2fe-duplicate-app",
535535
DisplayName:"First App",
536536
SharingLevel:database.AppSharingLevelOwner,
537537
Health:database.WorkspaceAppHealthDisabled,
@@ -568,14 +568,14 @@ func TestSubAgentAPI(t *testing.T) {
568568
},
569569
expectApps: []database.WorkspaceApp{
570570
{
571-
Slug:"duplicate-app",
571+
Slug:"6977f2fe-duplicate-app",
572572
DisplayName:"First Duplicate",
573573
SharingLevel:database.AppSharingLevelOwner,
574574
Health:database.WorkspaceAppHealthDisabled,
575575
OpenIn:database.WorkspaceAppOpenInSlimWindow,
576576
},
577577
{
578-
Slug:"valid-app",
578+
Slug:"7f9e8fef-valid-app",
579579
DisplayName:"Valid App",
580580
SharingLevel:database.AppSharingLevelOwner,
581581
Health:database.WorkspaceAppHealthDisabled,
@@ -754,7 +754,7 @@ func TestSubAgentAPI(t *testing.T) {
754754
apps,err:=db.GetWorkspaceAppsByAgentID(dbauthz.AsSystemRestricted(ctx),agentID)//nolint:gocritic // this is a test.
755755
require.NoError(t,err)
756756
require.Len(t,apps,1)
757-
require.Equal(t,"duplicate-slug",apps[0].Slug)
757+
require.Equal(t,"b219bd99-duplicate-slug",apps[0].Slug)
758758
require.Equal(t,"First Duplicate",apps[0].DisplayName)
759759
})
760760
})
@@ -1128,7 +1128,7 @@ func TestSubAgentAPI(t *testing.T) {
11281128
apps,err:=api.Database.GetWorkspaceAppsByAgentID(dbauthz.AsSystemRestricted(ctx),agentID)//nolint:gocritic // this is a test.
11291129
require.NoError(t,err)
11301130
require.Len(t,apps,1)
1131-
require.Equal(t,"custom-app",apps[0].Slug)
1131+
require.Equal(t,"9cc545fe-custom-app",apps[0].Slug)
11321132
require.Equal(t,"Custom App",apps[0].DisplayName)
11331133
})
11341134

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp