alibaba/open-code-review · error

read prompt file %q: %w

Error message

read prompt file %q: %w

What it means

resolveConversation materializes a template conversation from the embedded FS (embed.FS `prompts/` directory). When a manifest entry references a PromptFile that does not exist in the embedded template bundle, the embed.FS ReadFile error is wrapped with the file name. This indicates the shipped template manifest and its prompt files are out of sync — normally a build/packaging bug, not user input.

Source

Thrown at internal/config/template/template.go:194

	MaxCompletionTokens         int                   `json:"MAX_COMPLETION_TOKENS"`
	MaxToolRequestTimes         int                   `json:"MAX_TOOL_REQUEST_TIMES"`
	PlanModeLineThreshold       int                   `json:"PLAN_MODE_LINE_THRESHOLD"`
	PlanModeGroupLineThreshold  int                   `json:"PLAN_MODE_GROUP_LINE_THRESHOLD"`
	GroupingMinFiles            int                   `json:"GROUPING_MIN_FILES"`
	GroupingBundleLineThreshold int                   `json:"GROUPING_BUNDLE_LINE_THRESHOLD"`
	MaxReviewRounds             int                   `json:"MAX_REVIEW_ROUNDS"`
	ReLocationTask              *manifestConversation `json:"RE_LOCATION_TASK,omitempty"`
	ReviewFilterTask            *manifestConversation `json:"REVIEW_FILTER_TASK,omitempty"`
	GroupingTask                *manifestConversation `json:"GROUPING_TASK,omitempty"`
}

func resolveConversation(m manifestConversation) (LlmConversation, error) {
	var conv LlmConversation
	conv.Messages = make([]ChatMessage, len(m.Messages))
	for i, mm := range m.Messages {
		data, err := templateFS.ReadFile("prompts/" + mm.PromptFile)
		if err != nil {
			return LlmConversation{}, fmt.Errorf("read prompt file %q: %w", mm.PromptFile, err)
		}
		conv.Messages[i] = ChatMessage{
			Role:    mm.Role,
			Content: strings.TrimRight(string(data), "\r\n"),
		}
	}
	return conv, nil
}

func resolveOptionalConversation(m *manifestConversation, name string) (*LlmConversation, error) {
	if m == nil {
		return nil, nil
	}
	conv, err := resolveConversation(*m)
	if err != nil {
		return nil, fmt.Errorf("%s: %w", name, err)
	}
	return &conv, nil

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Verify the referenced file exists in internal/config/template/prompts/ and that the go:embed pattern includes it
  2. If task_template.json was customized, correct the PromptFile name to match an existing prompts/ file
  3. Rebuild cleanly (go clean && make build) so the embed FS is regenerated
  4. Report upstream if it occurs with an official release build

Example fix

// before (task_template.json)
"promptFile": "review-system-v2.md"   // file not embedded
// after
"promptFile": "review_system.md"   // matches prompts/review_system.md
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-flight: confirm the prompt file exists in the embedded FS
// (test code, not user code — embed.FS is internal)
func promptExists(tfs fs.FS, name string) bool {
    _, err := fs.Stat(tfs, "prompts/"+name)
    return err == nil
}
// verify all manifest prompt files resolve before shipping a patched template

Try / catch

tpl, err := template.LoadDefault()
if err != nil {
    if strings.Contains(err.Error(), "read prompt file") {
        fmt.Fprintln(os.Stderr, "embedded template manifest references a missing prompt file; rebuild or restore task_template.json")
    }
    return err
}

Prevention

When it happens

Trigger: LoadDefault -> resolveOptionalConversation -> resolveConversation processes a manifestConversation whose mm.PromptFile (e.g. "review_system.md") is absent under prompts/ in the embedded templateFS.

Common situations: A custom or patched build where task_template.json was edited to reference a new prompt file that was never added to the embedded prompts/ directory; an incomplete `go build` after deleting prompt files; go:embed pattern excluding the file so embed.FS lacks it.

Related errors


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/cec7d78cc924695b. Report an issue: GitHub.