micro/go-micro · error

failed to parse poll response: %w

Error message

failed to parse poll response: %w

What it means

This error is wrapped by pollPrediction (image path) when the JSON body returned by the Atlas Cloud prediction/status endpoint cannot be unmarshaled into the expected {data:{status,outputs,error}} shape. The library throws it because it cannot determine the job status without a parseable response. The underlying json.Unmarshal error is preserved via %w.

Source

Thrown at ai/atlascloud/atlascloud.go:1027

	httpReq.Header.Set("Authorization", "Bearer "+p.opts.APIKey)

	httpResp, err := http.DefaultClient.Do(httpReq)
	if err != nil {
		return nil, fmt.Errorf("poll request failed: %w", err)
	}
	defer httpResp.Body.Close()

	body, _ := io.ReadAll(httpResp.Body)

	var pollResp struct {
		Data struct {
			Status  string   `json:"status"`
			Outputs []string `json:"outputs"`
			Error   string   `json:"error"`
		} `json:"data"`
	}
	if err := json.Unmarshal(body, &pollResp); err != nil {
		return nil, fmt.Errorf("failed to parse poll response: %w", err)
	}

	switch pollResp.Data.Status {
	case "completed":
		resp := &ai.ImageResponse{}
		for _, output := range pollResp.Data.Outputs {
			resp.Images = append(resp.Images, ai.Image{URL: output})
		}
		return resp, nil
	case "failed":
		return nil, fmt.Errorf("image generation failed: %s", pollResp.Data.Error)
	default:
		return nil, nil
	}
}

const defaultVideoModel = "google/gemini-omni-flash/image-to-video-developer"

View on GitHub (pinned to 24529f1404)

Solutions

  1. Verify p.opts.BaseURL points to the correct Atlas Cloud API host (e.g. https://api.atlascloud.ai) with no trailing UI path
  2. Log the raw body returned by the poll endpoint and compare it against the expected {"data":{"status":...}} schema
  3. Confirm your API key is valid — some gateways return HTML login/redirect pages with 200 for unauthenticated requests
  4. Check whether an HTTP proxy/CDN in front of the API is rewriting or truncating responses
  5. Check Atlas Cloud API changelog for a poll-response schema change and update the library

Example fix

// before: silent truncation hides the real body
body, _ := io.ReadAll(httpResp.Body)
if err := json.Unmarshal(body, &pollResp); err != nil {
	return nil, fmt.Errorf("failed to parse poll response: %w", err)
}
// after: log body on failure to diagnose
tlogging.Logf("poll status=%d body=%q", httpResp.StatusCode, string(body))
Defensive patterns

Strategy: try-catch

Validate before calling

// before calling GenerateImage
if u, err := url.Parse(strings.TrimSpace(baseURL)); err != nil || u.Scheme == "" || u.Host == "" {
	return fmt.Errorf("invalid base URL %q", baseURL)
}

Type guard

func isValidPollResponse(body []byte) bool {
	var probe struct { Data struct { Status string `json:"status"` } `json:"data"` }
	return json.Unmarshal(body, &probe) == nil && probe.Data.Status != ""
}

Try / catch

resp, err := provider.GenerateImage(ctx, req)
if err != nil {
	if strings.Contains(err.Error(), "failed to parse poll response") {
		log.Printf("non-JSON poll body; check BaseURL/proxy: %v", err)
	}
	return fmt.Errorf("image job status unavailable: %w", err)
}

Prevention

When it happens

Trigger: GET <BaseURL>/api/v1/model/prediction/<id> (called from GenerateImage polling loop) returns a 200 response whose body is not valid JSON or does not match the expected struct — e.g. an HTML error/login page from a wrong BaseURL, a proxy gateway JSON envelope with a different schema, an empty body, or a truncated response.

Common situations: Misconfigured ATLAS BaseURL pointing at a different service or a UI route; corporate proxy or API gateway returning an HTML 200 page; Atlas Cloud changing the poll response schema (version drift); rate-limit or auth-redirect pages served with 200 status.

Understand the failure class

Related errors


AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01). Data as JSON: /api/errors/558b4e0ee51cca06. Report an issue: GitHub.