{"record":{"id":"2240e574448c5cd1","repo":"argoproj/argo-workflows","slug":"invalid-cache-key-s","errorCode":null,"errorMessage":"invalid cache key: %s","messagePattern":"invalid cache key: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"workflow/controller/cache/configmap_cache.go","lineNumber":154,"sourceCode":"\terr := retry.OnError(kwait.Backoff{\n\t\tDuration: time.Second,\n\t\tFactor:   2,\n\t\tJitter:   0.1,\n\t\tSteps:    5,\n\t\tCap:      30 * time.Second,\n\t}, func(err error) bool {\n\t\treturn argoerr.IsTransientErr(ctx, err) || apierr.IsConflict(err)\n\t}, func() error {\n\t\tinnerErr := c.save(ctx, key, nodeID, value)\n\t\treturn innerErr\n\t})\n\treturn err\n}\n\nfunc (c *configMapCache) save(ctx context.Context, key string, nodeID string, value *wfv1.Outputs) error {\n\tif !cacheKeyRegex.MatchString(key) {\n\t\terrString := fmt.Sprintf(\"invalid cache key: %s\", key)\n\t\terr := errors.New(errString)\n\t\tc.logError(ctx, err, logging.Fields{\"key\": key}, errString)\n\t\treturn err\n\t}\n\n\tc.lock.Lock()\n\tdefer c.lock.Unlock()\n\n\tc.logInfo(ctx, logging.Fields{\"key\": key, \"nodeID\": nodeID}, \"Saving ConfigMap cache entry\")\n\n\tcache, err := c.kubeClient.CoreV1().ConfigMaps(c.namespace).Get(ctx, c.name, metav1.GetOptions{})\n\tif apierr.IsNotFound(err) || cache == nil {\n\t\tcache, err = c.kubeClient.CoreV1().ConfigMaps(c.namespace).Create(ctx, &apiv1.ConfigMap{\n\t\t\tObjectMeta: metav1.ObjectMeta{\n\t\t\t\tName: c.name,\n\t\t\t},\n\t\t}, metav1.CreateOptions{})\n\t\tif err != nil {\n\t\t\tc.logError(ctx, err, logging.Fields{\"key\": key, \"nodeID\": nodeID}, \"Error saving to ConfigMap cache\")","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/workflow/controller/cache/configmap_cache.go#L136-L172","documentation":"When saving a memoization cache entry, the cache key must match cacheKeyRegex (a DNS-subdomain-like pattern). Keys that are too long (>253 chars) or contain invalid characters are rejected with this error, because ConfigMap keys/annotations cannot safely hold arbitrary strings.","triggerScenarios":"Calling save() (via SaveStreamViaTempFile or the anonymous key-construction path) with a memoization `key` value that fails cacheKeyRegex — typically a key longer than 253 characters or containing illegal characters (spaces, slashes, uppercase-unsafe values, etc.).","commonSituations":"Users set `memoization.key` from template expressions that embed long IDs (image digests, URLs, git SHAs concatenated); keys with `/` or spaces; generated keys exceeding ConfigMap limits.","solutions":["Shorten the memoization key to <=253 chars and keep it to [a-z0-9] with '-'/'.' separators.","Hash a long value into the key instead of embedding it, e.g. use sha256 of the input string.","Check the template expression building the key for unexpected content (full URLs, paths)."],"exampleFix":"# before\nmemoization:\n  key: config-{{workflow.parameters.configUrl}}\n# after\nmemoization:\n  key: config-{{=sprig.sha256sum(workflow.parameters.configUrl)}}","handlingStrategy":"validation","validationCode":"import \"regexp\"\nvar cacheKeyRegex = regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`)\nfunc validCacheKey(k string) bool {\n    return len(k) <= 253 && cacheKeyRegex.MatchString(k)\n}","typeGuard":"func isValidCacheKey(key string) bool {\n    return len(key) <= 253 && regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`).MatchString(key)\n}","tryCatchPattern":"if err := node.SaveOutput(...); err != nil && strings.Contains(err.Error(), \"invalid cache key\") {\n    // recompute a shorter, DNS-safe key and retry\n}","preventionTips":["Keep memoization keys short and DNS-subdomain-safe (<=253 chars, lowercase alnum/-/.)","Hash long inputs (sha256) instead of embedding raw URLs/IDs in keys","Avoid template expressions that may inject spaces, slashes, or uppercase into keys"],"tags":["memoization","cache-key","validation"],"backgroundTag":"invalid-cache-key","analyzedSha":"35bff19146f5a6ada77468c431f2624bd577e373","analyzedAt":"2026-09-03T19:34:35.908Z","contentChangedAt":"2026-09-03T19:34:35.908Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}