Repository navigation
Studio: let LAN access bind only the addresses you choose - #12839
Conversation
654e936 to
7e597b5
Compare
|
Rebased onto main to pick up #12906. The only conflict was one import line in |
|
Review record for #12839, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#541. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1: reviewed mirror
|
LAN access bound every detected address, public ones included, and only the port was configurable. A VPS on a tailnet had no way to serve on its Tailscale address without also exposing its public IP. Settings > Remote & LAN > LAN access gets an Addresses setting, built like the existing port setting. Automatic keeps today's behavior. Choose binds only the ticked addresses; a chosen address that is not up is skipped, and a start with none of them present fails closed instead of falling back to every address. An unreadable saved choice also refuses to start rather than reading as Automatic. Fixes unslothai#11822 Co-Authored-By: Claude Opus 5.5 <[email protected]>
get_app_setting returns its fallback for a missing row and for an undecodable one alike, so a corrupt lan_access_addresses row read as Automatic and the listener bound every address, including the ones the user excluded. Only a missing row means Automatic now; an undecodable one refuses to start.
Start binds the saved choice, so ticking only a Tailscale address and pressing Start without Save bound every address, public ones included.
Status now reports which saved addresses are public, so a saved public address that is not detected right now still shows the warning instead of reading as private.
Boot auto-start binds the saved choice too, so turning it on with an unsaved choice would bind every address at the next launch.
89c25d3 to
6b4d2c0
Compare
|
@codex review |
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 425b371fa1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| raise RuntimeError(status["block_reason"] or "operation_in_progress") | ||
|
|
||
| ports = lan_access_port_candidates() | ||
| selected = _read_lan_access_addresses(strict = True) |
There was a problem hiding this comment.
Surface strict address-read failures in the LAN panel
When the saved lan_access_addresses row is malformed or its database read fails, this strict call raises lan_access_addresses_invalid/lan_access_addresses_unavailable before start_lan_listener can populate the listener error. The route converts that to a 409, but LanAccessSection.perform discards request errors for start, while the next non-strict status read reports Automatic and off; in this scenario clicking Start appears to do nothing, and Automatic is not dirty so it cannot be resaved directly. Preserve the 409 detail in the UI or publish this failure through status.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing: this needs a corrupt or unreadable settings row, which Studio never writes (the value is always json.dumps of a validated list or null). Start already fails closed with nothing bound, the saved port setting behaves the same way, and saving any choice from the picker overwrites the row.
| return (status?.availableAddresses ?? []) | ||
| .filter((entry) => !entry.public) | ||
| .map((entry) => entry.address); |
There was a problem hiding this comment.
Cap the default draft at the backend selection limit
On a host where detection returns more than 64 non-public addresses, switching from Automatic to Choose preselects all of them here, although the backend rejects any selection with more than _MAX_LAN_ACCESS_ADDRESSES (64) unique entries. Saving that untouched default therefore always gets a 422, and the component replaces the useful validation detail with the generic “Could not save” message, leaving the user to guess how many addresses to uncheck. Enforce or expose the same limit in the form before creating the default draft.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing: this needs a single host with more than 64 private IPv4 addresses detected on interfaces that are up. The backend still rejects it with a 422 and binds nothing, so nothing is exposed; it is outside the cases this setting is for.
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Fixes #11822.
LAN access binds every address the machine has, public ones included, and only the port can be changed. On a VPS with a public IP on its network card, there's no way to serve Studio only on a Tailscale or private address: turning LAN access on always exposes the public IP too, then warns about it.
Settings > Remote & LAN > LAN access now has an Addresses setting, next to Port and built the same way:
This machine only has one private address, so for this screenshot I stubbed the detected addresses in the browser to match a VPS on a tailnet. Everything else is the real UI and backend.
Root cause
start_lan_listener(studio/backend/lan_access.py) binds every addressdetect_lan_addresses()returns. The detection keeps public addresses on purpose, since a VPS serving on its own public IP is a valid setup, but nothing let the user leave any of them out.How it works
utils/lan_access_settings.py): stored aslan_access_addresses, likelan_access_port.Nonemeans Automatic; a list means only those addresses. Validation accepts only IPv4 addresses the listener could bind. It rejects loopback, link-local, multicast, unspecified and reserved addresses, leading-zero forms, an empty list and more than 64 addresses.start_lan_accesspasses the saved choice tostart_lan_listener, which binds only the detected addresses that are in it. A chosen address that isn't up right now, like a Tailscale interface that's down, is skipped and logged. If none of the chosen addresses is on the machine, the start fails withselected_address_unavailableand never falls back to binding everything.lan_access_addresses_unavailable/_invalid). Falling back to Automatic would bind the public addresses the user excluded.PUT /api/settings/lan-access/addresseswith{"addresses": [...] | null}. It's owner-only and needs a UI session, like the other/lan-accessroutes. Malformed input gets a 422, and a change while LAN access is running gets a 409.GET /lan-accessaddsconfigured_addressesandavailable_addresses(each with apublicflag). Detection is skipped for-Hlaunches, since the launch already decides the bind.lan-access-section.tsx): an Automatic/Choose select with a checkbox per address. Public addresses are labeled, and a saved address that isn't up right now is still shown, marked "Not on this machine right now". The section only shows the setting when the backend reportsconfigured_addresses, as it does for the port, so a newer frontend still works with an older backend.Tests
tests/test_lan_access_settings.py: 10 new tests. They cover validation and storage; a corrupt or unreadable choice refusing to start; the choice reaching the listener; save refused while online or on Colab; status listing addresses with public flags; detection failures not breaking status; the HTTP route (422 / 200 / 409); and the bind itself. The bind tests check that a choice binds only the chosen addresses, that a chosen address that isn't up is skipped, that Automatic still binds everything, and that a choice with nothing detected binds nothing. The new tests fail onmainand pass with this change (the Automatic test passes on both, as it should).tests/test_account_chat_settings.py: the new route is added to the list of owner-only routes that must reject managed accounts. The guard intest_management_rejects_api_keysnow expects 6 UI-session-gated/lan-accesshandlers instead of 5.frontend/tests/lan-access-state.test.ts: 8 new tests for normalization, an older backend without the field, read-only rules, the private-first default choice, set comparison for the Save button, saved addresses that aren't up, and the error message.Ran on Windows 11 with Python 3.12:
test_lan_access_settings.py+test_account_chat_settings.py: 213 passed.mainhas on Windows, from symlinks, memlock and missing torch.lan-access-state.test.ts35 passed. The full suite has no new failures; the 2 that fail also fail onmain.ruff checkpasses,ruff formatwith the pinned 0.6.9 and the kwarg-spacing hook,biome checkadds no new errors, andcodespellpasses.Unrelated: after rebasing on today's
main,npm run typecheckfails intests/settings-deep-open-requests.test.ts, which still references thechat-canvas-networktarget that #12804 removed. This PR doesn't touch either file.Follow-up commits
19800a4bdA saved choice that can't be decoded (for example a truncatedvalue_jsonrow) no longer reads as Automatic.get_app_settingreturns its fallback both for a missing row and for an undecodable one, so a corrupt row bound every address, including the excluded ones. Only a missing row means Automatic now; an undecodable one refuses to start. Reproduced against a real sqlite store: before the fix, start bound both addresses; after, it refuses withlan_access_addresses_invalid.312230d3dStart stays disabled while the address choice is unsaved. Start binds the saved choice, so ticking only a Tailscale address and pressing Start without Save bound every address.fa987d762For the same reason, Start automatically can't be turned on while the choice is unsaved (turning it off is still allowed).90ab80adcStatus now reportsconfigured_public_addresses, so a saved public address that is down keeps its public warning.main, plus two comment-only trims.Real-socket check on Linux, using two local IPv4 addresses (one stood in for a public NIC, the other for a tailnet address): on
mainboth are bound and reachable. With Choose and only the tailnet address ticked, only that one is bound and the other refuses connections. A chosen address that isn't up is skipped. If none of the chosen addresses is up, start refuses instead of binding everything.Before / after
Settings > Remote & LAN > LAN access, as it opens. The Addresses row is new:
After saving a choice of one detected address plus a Tailscale address that isn't up on this machine, then reloading:
With an unsaved edit, Start and Start automatically stay disabled until Save:
Studio UI regression check
Base
658b75a68vs head633139ff3. Functional: NO_REGRESSION, UI coverage 62%, 1 visual change(s), 3 text-only change(s). Only steps whose screenshots differ are shown.settings/s07_tab_remote_lan: | reproduced on confirm (VISUAL_DIFF)

settings/s00_opensettings/s06_tab_apicrawl/r_projects