Skip to content

fix: client response handling and desktop tray icon safety (5 bugs)#2884

Closed
HUQIANTAO wants to merge 2 commits into
Hmbown:mainfrom
HUQIANTAO:fix/client-remaining-bugs
Closed

fix: client response handling and desktop tray icon safety (5 bugs)#2884
HUQIANTAO wants to merge 2 commits into
Hmbown:mainfrom
HUQIANTAO:fix/client-remaining-bugs

Conversation

@HUQIANTAO

@HUQIANTAO HUQIANTAO commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes 5 client and desktop application bugs related to HTTP connection pool management and Tauri component lifecycle.

Bugs Fixed

Connection Pool Management

  1. health_check not consuming response body (client.rs:1018-1038)

    • On success, the response body is never consumed. With HTTP/1.1 keep-alive or HTTP/2 multiplexing, the connection cannot be returned to the pool until the body is read.
    • Fix: Add resp.text().await to consume the body.
  2. maybe_probe_recovery not consuming response body (client.rs:908-922)

    • Same issue as health_check.
    • Fix: Add resp.text().await.
  3. synthesize_speech response body read error (client.rs:855)

    • unwrap_or_default() converts connection drops to empty string, causing misleading JSON parse error.
    • Fix: Replace with .context()? error propagation.
  4. fim_completion response body read error (client.rs:1368)

    • Same pattern as synthesize_speech.
    • Fix: Replace with .context()? error propagation.

Tauri Desktop

  1. TrayIcon dropped immediately after setup (desktop/tray.rs:10)
    • In Tauri v2, dropping the TrayIcon instance removes it from the system tray. The local variable goes out of scope at the end of setup().
    • Fix: Use app.manage(tray) to transfer ownership to Tauri's managed state, keeping the icon alive for the application's lifetime.

1. Fix health_check not consuming response body (client.rs:1018-1038)
   - Consume response body with resp.text().await on success path
   - Previously held connection open until drop, exhausting connection pool
   - Same fix applied to maybe_probe_recovery (client.rs:908-922)

2. Fix synthesize_speech response body read error (client.rs:855)
   - Replace unwrap_or_default() with .context()? propagation
   - Connection drops now surface as clear error

3. Fix fim_completion response body read error (client.rs:1368)
   - Replace unwrap_or_default() with .context()? propagation
   - Consistent with other API call error handling

4. Fix unwrap() on default_window_icon (desktop/tray.rs:10)
   - Replace .unwrap() with .ok_or() returning descriptive error
   - Previously panicked if icon resource missing or corrupted
   - Now returns proper error through Result propagation

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HUQIANTAO has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown

Thanks @HUQIANTAO for taking the time to contribute.

This repository is currently observing a maintainer-managed contribution gate in dry-run mode, so this pull request is staying open. When enforcement is enabled, pull requests from contributors who are not listed in .github/APPROVED_CONTRIBUTORS will be closed automatically.

Please read CONTRIBUTING.md for the expected contribution shape. A maintainer can grant PR access by commenting /lgtm on a pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a system tray setup for the desktop application and improves connection pooling and error handling in the TUI client by consuming response bodies in health checks and adding context to response parsing. Feedback is provided regarding the lifetime of the Tauri tray icon, which will be dropped immediately unless stored in Tauri's state.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread crates/desktop/src/tray.rs Outdated
Comment on lines +12 to +29
let _tray = TrayIconBuilder::new()
.icon(icon.clone())
.tooltip("CodeWhale Desktop")
.on_tray_icon_event(|tray, event| {
if let TrayIconEvent::Click {
button: MouseButton::Left,
button_state: MouseButtonState::Up,
..
} = event
{
let app = tray.app_handle();
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
let _ = window.set_focus();
}
}
})
.build(app)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

In Tauri v2, dropping the TrayIcon instance immediately removes the tray icon from the system tray. Since _tray is a local variable in the setup function, it will go out of scope and be dropped at the end of the function, causing the tray icon to disappear immediately after the application starts. To keep the tray icon alive, you should manage its lifetime by storing it in Tauri's state using app.manage(tray).

Suggested change
let _tray = TrayIconBuilder::new()
.icon(icon.clone())
.tooltip("CodeWhale Desktop")
.on_tray_icon_event(|tray, event| {
if let TrayIconEvent::Click {
button: MouseButton::Left,
button_state: MouseButtonState::Up,
..
} = event
{
let app = tray.app_handle();
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
let _ = window.set_focus();
}
}
})
.build(app)?;
let tray = TrayIconBuilder::new()
.icon(icon.clone())
.tooltip("CodeWhale Desktop")
.on_tray_icon_event(|tray, event| {
if let TrayIconEvent::Click {
button: MouseButton::Left,
button_state: MouseButtonState::Up,
..
} = event
{
let app = tray.app_handle();
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
let _ = window.set_focus();
}
}
})
.build(app)?;
app.manage(tray);

In Tauri v2, dropping the TrayIcon instance immediately removes the
tray icon from the system tray. Since the setup function's local
variable would go out of scope, use app.manage(tray) to transfer
ownership to Tauri's managed state, keeping the icon alive for the
application's lifetime.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HUQIANTAO has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

Hmbown added a commit that referenced this pull request Jun 7, 2026
Harvested from PR #2884 by @ousamabenyounes. Drops the orphan
desktop tray.rs module (dead code, never wired) from that PR.

Co-Authored-By: Ben Younes <2910651+ousamabenyounes@users.noreply.github.com>
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Thanks @HUQIANTAO — your contribution landed in 4e3184eae9fb on main:

fix(client): consume probe response body to return connection to pool

Closing this PR now that the code is on main. Credit lives in the commit message and (where applicable) the CHANGELOG.md entry for the next release. Apologies for not closing this at the time of the merge — the auto-close workflow is new in v0.8.31.

If you want to land more work and would prefer your future PRs merge cleanly without a harvest step, the CONTRIBUTING.md doc has a short note on what makes a contribution mergeable as-is.

@github-actions github-actions Bot closed this Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant