plandex-ai/plandex · error
old content does not have a line number prefix for first lin
Error message
old content does not have a line number prefix for first line
What it means
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.
Source
Thrown at app/server/model/plan/build_validate_and_fix.go:391
log.Printf("Processing replacement: %d/%d", i+1, len(replacements))
old := utils.GetXMLContent(replacement, "Old")
new := utils.GetXMLContent(replacement, "New")
if old == "" {
log.Printf("No old content found for replacement")
return buildValidateResult{valid: false, updated: updated}, fmt.Errorf("no old content found for replacement")
}
old = strings.TrimSpace(old)
// log.Printf("Old content trimmed:\n\n%s", strconv.Quote(old))
// log.Printf("New content:\n\n%s", strconv.Quote(new))
if !strings.HasPrefix(old, "pdx-") {
log.Printf("Old content does not have a line number prefix for first line")
return buildValidateResult{valid: false, updated: updated}, fmt.Errorf("old content does not have a line number prefix for first line")
}
oldLines := strings.Split(old, "\n")
var lastLine string
var lastLineNum int
firstLine := oldLines[0]
if len(oldLines) > 1 {
lastLine = oldLines[len(oldLines)-1]
}
firstLineNum, err := shared.ExtractLineNumberWithPrefix(firstLine, "pdx-")
if err != nil {
log.Printf("Error extracting line number from first line: %v", err)
return buildValidateResult{valid: false, updated: updated}, fmt.Errorf("error extracting line number from first line: %v", err)
}
if lastLine != "" {View on GitHub (pinned to e2d772072e)
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
Example fix
// before
old = "func main() {}"
// after
old = "pdx-10 func main() {}" Defensive patterns
Strategy: validation
Validate before calling
if !strings.HasPrefix(old, "pdx-") {
return fmt.Errorf("old content must start with pdx- line number prefix")
} Type guard
func hasLineNumberPrefix(s string) bool {
idx := strings.Index(s, "pdx-")
if idx != 0 { return false }
rest := strings.TrimPrefix(s, "pdx-")
n, err := strconv.Atoi(strings.Fields(rest)[0])
return err == nil && n > 0
} Prevention
- Always include line-number prefixes on old-content first lines
- Pre-validate model output format before applying edits
- Retry generation when prefix validation fails
When it happens
Trigger: 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).
Common situations: Models drifting from the prompt format, copying content without the prefixed first line, or emitting an empty/blank old block after trimming.
Related errors
- error extracting line number from first line: %v
- error extracting line number from last line: %v
- invalid line number for first line: %d
- invalid line numbers: %d-%d
- no whole file found in response
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/484f46a49689c8e1.
Report an issue: GitHub.