{"record":{"id":"ed67b0ed2c29c6b9","repo":"VictoriaMetrics/VictoriaMetrics","slug":"cannot-read-accountid","errorCode":null,"errorMessage":"cannot read AccountID","messagePattern":"cannot read AccountID","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/prompb/write_request_unmarshaler.go","lineNumber":695,"sourceCode":"\t\t\t\treturn fmt.Errorf(\"cannot read metric family name\")\n\t\t\t}\n\t\t\tmm.MetricFamilyName = value\n\t\tcase 4:\n\t\t\tvalue, ok := fc.String()\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"cannot read help\")\n\t\t\t}\n\t\t\tmm.Help = value\n\t\tcase 5:\n\t\t\tvalue, ok := fc.String()\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"cannot read unit\")\n\t\t\t}\n\t\t\tmm.Unit = value\n\t\tcase 11:\n\t\t\tvalue, ok := fc.Uint32()\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"cannot read AccountID\")\n\t\t\t}\n\t\t\tmm.AccountID = value\n\t\tcase 12:\n\t\t\tvalue, ok := fc.Uint32()\n\t\t\tif !ok {\n\t\t\t\treturn fmt.Errorf(\"cannot read ProjectID\")\n\t\t\t}\n\t\t\tmm.ProjectID = value\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":677,"sourceCodeEnd":708,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/prompb/write_request_unmarshaler.go#L677-L708","documentation":"MetricMetadata field 11 is 'AccountID' (uint32, a VictoriaMetrics extension field). fc.Uint32() returns ok=false when the field bytes are not a valid varint or the buffer ends mid-value. The library reports 'cannot read AccountID', indicating this extension field was encoded with a wrong wire type or truncated.","triggerScenarios":"AccountID encoded as fixed32/bytes instead of varint, truncated buffer at field 11, or a sender mixing Prometheus-generated metadata (no fields 11/12) with a VictoriaMetrics-specific encoder.","commonSituations":"Cluster tenants sending custom-encoded metadata, truncated bodies in multi-tenant gateways, hand-rolled serializers writing the AccountID with the wrong type.","solutions":["Encode AccountID as a uint32 varint (field 11) per the VM-extended MetricMetadata schema.","Regenerate the sender from the VictoriaMetrics prompb .proto so extension fields match.","Check the body for truncation before decoding.","Return 400 and log the payload region around the failure."],"exampleFix":"// sender side: before — AccountID as bytes\nbuf.EncodeStringBytes(11, []byte(accountID))\n\n// after — uint32 varint\nbuf.EncodeUint32(11, mm.AccountID)","handlingStrategy":"type-guard","validationCode":"// VM extension fields: validate tenant IDs fit uint32 before encoding\nfunc validAccountID(id uint32) bool {\n    return id > 0\n}\nif !validAccountID(mm.AccountID) {\n    return errors.New(\"AccountID must be a positive uint32\")\n}","typeGuard":"func isVarintUint32Field(b []byte, fieldNum int) bool {\n    if len(b) < 1 {\n        return false\n    }\n    tag := b[0]\n    return int(tag>>3) == fieldNum && tag&0x7 == 0\n}","tryCatchPattern":"if err := wr.Unmarshal(body); err != nil {\n    if strings.Contains(err.Error(), \"cannot read AccountID\") {\n        http.Error(w, \"invalid AccountID encoding in metadata\", http.StatusBadRequest)\n        return\n    }\n    return err\n}","preventionTips":["Regenerate senders from the VictoriaMetrics-extended prompb .proto so fields 11/12 match","Encode tenant IDs as uint32 varint, never as bytes or fixed32","In multi-tenant gateways, forward the body byte-for-byte rather than re-encoding","Add round-trip tests that include AccountID/ProjectID extension fields"],"tags":["protobuf","wire-type","victoria-metrics"],"backgroundTag":"malformed-protobuf-wire-format","analyzedSha":"5079fb58f1e8e62113f90c945ad71586c797d770","analyzedAt":"2026-09-03T18:10:26.153Z","contentChangedAt":"2026-09-03T18:10:26.153Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}