Repository: promptfoo/promptfoo
Issue: Custom provider's cached latencyMs seems to be ignored
Root cause: Algorithmic Error

**Describe the bug**
According to https://github.com/promptfoo/promptfoo/pull/5978 it should now be possible to write the `latencyMs` field in `ProviderResponse` in order to provide a cached latency (unless I misunderstood something). However, I couldn't make this work in my custom provider.

Here's the function that converts my (cached) data into a response:

```
  private createResponse(result: Result, wasCached: boolean): ProviderResponse {
    console.log(`Latency: ${result.latencyMs}`);
    if (!result.latencyMs) {
      throw new Error("Oops!");
    }
    return {
      cached: wasCached,
      output: JSON.stringify(result.output, null, 2),
      latencyMs: result.latencyMs,
      tokenUsage: {
        prompt: result.usage.input,
        cached: result.usage.cacheRead,
        completion: result.usage.output,
      },
    };
  }
```
The error is never thrown, so I'm writing valid `latencyMs` values, and I'm also setting `cached` correctly. But when viewing the results in my browser, I see < 10 ms latencies indicating that my values are ignored and it's still measuring the cache retrieval time instead (although I do see the "(cached)" indicator). 

**To Reproduce**
- Create a custom ApiProvider
- Perform some long running operation, set `latencyMs` in the response
- Observe that you see the correct value in the viewer
- Update the provider to use `promptfoo.cache.getCache().get()` to retrieve a previously cached value, and also write values to the cache
- Set `cached: true` and `latencyMs: <your stored value>`
- Observe that the frontend shows actual cache retrieval values

I suspect that you could ignore most of this and simply try to set a certain `latencyMs` but I'm not sure if the fact that the provider actually uses the cache makes any difference.

**Expected behavior**
The frontend should always show the latency written into `ProviderResponse`

**Screenshots**
Uncached:
<img width="479" height="134" alt="Image" src="https://github.com/user-attachments/assets/b3428261-a4c4-4872-aa23-3cd6bcfe2da1" />
Cached:

<img width="453" height="152" alt="Image" src="https://github.com/user-attachments/assets/7e98472f-0210-4421-9d92-e2faa9b6d3c2" />


**System information:**
=========================================================================================================
Promptfoo Debug Information
=========================================================================================================
{
  "version": "0.120.8",
  "platform": {
    "os": "win32",
    "release": "10.0.26100",
    "arch": "x64",
    "nodeVersion": "v25.2.1"
  },
  "env": {
    "telemetryDisabled": false,
    "telemetryDebug": false
  },
  "configInfo": {
    "configExists": false,
    "configContent": null
  }
}

**Additional context**
I can't use your LLM providers directly since I have a custom prompt generator that needs to run (and I also prefer to run my actual production code to find issues), so I only use a dummy prompt and do the rest via model and dataset configuration, however this requires a custom `ApiProvider`


<!-- linear-linkback -->
<p><a href="https://linear.app/promptfooo/issue/ENG-1359/custom-providers-cached-latencyms-seems-to-be-ignored">ENG-1359</a></p>

Thanks for the clear repro and detailed writeup here, @Wyverex42. I pushed a fix to respect provider-supplied latencyMs for cached responses, and it’ll be in the next release (hopefully later today). 

Really appreciate you taking the time to report this. If you hit anything else with custom providers or caching, feel free to open another issue and feel free to reach out (michael @ promptfoo.dev) if you'd like some swag. 

Wow that was a really quick fix, thank you so much @mldangelo!