PrimeIntellect/SWE-rebench-V2 huggingface dataset:
Repository: argoproj/argo (go)

Issue:
Creator label too long.
## Summary 

> Is there a way to prevent the Argo Workflow REST API from auto-generating/adding the workflows.argoproj.io/creator label? The label it generates for Service Account credentials is extremely long (exceeding the 63 char limit) and causing API calls to fail.

## Diagnostics

> Failure: Workflow.argoproj.io \"hello-world-hxtr5\" is invalid: metadata.labels: Invalid value: \"system-serviceaccount-sandbox-sandbox-mehdi-wf-deleteme-usw2-ppd-qal-automation\": must be no more than 63 characters"

---
<!-- Issue Author: Don't delete this message to encourage other users to support your issue! -->
**Message from the maintainers**:

Impacted by this bug? Give it a 👍. We prioritise the issues with the most 👍.


Pull request:
fix(server): Truncate creator label at 63 chars. Fixes #3756
Checklist:

* [x] Either (a) I've created an [enhancement proposal](https://github.com/argoproj/argo/issues/new/choose) and discussed it with the community, (b) this is a bug fix, or (c) this is a chore.
* [x] The title of the PR is (a) [conventional](https://www.conventionalcommits.org/en/v1.0.0/), (b) states what changed, and (c) suffixes the related issues number. E.g. `"fix(controller): Updates such and such. Fixes #1234"`.  
* [x] I've signed the CLA.
* [x] I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
* [x] My builds are green. Try syncing with master if they are not. 
* [x] My organization is added to [USERS.md](https://github.com/argoproj/argo/blob/master/USERS.md).

 Fixes #3756

Patch:
diff --git a/workflow/creator/creator.go b/workflow/creator/creator.go
index 4bc165ddb..30d46c538 100644
--- a/workflow/creator/creator.go
+++ b/workflow/creator/creator.go
@@ -14,6 +14,10 @@ import (
 func Label(ctx context.Context, obj metav1.Object) {
 	claims := auth.GetClaimSet(ctx)
 	if claims != nil {
-		labels.Label(obj, common.LabelKeyCreator, regexp.MustCompile("[^-_.a-z0-9A-Z]").ReplaceAllString(claims.Sub, "-"))
+		value := regexp.MustCompile("[^-_.a-z0-9A-Z]").ReplaceAllString(claims.Sub, "-")
+		if len(value) > 63 {
+			value = value[len(value)-63:]
+		}
+		labels.Label(obj, common.LabelKeyCreator, value)
 	}
 }


Test patch:
diff --git a/workflow/creator/creator_test.go b/workflow/creator/creator_test.go
index 30d03785f..464b9e6b1 100644
--- a/workflow/creator/creator_test.go
+++ b/workflow/creator/creator_test.go
@@ -2,6 +2,7 @@ package creator
 
 import (
 	"context"
+	"strings"
 	"testing"
 
 	"github.com/stretchr/testify/assert"
@@ -25,4 +26,11 @@ func TestLabel(t *testing.T) {
 			assert.Contains(t, wf.Labels, common.LabelKeyCreator)
 		}
 	})
+	t.Run("TooLong", func(t *testing.T) {
+		wf := &wfv1.Workflow{}
+		Label(context.WithValue(context.TODO(), auth.ClaimSetKey, &jws.ClaimSet{Sub: strings.Repeat("x", 63) + "y"}), wf)
+		if assert.NotEmpty(t, wf.Labels) {
+			assert.Equal(t, strings.Repeat("x", 62)+"y", wf.Labels[common.LabelKeyCreator])
+		}
+	})
 }