feat(desktop): pass through ADAL_APP_URL to sidecar for token compression#29158
Conversation
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for forwarding an ADAL_APP_URL environment variable from the desktop app to the sidecar process so LLM requests can be routed through a compression proxy.
Changes:
- Detect
ADAL_APP_URLin the parent process environment. - Forward
ADAL_APP_URLto the sidecar process environment when present.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Pass through token compression proxy URL to the sidecar process. | ||
| // When ADAL_APP_URL is set (e.g., by adal-compress proxy), the sidecar | ||
| // routes LLM requests through the proxy for transparent compression. | ||
| if let Ok(app_url) = std::env::var("ADAL_APP_URL") { | ||
| envs.push(("ADAL_APP_URL".to_string(), app_url)); | ||
| } |
There was a problem hiding this comment.
✅ Addressed in force-push. Now validates that only localhost/loopback URLs are accepted:
if url_str.starts_with("http://localhost")
|| url_str.starts_with("http://127.0.0.1")
|| url_str.starts_with("http://[::1]")Non-local URLs are rejected with tracing::warn. This prevents any env injection from routing sensitive traffic externally.
HTTPS enforcement was considered but intentionally omitted — localhost proxies typically run plain HTTP (TLS adds complexity for loopback with no security benefit since traffic never leaves the machine).
| if let Ok(app_url) = std::env::var("ADAL_APP_URL") { | ||
| envs.push(("ADAL_APP_URL".to_string(), app_url)); |
There was a problem hiding this comment.
✅ Addressed in force-push. Now uses std::env::var_os + .to_str() validation:
if let Some(app_url) = std::env::var_os("ADAL_APP_URL") {
if let Some(url_str) = app_url.to_str() {
// validate and push
}
}Non-UTF8 values are silently skipped (no panic, no lossy conversion). Since the sidecar expects a valid URL string, non-UTF8 values would be invalid anyway — skipping is the correct behavior.
…sion When ADAL_APP_URL is set in the user's environment, the Desktop app now passes it through to the sidecar process. This allows transparent token compression proxies to intercept LLM requests. Security: Only localhost/loopback URLs are accepted (http://localhost, http://127.0.0.1, http://[::1]). Non-local URLs are rejected with a warning log. Uses var_os for robustness with non-UTF8 edge cases. No behavioral change when ADAL_APP_URL is unset. Co-Authored-By: AdaL <adal@sylph.ai>
6b0bd29 to
85e6b12
Compare
There was a problem hiding this comment.
Addressing Copilot feedback
High: URL validation / traffic interception risk
✅ Fixed in force-push. Now only localhost/loopback URLs are accepted:
http://localhost*http://127.0.0.1*http://[::1]*
Any non-local URL is rejected with a tracing::warn log. This prevents environment injection from routing LLM traffic to external endpoints.
Low: std::env::var vs var_os
✅ Fixed in force-push. Now uses std::env::var_os + .to_str() check, so non-UTF8 values are handled gracefully (silently skipped) rather than causing a panic or silent drop.
Summary
Pass through
ADAL_APP_URLenvironment variable to the sidecar process, enabling AdaL CLI's token compression proxy to transparently reduce token usage for Desktop users.What type of PR is this?
Feature (non-breaking addition)
What this PR does
When the user has
ADAL_APP_URLset in their environment, the Desktop app now forwards it to the sidecar process. This enables the adal-compress token compression proxy to intercept and compress LLM requests before they reach providers.Security hardening: Only localhost/loopback URLs are accepted (
http://localhost,http://127.0.0.1,http://[::1]). Any non-local URL is rejected with atracing::warnlog to prevent unintended traffic routing.Implementation: Uses
std::env::var_osfor robustness with non-UTF8 edge cases, then validates and converts to a known-good UTF-8 string before pushing to the env vec.Context: What is ADAL_APP_URL?
AdaL is a coding agent built on top of OpenCode. It uses a transparent compression proxy (
adal-compress) that sits between the CLI/Desktop sidecar and the backend API:The proxy is inspired by Caveman (37k+ ★) and achieves 30-70% token savings while preserving all code, paths, URLs, and technical content.
Current issue: The Desktop sidecar doesn't reliably inherit
ADAL_APP_URLbecause:load_shell_envprobe is best-effort and can timeout or failWhy this benefits OpenCode broadly
While
ADAL_APP_URLis the immediate use case, this pattern enables any localhost middleware for the sidecar:This is consistent with how
OPENCODE_PORTand other env vars are already passed through.Testing
ADAL_APP_URLis unset (existing path unchanged)envsvecRisk
if let Some(...)pattern is a no-opRelated issues
opencode proxyfeature (proxy as server, not client — different direction)🌸 Generated with AdaL