Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/backend/handlers/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/gin-gonic/gin"
"github.com/google/uuid"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -440,7 +441,7 @@ func exchangeOAuthCode(ctx context.Context, provider *OAuthProvider, code string
func storeOAuthCallback(ctx context.Context, state string, data *OAuthCallbackData) error {
if state == "" {
// Generate a default key if no state provided
state = fmt.Sprintf("callback_%d", time.Now().Unix())
state = fmt.Sprintf("callback_%s", uuid.New().String())
}

const secretName = "oauth-callbacks"
Expand Down
7 changes: 4 additions & 3 deletions components/backend/handlers/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/gin-gonic/gin"
"github.com/google/uuid"
authnv1 "k8s.io/api/authentication/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
Expand Down Expand Up @@ -389,8 +390,8 @@ func CreateProjectKey(c *gin.Context) {
}

// Create a dedicated ServiceAccount per key
ts := time.Now().Unix()
saName := fmt.Sprintf("ambient-key-%s-%d", sanitizeName(req.Name), ts)
uid := uuid.New().String()[:8]
saName := fmt.Sprintf("ambient-key-%s-%s", sanitizeName(req.Name), uid)
sa := &corev1.ServiceAccount{
ObjectMeta: v1.ObjectMeta{
Name: saName,
Expand All @@ -412,7 +413,7 @@ func CreateProjectKey(c *gin.Context) {
}

// Bind the SA to the selected role via RoleBinding
rbName := fmt.Sprintf("ambient-key-%s-%s-%d", role, sanitizeName(req.Name), ts)
rbName := fmt.Sprintf("ambient-key-%s-%s-%s", role, sanitizeName(req.Name), uid)
rb := &rbacv1.RoleBinding{
ObjectMeta: v1.ObjectMeta{
Name: rbName,
Expand Down
6 changes: 3 additions & 3 deletions components/backend/handlers/scheduled_sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"ambient-code-backend/types"

"github.com/gin-gonic/gin"
"github.com/google/uuid"
authzv1 "k8s.io/api/authorization/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -141,8 +142,7 @@ func CreateScheduledSession(c *gin.Context) {
}
}

timestamp := time.Now().Unix()
name := fmt.Sprintf("schedule-%d", timestamp)
name := fmt.Sprintf("schedule-%s", uuid.New().String())

// Inject display name into session template so the trigger can use it for naming
if req.DisplayName != "" && req.SessionTemplate.DisplayName == "" {
Expand Down Expand Up @@ -431,7 +431,7 @@ func TriggerScheduledSession(c *gin.Context) {
return
}

jobName := fmt.Sprintf("%s-manual-%d", name, time.Now().Unix())
jobName := fmt.Sprintf("%s-manual-%s", name, uuid.New().String()[:8])
job := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: jobName,
Expand Down
6 changes: 3 additions & 3 deletions components/backend/handlers/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"ambient-code-backend/types"

"github.com/gin-gonic/gin"
"github.com/google/uuid"
authnv1 "k8s.io/api/authentication/v1"
authzv1 "k8s.io/api/authorization/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -695,10 +696,9 @@ func CreateSession(c *gin.Context) {
timeout = *req.Timeout
}

// Generate unique name (timestamp-based)
// Generate unique name (UUID-based)
// Note: Runner will create branch as "ambient/{session-name}"
timestamp := time.Now().Unix()
name := fmt.Sprintf("session-%d", timestamp)
name := fmt.Sprintf("session-%s", uuid.New().String())

// Create the custom resource
// Metadata
Expand Down
7 changes: 1 addition & 6 deletions components/backend/handlers/sessions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,8 @@ var _ = Describe("Sessions Handler", Label(test_constants.LabelUnit, test_consta

sessionNames := make([]string, 0)

// Create multiple sessions with delays to ensure unique timestamps
// Create multiple sessions concurrently - UUID-based names ensure uniqueness
for i := 0; i < 3; i++ {
// Add a delay to ensure unique timestamps (Unix() has 1-second precision)
if i > 0 {
time.Sleep(1001 * time.Millisecond) // Slightly over 1 second to ensure different Unix timestamps
}

context := httpUtils.CreateTestGinContext("POST", "/api/projects/"+testNamespace+"/agentic-sessions", sessionRequest)
httpUtils.SetAuthHeader(testToken)
httpUtils.SetProjectContext(testNamespace)
Expand Down
Loading