{"record":{"id":"484f46a49689c8e1","repo":"plandex-ai/plandex","slug":"old-content-does-not-have-a-line-number-prefix-for","errorCode":null,"errorMessage":"old content does not have a line number prefix for first line","messagePattern":"old content does not have a line number prefix for first line","errorType":"validation","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/model/plan/build_validate_and_fix.go","lineNumber":391,"sourceCode":"\t\tlog.Printf(\"Processing replacement: %d/%d\", i+1, len(replacements))\n\n\t\told := utils.GetXMLContent(replacement, \"Old\")\n\t\tnew := utils.GetXMLContent(replacement, \"New\")\n\n\t\tif old == \"\" {\n\t\t\tlog.Printf(\"No old content found for replacement\")\n\t\t\treturn buildValidateResult{valid: false, updated: updated}, fmt.Errorf(\"no old content found for replacement\")\n\t\t}\n\n\t\told = strings.TrimSpace(old)\n\n\t\t// log.Printf(\"Old content trimmed:\\n\\n%s\", strconv.Quote(old))\n\n\t\t// log.Printf(\"New content:\\n\\n%s\", strconv.Quote(new))\n\n\t\tif !strings.HasPrefix(old, \"pdx-\") {\n\t\t\tlog.Printf(\"Old content does not have a line number prefix for first line\")\n\t\t\treturn buildValidateResult{valid: false, updated: updated}, fmt.Errorf(\"old content does not have a line number prefix for first line\")\n\t\t}\n\n\t\toldLines := strings.Split(old, \"\\n\")\n\n\t\tvar lastLine string\n\t\tvar lastLineNum int\n\t\tfirstLine := oldLines[0]\n\t\tif len(oldLines) > 1 {\n\t\t\tlastLine = oldLines[len(oldLines)-1]\n\t\t}\n\n\t\tfirstLineNum, err := shared.ExtractLineNumberWithPrefix(firstLine, \"pdx-\")\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error extracting line number from first line: %v\", err)\n\t\t\treturn buildValidateResult{valid: false, updated: updated}, fmt.Errorf(\"error extracting line number from first line: %v\", err)\n\t\t}\n\n\t\tif lastLine != \"\" {","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/model/plan/build_validate_and_fix.go#L373-L409","documentation":"During XML response handling in buildValidate, the model-supplied 'old' content block must begin with a 'pdx-' line-number prefix so it can be matched against the original file. This error is thrown when the first line of the old-content region lacks that prefix, making the edit target impossible to locate. It aborts validation with valid=false.","triggerScenarios":"The LLM returns a replace/old block whose first line does not start with 'pdx-<num>' (e.g. it omits line-number prefixes or emits raw file content).","commonSituations":"Models drifting from the prompt format, copying content without the prefixed first line, or emitting an empty/blank old block after trimming.","solutions":["Retry the build validation so the model regenerates a correctly prefixed old block","Check prompt/ instructions emphasize that old content must start with 'pdx-N' on the first line","Inspect logged 'Old content' output to see exactly what the model produced and adjust parsing or prompting accordingly"],"exampleFix":"// before\nold = \"func main() {}\"\n// after\nold = \"pdx-10 func main() {}\"","handlingStrategy":"validation","validationCode":"if !strings.HasPrefix(old, \"pdx-\") {\n    return fmt.Errorf(\"old content must start with pdx- line number prefix\")\n}","typeGuard":"func hasLineNumberPrefix(s string) bool {\n    idx := strings.Index(s, \"pdx-\")\n    if idx != 0 { return false }\n    rest := strings.TrimPrefix(s, \"pdx-\")\n    n, err := strconv.Atoi(strings.Fields(rest)[0])\n    return err == nil && n > 0\n}","tryCatchPattern":null,"preventionTips":["Always include line-number prefixes on old-content first lines","Pre-validate model output format before applying edits","Retry generation when prefix validation fails"],"tags":["go","parsing","llm-output","line-numbers"],"backgroundTag":"missing-line-number-prefix","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}