Repository navigation
fix(sandbox): resolve the gateway url and buffer broker request bodies - #215
Merged
Merged
Conversation
Two defects found by the first in-app sandbox chat, both of which left the sandbox unable to reach a model. The egress resolver only read base_url from the hub auth file, which only the custom-provider flow writes; an SSO login records gateway_url instead. The common case therefore produced a sandbox with no routes and a guest config with no provider at all. Fall back to loadGatewayUrl(), which normalizes to the same /v1 base the host's own config uses. Electron's net.fetch then rejected every forwarded request with net::ERR_INVALID_ARGUMENT: the broker passes the guest's body through as a stream, which it cannot take. Buffer the body (model requests are small JSON) and drop the duplex flag; the response stays streamed. Verified end to end: a chat completion now returns to the guest through guest loopback -> vsock -> broker -> gateway, with the real token attached host-side. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two defects found by the first real in-app sandbox chat on macOS. Either one alone left a sandbox unable to reach a model, so the broker work (#209) has never actually served a completion until now.
1. Gateway URL never resolved
resolveSandboxEgressrequiredbase_urlfrom the hub auth file — but that field is only written by the custom-provider flow. An SSO login recordsgateway_urlinstead, which is the common case. Result:gatewayresolved to null, so the sandbox got no broker routes and a guest config containing only{"permission":"allow"}— no provider at all. Observed directly in the guest:Fix: fall back to
loadGatewayUrl(), whichnormalizeGatewayBaseUrlturns into exactly the/v1base the host's own working config uses (verified against~/.config/codev/codev.jsonc:https://netmind.viettel.vn/gateway/v1).2. Electron's net.fetch rejects streamed request bodies
With the config fixed, the guest reached the broker and every request came back
Bad Gateway: net::ERR_INVALID_ARGUMENT. The broker forwards the guest's request body as a stream (Readable.toWeb) plusduplex: "half";net.fetchaccepts neither. Fix: buffer the body in the desktop'sfetchImpland dropduplex. Model requests are small JSON payloads, and the response stays streamed, which is what token streaming needs.Verification
A real completion, requested from inside the NIC-less guest over the full chain (guest loopback → vsock → host broker → token swap → gateway):
Also confirmed in the same run: the guest config now carries the
netgateprovider pointed athttp://127.0.0.1:8788/llm/v1with the placeholder key (real token stays host-side), andpermission: "allow"from #210.Fork-only file; no DIVERGENCES row. No CHANGELOG entry — this fixes #209/#212 work that is still under Unreleased, so the existing entry describes the shipped behavior correctly.
🤖 Generated with Claude Code