Repository navigation
feat(local-models): separate shared gateway display and add tabbed Advanced dialog - #657
oldwinter53 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Request changes (1 P1, 2 P2)
Scope: base main, merge base abfbcb5f, 2 commits, 20 files reviewed at 86a4a0d1. Loaded helper skills: coderbook, ponytail-review (sections 1–3), karpathy-guidelines. Ran in a separate session. The security checklist does not apply: there are no auth endpoints, tokens or dependency changes, only a new local IPC surface, which is reviewed below.
Findings
P1
1. LocalGatewayService.#resolve re-implements the localmodels Bifrost resolution, and the copy already disagrees with the original (apps/desktop/src/main/local-gateway.ts:261-330)
The comment at line 272 says "Match localmodels-tool.ts". The file then copies field, readOwnedBifrost, the loopback address parser (parseLoopbackAdminUrl vs parseLoopbackBifrostAddress), readOwnedJson and the tools/bifrost path layout from packages/local-installation/src/localmodels-tool.ts:547-620. This is a second implementation of the same rule, and it already differs from the one the runtime uses:
- Runtime (
localmodelsIsolation,localmodels-tool.ts:829-866): a home that is not legacy always useslocalmodelsBifrostDirectory(home). Its address comes from this home'sowned.json, then itsbifrost-addr, then the default. The shared~/.local/share/localmodels/toolsdirectory is only used whenlegacyLocalmodelsTools(home)picks it, and that requires one of this home's plan deployments to live under this home's models directory. - Desktop copy (lines 284-310): if this home's
owned.jsonhas nogateway.bifrostrecord, it always falls back to the shared~/.local/share/localmodels/tools/owned.jsonand then to~/.local/state/localmodels/bifrost. It takes the firstapp_dirandaddrit finds there.
Failure scenario: a machine that ran localmodels before per-home isolation, or that has another Linger installation, has a shared owned.json that records that other gateway. This home's gateway has not written its own record yet. The Advanced dialog then shows the other installation's admin username and URL, and reveals or copies its admin-password. Open launches the other gateway's console. The runtime itself never touches that directory for this home. None of these fallback paths has a test in local-gateway.test.ts.
Fix: export one resolver from @linger/local-installation that returns { bifrostDir, addr } for a home. It should reuse legacyLocalmodelsTools, readOwnedBifrost and localmodelsBifrostDirectory (read-only, allocate: false). Then delete the copied helpers and the extra ~/.local/... fallbacks from local-gateway.ts. That way the dialog always points at the gateway the runtime actually uses.
P2
2. Clipboard auto-clear is copied from setup-account (apps/desktop/src/main/local-gateway.ts:202-225)
The block that writes the clipboard, sets a 60 s timer, reads the clipboard back and clears it only if unchanged is nearly line for line the same as SetupAccount.copy in apps/desktop/src/main/setup-account.ts:58-72. The new code already imports CLIPBOARD_CLEAR_MS from that file. Move the logic into one small helper, e.g. copySecretWithAutoClear(clipboard, text, ms), and call it from both places, so a change to the clear rule happens once.
3. The computerId gate is not a security boundary, but the docs present it as one (apps/desktop/src/main/desktop-ipc.ts:237-270, apps/desktop/AGENTS.md:457-463)
handle() only checks that the caller has the configured serverUrl origin. The same page can call IPC.computerStatus (desktop-ipc.ts:144-153), which returns computerId. Any script on the TeamHub origin, including an XSS payload or a hostile team server, can therefore call lingerDesktop.localGateway.revealPassword(<that id>) and get the plaintext Bifrost admin password in the page's JS (local-model-advanced-dialog.tsx:215-217). The origin check is the only real gate. The computerId check only routes the UI. The existing local-account flow keeps the secret in the main process: copy and reveal only touch the clipboard and the file manager. Either keep that pattern (main-process copy only, no revealPassword to the renderer), or say plainly in apps/desktop/AGENTS.md that the remote origin can read the password. Then drop the "own enrolled computerId only" framing, which suggests more protection than exists.
Verified as fine
- Every new channel goes through
handle(), which rejects senders whosesenderFrame.originis notserverUrl(apps/desktop/src/main/desktop-ipc.ts:161-174).computerIdis validated with zod (desktop-ipc.ts:34). - The password file read requires a regular file that is not a symlink, at most 4096 bytes, owned by the current user, with
mode & 0o077 == 0on POSIX (local-gateway.ts:59-80,#readPasswordat:243-249). The password is never cached in the service. openAdminonly opens a URL built from a strict127.0.0.1:<port>match (local-gateway.ts:47-57). It cannot be made to open arbitrary URLs.- Older desktop builds and browsers:
desktopLocalGateway()returnsundefinedwhen the bridge is missing (apps/web/src/features/local-models/desktop-local-gateway.ts:28-34), and the preload API field is optional (apps/desktop/src/shared/api.ts:183). - The revealed password is cleared on tab change and unmount (
local-model-advanced-dialog.tsx:184-189). The timer is disposed on module stop (desktop-ipc.ts:270). isDesktopComputeris computed fromdesktop.status.computerId === computer_id(local-models-page.tsx:215-218, 234-237), so other users' computers never show desktop actions.- No CJK in changed non-locale files or in commit messages. No contract or env changes.
apps/web/AGENTS.mdandapps/desktop/AGENTS.mdwere updated in the same PR.
Process notes
- The branch is 16 commits behind
main, andmainrequires up-to-date branches, so it needs a rebase. - No merge commits and no fixup commits.
CI
All checks that ran passed: check (desktop), check (web), both web test shards, web-static, repository-gate, CodeQL. check (packages) was skipped because no package changed; it would run if finding 1 is fixed by moving the resolver into @linger/local-installation. I did not run any tests locally. The findings come from reading the code.
Automated review by Claude Code
Automated review of 86a4a0d by Claude Code.
86a4a0d to
a3522c5
Compare
|
Addressed all three review findings in
|
8a407fd to
f948d04
Compare
|
Rebased onto latest
All 11/11 CI checks ( |
There was a problem hiding this comment.
Approve with nits (1 P3)
Scope: follow-up on 86a4a0d; reviewed head f948d04 against main, merge base 8b7fe39. 4 commits, 25 files. The branch was rebased since the previous review, so I used git range-diff: c1693564 and e5153271 match the earlier two commits, and the new commits are 15480162 and f948d043. I also rechecked the whole merge-base diff for P0/P1 problems. Loaded skills: coderbook; ponytail-review and karpathy-guidelines were applied from their checklists. Ran in a separate session.
Previous findings
-
P1: Desktop duplicated the Bifrost path resolution, and the copy had drifted. Resolved.
apps/desktop/src/main/local-gateway.ts:217now callsresolveLocalmodelsBifrostLocation(packages/local-installation/src/localmodels-tool.ts:796). That function follows the same branches aslocalmodelsIsolation(localmodels-tool.ts:868):- A legacy home uses the shared
owned.json'sapp_dir/addr. - Otherwise it uses this home's
runtime/localmodels/bifrostandresolveLocalmodelsBifrostAddr(..., { allocate: false }).
It does this without writing the legacy marker (
legacyLocalmodelsTools(home, { persist: false })). The new tests cover both cases: "never falls back to another installation's shared legacy gateway when this home is isolated" and "resolveLocalmodelsBifrostLocation resolves a verified legacy home without writing the marker". - A legacy home uses the shared
-
P2: The 60 s clipboard clear was copied from
setup-account. Resolved.apps/desktop/src/main/secret-clipboard.tsholds the logic, and bothSetupAccountandLocalGatewayServiceuse it.CLIPBOARD_CLEAR_MSis re-exported, so existing imports still work. -
P2: The
computerIdcheck is not a security boundary. Resolved by documentation.apps/desktop/AGENTS.md,apps/desktop/src/shared/api.ts:186andapps/desktop/src/main/desktop-ipc.ts:247now say that theserverUrlorigin check is the boundary and thatcomputerIdonly routes the UI.
Findings
P3
- The PR description overstates the IPC gating.
apps/desktop/src/main/desktop-ipc.ts:247. The body still says the gateway is "Double-gated to both the configuredserverUrlorigin andcomputerId === desktopComputerId". The code and docs now say the origin check is the only security boundary. The revert note also names86a4a0d1/a2617509, which no longer exist after the rebase. Fix: update the description to match the docs and the current commit SHAs.
Verified as fine
resolveLocalmodelsBifrostLocationis read-only.legacyLocalmodelsToolsonly writes the marker whenpersistis true (localmodels-tool.ts:694).- With
allocate: false,resolveLocalmodelsBifrostAddrreturns beforepickFreeoratomicPrivate(localmodels-tool.ts:765). - Unlike
localmodelsIsolation, it does not callprivateDirectory.
LocalGatewayServiceis wired to this installation'shome(apps/desktop/src/main/index.ts:351). Every IPC handler goes throughrequireOwnGateway/isOwnComputer(desktop-ipc.ts:249-281), and the clipboard timer is disposed on unsubscribe (desktop-ipc.ts:282).- The password is read only after the file checks.
#readPasswordreads it only afterlstatconfirms a regular, non-symlink file of at most 4096 bytes, owned by the current user, with no group or other permission bits (local-gateway.ts:49-68,:208). - Two clipboard instances do not interfere. Each one clears only if the clipboard still holds its own secret (
secret-clipboard.ts:33-37). - Web follow-ups in
local-model-advanced-dialog.tsx:- A rejected
openFoldernow showsgatewayOpenFolderFailed, which has a zh-CN catalog entry (:656-662). - The Desktop "Open" admin button only renders when
adminUrlis present (:206,:288). - The fallback username matches
DEFAULT_ADMIN_USER = "localmodels"(:418,local-gateway.ts:17).
- A rejected
- No CJK outside the zh-CN catalog, and none in commit messages.
- No merge commits. The branch is up to date with
main.
Process notes
- None.
CI
All checks pass: repository-gate, desktop, packages, installer, web-static, web tests (1/2 and 2/2), web, and CodeQL. computer-go, contracts, teamhub and teamhub-cli were skipped because the PR touches none of their paths. I did not run any tests locally.
Automated review by Claude Code
Automated review of f948d04 by Claude Code.
f948d04 to
90a95b2
Compare
There was a problem hiding this comment.
Approve with nits (0 new findings; 1 previous P3 not resolved)
Scope: follow-up on f948d04. Base main, merge base eafcfd41, 4 commits, 25 files reviewed. Helper skills not loaded in this run; reviewed against the linger-pr-review checklist directly. Ran in a separate session. The previous head is no longer an ancestor (the branch was force-pushed after a rebase), so I compared the two versions with git range-diff and re-read the full merge-base diff.
Since the previous review: this is a rebase onto newer main. Conflict resolutions bring in the driver-update dialog, hasReadyAlternatives, and grouped expandedKey, and the isDesktopComputer prop is renamed to the existing isLocalDesktop prop. I found no new logic in the PR's own code.
Previous findings
- P3: PR description still says computerId is a second security gate. Not resolved. The code and docs now say the
serverUrlorigin check inhandle()is the only security boundary (apps/desktop/src/main/desktop-ipc.ts:267-268,apps/desktop/src/shared/api.ts:204-207). The PR body still says "Double-gated to both the configuredserverUrlorigin andcomputerId === desktopComputerId". It also still cites commitsa2617509and86a4a0d1, which are no longer in the branch (the current ones ared29753f7,e9667caa,eff3aa9eand90a95b28). Please update the description.
Findings
None new.
Verified as fine
- IPC origin gate. Every
localGatewaychannel goes throughhandle().handle()rejects any sender frame whose origin is not the configuredserverUrl(apps/desktop/src/main/desktop-ipc.ts:189-195).computerIdis checked with zod and matched against the enrolledcomputerId(desktop-ipc.ts:269-280).getInforeturns{available:false}instead of throwing. - Password read. The password is read on demand with
lstat: it must be a regular file, not a symlink, at most 4096 bytes, owned by the current user, and have mode& 0o077 === 0on POSIX (apps/desktop/src/main/local-gateway.ts:48-68,:214-219). It is never cached and never included inDesktopLocalGatewayInfo(apps/desktop/src/shared/api.ts:71-79). - Admin URL is loopback only.
openAdminonly opens URLs built byparseLoopbackBifrostAddress. That function accepts only127.0.0.1:<1-65535>(packages/local-installation/src/localmodels-tool.ts:547-557), so a tamperedbifrost-addrcannot open an arbitrary URL. - Read-only resolver.
resolveLocalmodelsBifrostLocationfollows the same branches aslocalmodelsIsolation(localmodels-tool.ts:868-900): legacy ownedapp_dir, otherwise the per-homebifrostdir. It does not write:legacyLocalmodelsTools(..., {persist:false})skips writing the marker, andallocate:falsereturns the saved or default address without probing ports (localmodels-tool.ts:746-772,:797-811). - Shared clipboard helper.
SecretClipboardpreserves the previousSetupAccountbehaviour: re-copying resets the timer, the clipboard is cleared only if it still holds the secret, and the timer isunref'd (apps/desktop/src/main/secret-clipboard.ts:24-41).SetupAccountnow delegates to it (apps/desktop/src/main/setup-account.ts:57-61), and the duplicate timer code is gone. The service is disposed on module stop (desktop-ipc.ts:302). - Rebase conflict resolution. Both
ComputerModelscall sites passisLocalDesktopcomputed from the desktop's enrolledcomputerId(apps/web/src/features/local-models/local-models-page.tsx:231-254).AdvancedDialogandUpdateDriverDialogboth get the same flag (local-models-page.tsx:1921-1931). - CJK check. Added lines outside the translation catalogs and all commit messages are free of CJK.
Process notes
- The branch is 2 commits behind
main, which requires up-to-date branches, so it needs a rebase. eff3aa9e("reuse localmodels Bifrost resolver and shared secret clipboard") and90a95b28("handle Diagnostics openFolder error…") patche9667caafrom the same PR. Sincemaintakes rebase merges, consider squashing them into it withgit rebase -i --autosquash.- No merge commits. All commits are authored by Dongdong Chen cdd@simplexai.com.
CI
Completed checks pass: desktop, installer, web tests (1/2, 2/2), repository-gate, CodeQL. check (packages) and web-static are still pending. The computer, teamhub and contracts checks were skipped because this PR doesn't touch those paths. I didn't run any tests locally; nothing in the changes since the previous review needed it.
Automated review by Claude Code
Automated review of 90a95b2 by Claude Code.
|
Rebased onto current main (head 90a95b2). Conflicts came from main's NVIDIA driver update IPC and grouped model rows landing in the same files; both sides are kept. The PR's |
90a95b2 to
be0577a
Compare
|
Rebased cleanly onto latest Conflicts resolved:
Also updated the PR description to resolve the remaining P3 note (accurate |
There was a problem hiding this comment.
Approve (0 findings)
Follow-up on 90a95b2. Merge base 1c35212b; 2 commits, 25 files reviewed. The previous review had no findings. Since then the branch has been rebased onto main and the three earlier commits squashed into two. The PR's own diff over its 25 files is byte-identical to the previous head's, and main touched none of those files in between.
Verified as fine
resolveLocalmodelsBifrostLocationis read-only. It callslegacyLocalmodelsTools(home, { persist: false }), which skips the marker write, andresolveLocalmodelsBifrostAddr(..., { allocate: false }), which returns beforeatomicPrivateor port allocation (packages/local-installation/src/localmodels-tool.ts:859-861,893-907). Its legacy branch resolves the same directory and address aslocalmodelsIsolation(:968-981).- Password reads go through
lstatand require a non-symlink regular file of at most 4096 bytes, owned by the current UID, with mode& 0o077 === 0(apps/desktop/src/main/local-gateway.ts:48-67,211-217). Every gateway IPC passes theserverUrlsame-origin check inhandle()(apps/desktop/src/main/desktop-ipc.ts:192) and the enrolled-computerIdmatch (:270-280).openAdminonly opens the URL fromparseLoopbackAdminUrl, which accepts only127.0.0.1:<port>. SecretClipboardmatches the clipboard logic previously inlined inSetupAccount: clear after 60s only if the value is unchanged, and re-copying resets the timer (apps/desktop/src/main/secret-clipboard.ts:24-41).setup-account.tsnow reuses it.
CI: all required checks pass (desktop, web, web tests 1/2 and 2/2, packages, installer, repository-gate, CodeQL). Go, contracts and teamhub checks were skipped because the PR doesn't touch them. The branch is up to date with main. I ran no tests myself.
Automated review by Claude Code
Automated review of be0577a by Claude Code.
be0577a to
255a90f
Compare
|
Rebased onto latest |
There was a problem hiding this comment.
Approve (0 findings)
Follow-up on be0577a. Merge base 6a511c15, 2 commits, 25 files reviewed. The only change since the previous review is the rebase onto main's 48258b1f ("drop divider lines"). It removes every bordered prop and divide-y class from the new dialog and the details card, which matches the new Fact signature at apps/web/src/features/local-models/local-model-details.tsx:59. No bordered or divide-y is left under features/local-models/.
Verified as fine
- Every
local-gateway.*channel goes throughhandle()'sserverUrlorigin check, andcomputerIdmust match the enrolled computer. Reveal, copy, open-admin and open-folder throwNot allowedotherwise (apps/desktop/src/main/desktop-ipc.ts:267-302). - The password is read only from a file that is a regular, non-symlink file owned by the current user, mode
0600, and at most 4 KiB (apps/desktop/src/main/local-gateway.ts:48-68). The resolver is read-only:persist: falseskips writing the legacy marker andallocate: falseskips allocating a port (packages/local-installation/src/localmodels-tool.ts:893-906). openAdminonly opens a URL built byparseLoopbackBifrostAddress, so it is alwayshttp://127.0.0.1:<port>(apps/desktop/src/main/local-gateway.ts:38-46).
CI: All finished checks pass (desktop, packages, installer, web tests 1/2 and 2/2, repository-gate, CodeQL). web-static was still pending at review time. I ran no tests myself.
Automated review by Claude Code
Automated review of 255a90f by Claude Code.
What and why
Clarifies the single-gateway architecture in the Local Models UI and upgrades the computer
Detailsdialog into a tabbedAdvancedmodal with local-only Bifrost gateway credentials on Linger Desktop:51f52eb1):Shared gateway(Ready · Bifrost (Pi)+http://127.0.0.1:18480/v1frommodel-source.status.gateway_url) from each model's backendModel server(http://127.0.0.1:1810x/v1), avoiding the impression that each loaded model runs a separate Bifrost gateway.Advanceddialog & local-only Desktop gateway IPC (255a90fd):Detailsbutton withAdvanced(Gateway & access,Memory & hardware,Diagnostics):/v1API endpoint, Bifrost Admin console URL (with DesktopOpenwhenadminUrlis available), access scope (Local only (127.0.0.1)· no API key required on localhost), loaded model IDs with one-clickCopy IDandCopy curl, and Admin credentials.localmodelstool version, copyable Computer ID, debug mode), per-model backend server endpoints, and Desktop local tools (Save diagnostics,Open gateway folderwith error feedback).LocalGatewayService(window.lingerDesktop.localGateway) backed by read-onlyresolveLocalmodelsBifrostLocationin@linger/local-installationand sharedSecretClipboard:serverUrlorigin check inDesktopIpcModuleis the IPC security boundary;computerId === desktopComputerIdroutes the UI to this desktop's enrolled computer.admin-passwordon demand only after verifying regular file, non-symlink,<= 4096bytes, owner UID, and POSIX0600mode; never transmits credentials over TeamHub.openAdminto loopback127.0.0.1URLs, and marks reveal/copy controlsdata-voice-risk="never".How it was verified
make check BASE=origin/main/ fast checks of every touched appcontracts/openapi/changed (N/A — no OpenAPI schema changes)Commands run against rebased
HEAD(255a90fdonorigin/main6a511c15):make check-repository BASE=origin/main,scripts/ci/check-changed-files.sh origin/main HEAD, andnode scripts/check-doc-links.mjs→ exit 0 (Prettier, env inventory, CJK gate, 111 Markdown files)packages/local-installation:typecheck,lint, andvitest run src/localmodels-tool.test.ts(64 passed, 1 skipped)apps/desktop:typecheck,lint, andvitest run src/main/local-gateway.test.ts src/main/desktop-ipc.test.ts src/main/setup-account.test.ts(34/34 passed)apps/web:typecheck,lint,pnpm react:doctor --base origin/main, andvitest runforlocal-models-page.test.tsx,local-models-rules.test.ts, andvoice-risk-markers.test.ts(131/131 passed)Boundary
apps/web/AGENTS.md,apps/desktop/AGENTS.md, andpackages/local-installation/AGENTS.md.provider_readypath (adds zero network round trips or filesystem walks during chat send).255a90fdand51f52eb1cleanly restores the priorDetailsdialog and endpoint row with no data, config, or API contract migrations.