fix(net): pass WireGuard endpoint to sly-net-client only when explicitly overridden - #125
Merged
Merged
Conversation
The agent always passed the WireGuard endpoint as the 3rd positional argument to sly-net-client. That argument is an *override*: when it is empty, the client uses the endpoint the server returns to it at registration instead. NET_SERVER_ADDRESS() never returned an empty value — when the env var was unset it synthesized "<server hostname>:<NET_SERVER_PORT>" (default port 51822). So arg 3 was always non-empty, the override was always in force, and the endpoint advertised by the server could never take effect. Changing the agent-facing endpoint therefore required recreating the net-client container on every host instead of being a server-side setting. NET_SERVER_ADDRESS() now returns None when the env var is unset or empty, and main.py appends arg 3 only when it is truthy. A value is still returned — with the existing http:// normalization — whenever the variable is actually set, which covers both real override paths: the server sending netClientOptions.netServerAddress via GetAgentOptions, and an operator setting it directly on the agent container. Only the agent's own synthesized fallback is dropped, since that is what pinned agents to a stale endpoint. main.py:_start_net_client was the only caller of NET_SERVER_ADDRESS(), so no other consumer is affected. The NET_SERVER_PORT() guard is left untouched. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
tonybart1337
force-pushed
the
fix/net-server-address-explicit-override
branch
from
July 28, 2026 18:23
9f5221c to
257bb6f
Compare
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.
Problem
_start_net_clientalways passed the WireGuard endpoint as the 3rd positional argument tosly-net-client:That argument is an override. When it is empty, the client instead uses the endpoint the server hands it during registration.
NET_SERVER_ADDRESS()never returned an empty value — when the env var was unset it synthesized<server hostname>:<NET_SERVER_PORT>(default51822). Arg 3 was therefore always non-empty, the override was always in force, and the server-advertised endpoint could never take effect.Consequence: changing the agent-facing endpoint requires recreating the net-client container on every host, rather than being a server-side setting.
Change
constants.NET_SERVER_ADDRESS()returnsNonewhenNET_SERVER_ADDRESSis unset or empty. When it is set, behaviour is unchanged, including the existinghttp://-prefixing normalization.main._start_net_clientappends arg 3 only when that value is truthy, and logs when it is omitted."Explicitly overridden" still covers both legitimate paths:
netClientOptions.netServerAddressviaGetAgentOptions(agent_utils.update_env_param(constants._NET_SERVER_ADDRESS, ...))NET_SERVER_ADDRESSdirectly on the agent containerOnly the agent-invented
hostname:NET_SERVER_PORTfallback is dropped — that is what pins agents to a stale endpoint.main.py:_start_net_clientwas the only caller ofNET_SERVER_ADDRESS()(verified by grep over the whole repo), so no other consumer changes. TheNET_SERVER_PORT()guard in_start_net_clientis left untouched.Verification
No test covers this path; the repo's suite is
tests/clean_functions+tests/test_run_daemon.pyand is unrelated. Baseline and post-changepytestresults are identical (3 failed, 10 passed; the 3 failures are pre-existingFileNotFoundError: /sly_agent/apps_cache, i.e. they expect an agent-container filesystem).pylint(what CI runs) scores10.00/10on both changed files.The real
_start_net_clientwas executed with a fake docker API to capture the actualcommand:NET_SERVER_ADDRESS[…, '<server-host>:51822']""/ whitespace[…, '<server-host>:51822']vpn.example.com:51825[…, 'vpn.example.com:51825'][…, 'vpn.example.com:51825']https://vpn.example.com:9999[…, 'vpn.example.com:9999'][…, 'vpn.example.com:9999']Notes for the reviewer
set -u, so with two arguments it expands to the empty string and the override is simply not applied. Worth re-confirming against whichever image tag you deploy.git log -Sshows arg 3 has been unconditionally present since beforeNET_SERVER_ADDRESSwas introduced (4db1a02, Sep 2024 — the pre-existing code synthesized the samehostname:portinline). The empty-arg path has effectively never been exercised by a released agent, so this is the first traffic through it.🤖 Generated with Claude Code