alibaba/open-code-review · error

load tools: %w

Error message

load tools: %w

What it means

loadLLMRuntime loads the tool configuration via toolsconfig.Load and wraps any failure as `load tools: %w`. The tool config defines which agent tools are exposed to the LLM; a malformed, missing-but-required, or unreadable tool config aborts startup before any LLM call.

Source

Thrown at cmd/opencodereview/shared.go:216

	RuntimeConfig agent.RuntimeConfig
}

// newRetryCollector builds the per-run retry collector. It is a variable so a
// test can hand back a collector whose invariants are already violated, which is
// the only way to exercise the Freeze construction-error branch from the
// outside: every production path finalizes every logical request on every exit,
// so a well-behaved run can never produce one.
var newRetryCollector = llm.NewRetryCollector

// loadLLMRuntime loads tool defs from toolConfigPath, reads the app config
// from the user's default config path (applying the configured language to
// tpl — defaulting when the config file is absent), resolves the LLM
// endpoint (honoring resolveOpts), and
// returns the runtime bundle. tpl is mutated in place.
func loadLLMRuntime(tpl *template.Template, toolConfigPath string, resolveOpts llm.ResolveOptions) (*llmRuntime, error) {
	toolEntries, err := toolsconfig.Load(toolConfigPath)
	if err != nil {
		return nil, fmt.Errorf("load tools: %w", err)
	}
	planToolDefs := agent.BuildToolDefs(toolEntries, true)
	mainToolDefs := agent.BuildToolDefs(toolEntries, false)

	cfgPath, err := defaultConfigPath()
	if err != nil {
		return nil, err
	}
	appCfg, err := LoadAppConfig(cfgPath)
	if err != nil {
		return nil, fmt.Errorf("load app config: %w", err)
	}
	// Apply the language directive even when the config file is missing
	// (upstream #fix: ApplyLanguage with empty lang falls back to default).
	var lang string
	if appCfg != nil {
		lang = appCfg.Language
	}

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Open the path from the error and fix YAML/JSON syntax and field names to match the toolsconfig schema
  2. Validate against the schema of the installed ocr version (config format can change between versions)
  3. Fix file permissions (chmod/chown) so the running user can read it
  4. Restore a known-good default tool config

Example fix

// before (tools.yaml)
tools:
  - name: read_file
    comand: cat   # typo
// after
tools:
  - name: read_file
    command: cat
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat(toolConfigPath); err != nil {
	return fmt.Errorf("tool config unreadable: %w", err)
}
// parse it yourself to surface syntax errors before ocr runs

Try / catch

if err != nil {
	log.Fatalf("tool config invalid: %v — fix the file reported in the wrapped error", err)
}

Prevention

When it happens

Trigger: ocr review/scan/executeReviewContext starting with toolConfigPath pointing to a file that does not parse (bad YAML/JSON schema), has invalid tool entries, or cannot be read (permissions).

Common situations: Hand-edited tools config with a schema typo; upgrade changed the config format; file created by root and unreadable by the running user; wrong path passed programmatically in tests.

Related errors


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