Repository navigation
fix: Implement speed test and health check for Cap desktop app - #4204
ondrej-sedlak wants to merge 2 commits into
Conversation
- new network_status module runs a startup health check that uploads a probe payload to /api/desktop/health-check and flags failures in the UI - periodic upload speed test (skipped while a recording is active) drives a bottom-left indicator and caps studio recording quality by bandwidth - new authenticated /api/desktop/health-check endpoint in the web app
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
|
🚨 Contributor flagged. Click here for more info: Superagent Dashboard |
| Err(error) => { | ||
| tracing::warn!(error = %error, "upload speed test failed"); | ||
| None |
There was a problem hiding this comment.
A connection below roughly 0.84 Mbps cannot upload the 2 MiB probe within 20 seconds. That timeout sets upload_mbps to None, and effective_studio_quality keeps the configured quality. The slowest connections therefore get no cap. Distinguish a timed-out measurement from an unavailable one, or use a smaller or adaptive probe.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop-gpui/src/network_status.rs
Line: 179-181
Comment:
**Slow links skip quality cap**
A connection below roughly 0.84 Mbps cannot upload the 2 MiB probe within 20 seconds. That timeout sets `upload_mbps` to `None`, and `effective_studio_quality` keeps the configured quality. The slowest connections therefore get no cap. Distinguish a timed-out measurement from an unavailable one, or use a smaller or adaptive probe.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| let _ = cx.update(|cx| { | ||
| status.update(cx, |status, cx| { | ||
| status.upload_mbps = outcome; | ||
| status.last_speed_test = Some(Instant::now()); |
There was a problem hiding this comment.
Recovered connections still show failure
A brief network failure at launch leaves the red upload warning visible until the app restarts. run_health_check writes health only once, and later successful speed tests never clear it. Update health after subsequent probes, or retry a failed health check.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop-gpui/src/network_status.rs
Line: 184-187
Comment:
**Recovered connections still show failure**
A brief network failure at launch leaves the red upload warning visible until the app restarts. `run_health_check` writes `health` only once, and later successful speed tests never clear it. Update `health` after subsequent probes, or retry a failed health check.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| let request = client | ||
| .request(method, url) | ||
| .header("Content-Type", content_type) | ||
| .body(body) | ||
| .bearer_auth(token); |
There was a problem hiding this comment.
Protected deployments reject probes
authed_raw_request skips apply_desktop_headers, unlike the existing authenticated request helper. If VITE_VERCEL_AUTOMATION_BYPASS_SECRET is configured for a protected deployment, probes omit its bypass header and can be rejected before reaching the endpoint. Apply the shared headers to raw requests too.
| let request = client | |
| .request(method, url) | |
| .header("Content-Type", content_type) | |
| .body(body) | |
| .bearer_auth(token); | |
| let request = apply_desktop_headers(client.request(method, url)) | |
| .header("Content-Type", content_type) | |
| .body(body) | |
| .bearer_auth(token); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop-gpui/src/auth.rs
Line: 454-458
Comment:
**Protected deployments reject probes**
`authed_raw_request` skips `apply_desktop_headers`, unlike the existing authenticated request helper. If `VITE_VERCEL_AUTOMATION_BYPASS_SECRET` is configured for a protected deployment, probes omit its bypass header and can be rejected before reaching the endpoint. Apply the shared headers to raw requests too.
```suggestion
let request = apply_desktop_headers(client.request(method, url))
.header("Content-Type", content_type)
.body(body)
.bearer_auth(token);
```
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| const body = await c.req.arrayBuffer(); | ||
| if (body.byteLength > MAX_PROBE_BYTES) { |
There was a problem hiding this comment.
The 8 MiB limit runs after arrayBuffer() has loaded the entire request into memory. An authenticated caller can make the server allocate far more than the intended limit before it returns 413, especially on self-hosted deployments. Count bytes while reading and stop once the limit is reached.
How this was verified: The authenticated POST handler reads the complete caller-supplied body before checking its size.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/web/app/api/desktop/[...route]/health-check.ts
Line: 11-12
Comment:
**Body limit checks too late**
The 8 MiB limit runs after `arrayBuffer()` has loaded the entire request into memory. An authenticated caller can make the server allocate far more than the intended limit before it returns 413, especially on self-hosted deployments. Count bytes while reading and stop once the limit is reached.
**How this was verified:** The authenticated POST handler reads the complete caller-supplied body before checking its size.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| import { Hono } from "hono"; | ||
| import { withAuth } from "../../utils"; | ||
|
|
||
| export const app = new Hono(); |
There was a problem hiding this comment.
The new route uses Hono handlers, but AGENTS.md requires new routes under apps/web/app/api/* to use the HttpApi class/group/endpoint pattern and apiToHandler. The explicit Hono exception covers only the developer v1 route families, not /api/desktop. Implement this endpoint with the required pattern before merging.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/web/app/api/desktop/[...route]/health-check.ts
Line: 4
Comment:
**New route breaks API rule**
The new route uses Hono handlers, but `AGENTS.md` requires new routes under `apps/web/app/api/*` to use the `HttpApi` class/group/endpoint pattern and `apiToHandler`. The explicit Hono exception covers only the developer v1 route families, not `/api/desktop`. Implement this endpoint with the required pattern before merging.
**Context Used:** AGENTS.md ([source](https://github.com/capsoftware/cap/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| } | ||
| } | ||
|
|
||
| /// The quality tier the measured upload speed can sustain. |
There was a problem hiding this comment.
The comment above quality_for_upload_speed only repeats the function's name and return value. AGENTS.md prohibits comments that narrate code or restate types. The same pattern appears above effective_studio_quality and in the module introduction. Remove these comments or explain a non-obvious decision to satisfy the requirement before merging.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop-gpui/src/network_status.rs
Line: 99
Comment:
**Comments repeat the code**
The comment above `quality_for_upload_speed` only repeats the function's name and return value. `AGENTS.md` prohibits comments that narrate code or restate types. The same pattern appears above `effective_studio_quality` and in the module introduction. Remove these comments or explain a non-obvious decision to satisfy the requirement before merging.
**Context Used:** AGENTS.md ([source](https://github.com/capsoftware/cap/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| "Upload check failed - contact support".to_string() | ||
| } else { | ||
| match status.upload_mbps { | ||
| Some(mbps) => format!("{mbps:.1} Mbps up"), | ||
| None => "Checking upload...".to_string(), |
There was a problem hiding this comment.
Network labels ignore language
The new status labels are hardcoded in English while the rest of this window uses tr for translated text. Add translation keys for the warning, checking message, and speed label so changing the app's language also changes this new UI.
Knowledge Base Used: GPUI desktop client
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop-gpui/src/main_window.rs
Line: 3982-3986
Comment:
**Network labels ignore language**
The new status labels are hardcoded in English while the rest of this window uses `tr` for translated text. Add translation keys for the warning, checking message, and speed label so changing the app's language also changes this new UI.
**Knowledge Base Used:** [GPUI desktop client](https://app.greptile.com/-/switch-tenant?tenant=cap&next=%2Fcustom-context%2Fknowledge-base%2Fcapsoftware%2Fcap%2F-%2Fdocs%2Fgpui-desktop-client.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Description
probe payload to /api/desktop/health-check and flags failures in the UI
a bottom-left indicator and caps studio recording quality by bandwidth
Resolves #73
Issue: #73
/claim #73
Do not merge until the desktop build error and startup panic are fixed and the repository's API and comments rules are satisfied.
Findings
Fix with agent prompt
Summary
Adds authenticated upload probes, a network indicator, and bandwidth-based Studio quality limits.
Reviews (1) · Last reviewed commit: "feat: add upload speed test and startup ..." · Reviewed by Greptile