Skip to content

fix(desktop): log Gemini proxy forwarded uid - #7659

Merged
kodjima33 merged 2 commits into
BasedHardware:mainfrom
tianmind-studio:codex/gemini-forwarded-uid-logging
Jun 6, 2026
Merged

kodjima33 merged 2 commits into
BasedHardware:mainfrom
tianmind-studio:codex/gemini-forwarded-uid-logging

Conversation

@tianmind-studio

Copy link
Copy Markdown
Contributor

Summary

  • log successful non-BYOK Gemini proxy forwards with uid and forwarded path
  • cover both non-streaming and streaming Gemini proxy paths

Fixes #7624.

Verification

  • git diff --check

Not run locally: cargo check && cargo test because this Windows host does not have cargo/rustc installed.

@greptile-apps

greptile-apps Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds observability logging to the non-BYOK Gemini proxy paths by converting the existing direct returns into a two-step pattern: await? the server-key helper, emit a tracing::info! with uid and effective_path, then return Ok(response). Both the non-streaming (gemini_proxy) and streaming (gemini_stream_proxy) branches are covered.

  • Non-streaming path (line 141): gemini_proxy_server_key is now await?-ed and the log is emitted before returning Ok(response).
  • Streaming path (line 366): gemini_stream_server_key is likewise await?-ed and logged; note the log fires as soon as the upstream HTTP response headers arrive, before any SSE chunks are streamed to the client.

Confidence Score: 4/5

Safe to merge; the refactor is mechanically correct and introduces no behavioral regression — the only concern is that the new log line fires for all upstream HTTP responses, not just 2xx.

The change is narrow: two return sites are converted from a direct return into await?/log/Ok(response). The ? propagation is correct, ownership and lifetimes are unaffected, and there is no change to error handling paths. The one gap is that both gemini_proxy_server_key and gemini_stream_server_key return Ok(response) for any upstream HTTP status, so the forwarded log will also appear when Gemini returns a 429 or 500 — a misleading signal when debugging user-facing errors.

desktop/Backend-Rust/src/routes/proxy.rs — specifically the two new tracing::info! sites at the non-BYOK return paths.

Important Files Changed

Filename Overview
desktop/Backend-Rust/src/routes/proxy.rs Adds tracing::info! logging for non-BYOK Gemini proxy forwards; the refactor from direct return to await?/log/Ok is correct, but the log fires for any upstream HTTP status (including 4xx/5xx from Gemini), which is slightly at odds with the PR description's "successful" qualifier.

Sequence Diagram

sequenceDiagram
    participant Client
    participant gemini_proxy
    participant gemini_proxy_server_key
    participant Upstream

    Client->>gemini_proxy: "POST /v1/proxy/gemini/*path"
    Note over gemini_proxy: Auth, allowlist, sanitize, rate limit

    alt Non-BYOK path (this PR)
        gemini_proxy->>gemini_proxy_server_key: .await?
        gemini_proxy_server_key->>Upstream: forward with server key
        Upstream-->>gemini_proxy_server_key: response (any HTTP status)
        gemini_proxy_server_key-->>gemini_proxy: Ok(response)
        Note over gemini_proxy: NEW: tracing::info!(uid, path) fires for ANY status
        gemini_proxy-->>Client: Ok(response)
    else BYOK path
        gemini_proxy->>Upstream: forward with user API key
        Upstream-->>gemini_proxy: response
        gemini_proxy-->>Client: response (no log)
    end
Loading

Reviews (1): Last reviewed commit: "fix(desktop): log Gemini proxy forwarded..." | Re-trigger Greptile

Comment on lines +141 to +150
let response = gemini_proxy_server_key(
&state, &user, &effective_path, action, model, &sanitized_body,
)
.await;
.await?;
tracing::info!(
"gemini_proxy: forwarded uid={} path={}",
user.uid,
effective_path
);
return Ok(response);

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.

P2 The log fires for every completed upstream HTTP exchange, including 4xx/5xx responses from the Gemini API. Both gemini_proxy_server_key and gemini_stream_server_key return Ok(response) even when the upstream status is an error — the ? only propagates network-level ProxyErrors. This means a Gemini-returned 429 or 500 will still produce a "forwarded" log line, which could be misleading when correlating logs with user-facing errors. The PR description says "log successful … forwards"; checking response.status().is_success() before emitting the line would match that intent.

Suggested change
let response = gemini_proxy_server_key(
&state, &user, &effective_path, action, model, &sanitized_body,
)
.await;
.await?;
tracing::info!(
"gemini_proxy: forwarded uid={} path={}",
user.uid,
effective_path
);
return Ok(response);
let response = gemini_proxy_server_key(
&state, &user, &effective_path, action, model, &sanitized_body,
)
.await?;
if response.status().is_success() {
tracing::info!(
"gemini_proxy: forwarded uid={} path={}",
user.uid,
effective_path
);
}
return Ok(response);

Comment on lines +366 to +380
let response = gemini_stream_server_key(
&state,
&effective_path,
action,
model,
sanitized_body,
&query,
)
.await?;
tracing::info!(
"gemini_stream_proxy: forwarded uid={} path={}",
user.uid,
effective_path
);
return Ok(response);

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.

P2 Same semantic issue for the streaming path: gemini_stream_server_key returns Ok(response) regardless of whether the upstream status is 2xx, 4xx, or 5xx, so the "forwarded" log fires even when the downstream client will receive an error stream. Additionally, for the streaming case, the log fires as soon as the response headers are received from the upstream — before any SSE body chunks are delivered — which is the earliest practical logging point but worth noting in a follow-up if per-stream-completion logging is ever needed.

Suggested change
let response = gemini_stream_server_key(
&state,
&effective_path,
action,
model,
sanitized_body,
&query,
)
.await?;
tracing::info!(
"gemini_stream_proxy: forwarded uid={} path={}",
user.uid,
effective_path
);
return Ok(response);
let response = gemini_stream_server_key(
&state,
&effective_path,
action,
model,
sanitized_body,
&query,
)
.await?;
if response.status().is_success() {
tracing::info!(
"gemini_stream_proxy: forwarded uid={} path={}",
user.uid,
effective_path
);
}
return Ok(response);

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Small Rust log-only fix for #7624 (Gemini proxy uid attribution). Tiny diff, no behavior change.

@kodjima33
kodjima33 merged commit 1ed6773 into BasedHardware:main Jun 6, 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.

Desktop Rust backend: add UID logging on successful Gemini proxy requests

2 participants