alibaba/open-code-review · error

unmarshal task_template manifest: %w

Error message

unmarshal task_template manifest: %w

What it means

After reading task_template.json, LoadDefault unmarshals it into templateManifest. If the JSON is syntactically invalid or its shape does not match templateManifest fields, json.Unmarshal fails and the error is wrapped as 'unmarshal task_template manifest'. This indicates the embedded template manifest is malformed, which is a source-tree defect shipped into the binary.

Source

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

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

// LoadDefault parses the embedded task_template.json and resolves prompt file references.
func LoadDefault() (*Template, error) {
	data, err := templateFS.ReadFile("task_template.json")
	if err != nil {
		return nil, fmt.Errorf("read embedded task_template.json: %w", err)
	}
	var m templateManifest
	if err := json.Unmarshal(data, &m); err != nil {
		return nil, fmt.Errorf("unmarshal task_template manifest: %w", err)
	}

	var tpl Template
	tpl.MaxTokens = m.MaxTokens
	tpl.MaxCompletionTokens = m.MaxCompletionTokens
	tpl.MaxToolRequestTimes = m.MaxToolRequestTimes
	tpl.PlanModeLineThreshold = m.PlanModeLineThreshold
	tpl.PlanModeGroupLineThreshold = m.PlanModeGroupLineThreshold
	tpl.GroupingMinFiles = m.GroupingMinFiles
	tpl.GroupingBundleLineThreshold = m.GroupingBundleLineThreshold
	tpl.MaxReviewRounds = m.MaxReviewRounds

	if tpl.MainTask, err = resolveConversation(m.MainTask); err != nil {
		return nil, fmt.Errorf("MAIN_TASK: %w", err)
	}
	if tpl.PlanTask, err = resolveOptionalConversation(m.PlanTask, "PLAN_TASK"); err != nil {
		return nil, err
	}

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Run the JSON through a validator (jq . task_template.json or python -m json.tool) and fix the syntax error at the reported offset
  2. Compare field names/types in task_template.json against the templateManifest struct tags (e.g. "MAX_TOKENS") and fix mismatches
  3. Ensure the file is UTF-8 without BOM; re-save with correct encoding
  4. Rebuild the binary after fixing — the embedded copy changes only at compile time

Example fix

// before (task_template.json)
{"MAX_TOKENS": 4096, "MAIN_TASK": {"messages": [},]}
// after
{"MAX_TOKENS": 4096, "MAIN_TASK": {"messages": []}}
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat("internal/config/template/task_template.json"); err != nil { t.Fatal("manifest missing") }
// fail the build early on invalid JSON:
out, err := exec.Command("go", "run", "./cmd", "validate-template").CombinedOutput()
if err != nil { t.Fatalf("task_template.json invalid: %s", out) }

Try / catch

tpl, err := template.LoadDefault()
if err != nil {
	var syntaxErr *json.SyntaxErr
	var typeErr *json.UnmarshalTypeError
	switch {
	case errors.As(err, &syntaxErr):
		return fmt.Errorf("task_template.json is not valid JSON: %w", err)
	case errors.As(err, &typeErr):
		return fmt.Errorf("task_template.json field %s has wrong type: %w", typeErr.Field, err)
	}
	return err
}

Prevention

When it happens

Trigger: Calling LoadDefault() when the embedded task_template.json contains invalid JSON (syntax error, trailing comma, BOM) or has fields with types that cannot unmarshal into templateManifest (e.g. a string where a number is expected).

Common situations: Hand-editing the JSON and introducing a syntax error; a merge conflict marker left in the file; changing a manifest field type in Go without updating the JSON; a tool rewriting the file with wrong encoding (UTF-16/BOM).

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


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