{"record":{"id":"edee2ce0e3d23fdd","repo":"multica-ai/multica","slug":"fetch-agents-w","errorCode":null,"errorMessage":"fetch agents: %w","messagePattern":"fetch agents: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/cmd/multica/cmd_autopilot.go","lineNumber":788,"sourceCode":"// ---------------------------------------------------------------------------\n\n// uuidRegexp matches a canonical UUID (8-4-4-4-12 hex).\nvar uuidRegexp = regexp.MustCompile(`^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$`)\n\n// resolveAgent accepts either a UUID or an agent name (case-insensitive substring)\n// and returns the agent's UUID. Errors on no match or ambiguous match.\nfunc resolveAgent(ctx context.Context, client *cli.APIClient, nameOrID string) (string, error) {\n\tif uuidRegexp.MatchString(nameOrID) {\n\t\treturn nameOrID, nil\n\t}\n\tif client.WorkspaceID == \"\" {\n\t\treturn \"\", fmt.Errorf(\"workspace ID is required to resolve agents; use --workspace-id or set MULTICA_WORKSPACE_ID\")\n\t}\n\n\tvar agents []map[string]any\n\tagentPath := \"/api/agents?\" + url.Values{\"workspace_id\": {client.WorkspaceID}}.Encode()\n\tif err := client.GetJSON(ctx, agentPath, &agents); err != nil {\n\t\treturn \"\", fmt.Errorf(\"fetch agents: %w\", err)\n\t}\n\n\tnameLower := strings.ToLower(nameOrID)\n\ttype match struct{ ID, Name string }\n\tvar matches []match\n\tfor _, a := range agents {\n\t\taName := strVal(a, \"name\")\n\t\tif strings.Contains(strings.ToLower(aName), nameLower) {\n\t\t\tmatches = append(matches, match{ID: strVal(a, \"id\"), Name: aName})\n\t\t}\n\t}\n\n\tswitch len(matches) {\n\tcase 0:\n\t\treturn \"\", fmt.Errorf(\"no agent found matching %q\", nameOrID)\n\tcase 1:\n\t\treturn matches[0].ID, nil\n\tdefault:","sourceCodeStart":770,"sourceCodeEnd":806,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/cmd/multica/cmd_autopilot.go#L770-L806","documentation":"resolveAgent wraps any failure of the GET /api/agents?workspace_id=<id> request (via client.GetJSON) with 'fetch agents: %w'. The wrapped error contains the real cause: connection refused, 401/403 auth failure, 404, 5xx, or a JSON decode failure of the response body.","triggerScenarios":"Server down or wrong server_url in CLI config; expired/invalid auth credentials; the workspace_id is valid format but inaccessible to the current user; proxy or TLS interception breaking the request.","commonSituations":"Local dev server not running when the CLI points at localhost; token expired after long idle; server_url pointing at a stale deployment; workspace deleted or user removed from it.","solutions":["Read the wrapped error: a 401/403 means re-authenticate; connection refused means the server URL/port is wrong or the server is down.","Verify connectivity: `multica config get server_url` and curl the /api/agents endpoint with the same credentials.","Confirm the workspace still exists and the current user has access to it."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"# preflight the endpoint the resolver will hit\ncurl -sf -H \"Authorization: Bearer $TOKEN\" \"$SERVER_URL/api/agents?workspace_id=$WS\" -o /dev/null \\\n  || { echo \"agents endpoint unreachable or unauthorized\" >&2; exit 2; }","typeGuard":null,"tryCatchPattern":"err := cmd.Run()\nif err != nil && strings.Contains(err.Error(), \"fetch agents\") {\n    if isTransient(err) { // connection refused, 502/503, timeout\n        time.Sleep(backoff)\n        err = cmd.Run()\n    }\n}","preventionTips":["Health-check server_url before batch automation runs.","Refresh auth tokens on a schedule so long-idle CLIs never resolve names with expired credentials."],"tags":["cli","api","network","agents","go"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}