{"record":{"id":"41f5804bc27edd1a","repo":"temporalio/temporal","slug":"failed-to-decode-temporalnamespacedivision-field","errorCode":null,"errorMessage":"failed to decode TemporalNamespaceDivision field: %w","messagePattern":"failed to decode TemporalNamespaceDivision field: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/worker/common/chasm_util.go","lineNumber":29,"sourceCode":"\t\"go.temporal.io/server/common/searchattribute/sadefs\"\n)\n\nfunc ArchetypeIDFromExecutionInfo(\n\texecutionInfo *workflowpb.WorkflowExecutionInfo,\n) (chasm.ArchetypeID, error) {\n\tindexedField := executionInfo.SearchAttributes.GetIndexedFields()\n\tif indexedField == nil {\n\t\treturn chasm.WorkflowArchetypeID, nil\n\t}\n\n\tnsDivisionPayload, ok := indexedField[sadefs.TemporalNamespaceDivision]\n\tif !ok {\n\t\treturn chasm.WorkflowArchetypeID, nil\n\t}\n\n\tvar nsDivisionStr string\n\tif err := payload.Decode(nsDivisionPayload, &nsDivisionStr); err != nil {\n\t\treturn chasm.UnspecifiedArchetypeID, fmt.Errorf(\"failed to decode TemporalNamespaceDivision field: %w\", err)\n\t}\n\n\tif len(nsDivisionStr) == 0 || !unicode.IsDigit(rune(nsDivisionStr[0])) {\n\t\treturn chasm.WorkflowArchetypeID, nil\n\t}\n\n\tarchetypeID, err := strconv.ParseUint(nsDivisionStr, 10, 32)\n\tif err != nil {\n\t\treturn chasm.UnspecifiedArchetypeID, fmt.Errorf(\"failed to parse archetypeID: %w\", err)\n\t}\n\n\treturn chasm.ArchetypeID(archetypeID), nil\n}\n","sourceCodeStart":11,"sourceCodeEnd":43,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/service/worker/common/chasm_util.go#L11-L43","documentation":"ArchetypeIDFromExecutionInfo extracts a CHASM archetype ID from the workflow execution info's TemporalNamespaceDivision payload. If the raw payload cannot be decoded into a string (corrupt or wrongly-encoded data), the function returns UnspecifiedArchetypeID along with this wrapped error.","triggerScenarios":"Calling ArchetypeIDFromExecutionInfo on an execution info whose namespace-division payload was written with a non-string encoding (e.g. binary/protobuf bytes instead of a plain string payload) or is corrupted in persistence.","commonSituations":"Mixed-version clusters where an older writer encoded the field differently than the current decoder expects; data migrations or manual persistence edits; CHASM experiments flag differences between services writing and reading the field.","solutions":["Inspect the payload's encoding/metadata and re-encode it as the expected plain string before storage.","Ensure all services in the cluster run compatible versions so the TemporalNamespaceDivision field is written and read consistently.","Treat UnspecifiedArchetypeID + error as a fallback (defaults to WorkflowArchetypeID only for empty/non-digit strings) and alert on the decode failure to catch data corruption early.","If the payload is unrecoverable, clear/rewrite the field via the appropriate migration so future writes use the string encoding."],"exampleFix":"// before\npayload := payloads.NewEncodedValue(raw, \"unknown-encoding\")\ninfo.NamespaceDivision = payload // fails to decode later\n// after\nb, _ := proto.Marshal(&commonpb.Payload{Metadata: map[string]string{\"encoding\": encodingtype.Raw}, Data: []byte(nsDivision)})\ninfo.NamespaceDivision = payloads.NewData(b) // decodable string payload","handlingStrategy":"type-guard","validationCode":"func nsDivisionDecodable(p *commonpb.Payload) error {\n  var s string\n  if err := payload.Decode(p, &s); err != nil {\n    return err\n  }\n  return nil\n}","typeGuard":"func isStringPayload(p *commonpb.Payload) bool {\n  enc := p.GetMetadata()[\"encoding\"]\n  return enc == encodingtype.String || enc == encodingtype.Json\n}","tryCatchPattern":"archetypeID, err := common.ArchetypeIDFromExecutionInfo(info)\nif err != nil {\n  logger.Warn(\"namespace division payload undecodable; defaulting archetype\", tag.Error(err))\n  archetypeID = chasm.WorkflowArchetypeID\n}","preventionTips":["Write TemporalNamespaceDivision only as a plain string payload.","Keep CHASM library versions consistent across all services that write this field.","Avoid manual persistence edits to payload fields.","Monitor decode errors as an early signal of data corruption or version skew."],"tags":["go","chasm","payload-decode","serialization"],"backgroundTag":"payload-decode-failed","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}