{"record":{"id":"4eb641f1bcca5171","repo":"hashicorp/terraform","slug":"failed-to-generate-initial-lineage-v","errorCode":null,"errorMessage":"failed to generate initial lineage: %v","messagePattern":"failed to generate initial lineage: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloud/state.go","lineNumber":194,"sourceCode":"\t\t\t// If the state, lineage or serial haven't changed at all then we have nothing to do.\n\t\t\treturn nil\n\t\t}\n\t\ts.serial++\n\t} else {\n\t\t// We might be writing a new state altogether, but before we do that\n\t\t// we'll check to make sure there isn't already a snapshot present\n\t\t// that we ought to be updating.\n\t\terr := s.refreshState()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed checking for existing remote state: %s\", err)\n\t\t}\n\t\tlog.Printf(\"[DEBUG] cloud/state: after refresh, state read serial is: %d; serial is: %d\", s.readSerial, s.serial)\n\t\tlog.Printf(\"[DEBUG] cloud/state: after refresh, state read lineage is: %s; lineage is: %s\", s.readLineage, s.lineage)\n\n\t\tif s.lineage == \"\" { // indicates that no state snapshot is present yet\n\t\t\tlineage, err := uuid.GenerateUUID()\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to generate initial lineage: %v\", err)\n\t\t\t}\n\t\t\ts.lineage = lineage\n\t\t\ts.serial++\n\t\t}\n\t}\n\n\tf := statefile.New(s.state, s.lineage, s.serial)\n\n\tvar buf bytes.Buffer\n\terr := statefile.Write(f, &buf)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tvar jsonState []byte\n\tif schemas != nil {\n\t\tjsonState, err = jsonstate.Marshal(f, schemas)\n\t\tif err != nil {","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/cloud/state.go#L176-L212","documentation":"Returned by the state persister when, on a fresh workspace (s.readState == nil and lineage == \"\"), uuid.GenerateUUID() fails to produce a new state lineage UUID. UUID generation in this codebase is cryptographic random, so failure is exceptionally rare.","triggerScenarios":"First-ever state write to a cloud workspace; refreshState found no existing state so lineage is empty; the UUID generator's crypto/rand source returns an error (entropy exhaustion).","commonSituations":"Effectively never on normal systems. Could occur on a severely constrained environment where crypto/rand read fails (broken /dev/urandom, chroot/container without the device).","solutions":["Retry the operation (transient entropy issues usually clear).","Verify /dev/urandom (or the platform CSPRNG) is available and readable in the execution environment.","If reproducible, inspect the host's RNG health and container device mappings."],"exampleFix":"// before: first apply on fresh workspace fails generating lineage\n// after: ensure /dev/urandom is available in the container, then re-run\ndocker run --device /dev/urandom ... terraform apply","handlingStrategy":"retry","validationCode":"// Sanity-check the CSPRNG is available before first write.\nif _, err := os.Open(\"/dev/urandom\"); err != nil {\n    return fmt.Errorf(\"no CSPRNG available for state lineage\")\n}","typeGuard":null,"tryCatchPattern":"var lineage string\nfor i := 0; i < 3; i++ {\n    var e error\n    lineage, e = uuid.GenerateUUID()\n    if e == nil { break }\n    time.Sleep(100 * time.Millisecond)\n}","preventionTips":["Ensure /dev/urandom is mounted in containers.","Retry on rare entropy failures rather than aborting.","Health-check the host RNG in base images."],"tags":["terraform","cloud-backend","state","lineage","uuid","crypto-rand","rare"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}