Repository navigation
feat(local-models): upgrade UX, agent setup, and model telemetry - #240
oldwinter53 wants to merge 1 commit into
Conversation
Task: 20261118-local-models-experience-upgrade
There was a problem hiding this comment.
Request changes (1 P1, 4 P2, 1 P3)
Scope: base main at merge base fb2e1537, 1 commit, 43 files (+7482/−418) reviewed at 320f96a. Loaded skills: coderbook, ponytail-review, karpathy-guidelines. This review ran in a separate session.
Findings
P1
1. LINGER_LOCALMODELS_CACHE_DIR / LINGER_LOCALMODELS_REUSE_DIRS forwarding never works in production — apps/computer/local-daemon/internal/localmodels/tool.go:94
commandArgsmaps theLINGER_LOCALMODELS_*keys toLOCALMODELS_*, but the only environment that reaches it isproviderEnvironment(cmd/linger-computer-daemon/main.go:318, andInspectPi). That map is built bycomputerconfig.RuntimeEnvironment, which drops everyLINGER_-prefixed key (internal/computerconfig/environment.go:34).- Failure scenario: an operator sets
LINGER_LOCALMODELS_CACHE_DIR=/shared/cachein the Daemon environment, as the README and the PR body say to. The key is stripped beforeLibrary/Toolsee it, solocalmodelsgets noLOCALMODELS_CACHE_DIRand downloads the weights again. The tests inpi_runtime_test.go:67-110callcommandArgsdirectly withLINGER_keys, so they pass even though the production path is broken. - Fix: delete the
LINGER_aliasing (lingerCacheDir,lingerReuseDirs, andkeyPreference/firstNonEmptyif nothing else uses them). Document settingLOCALMODELS_CACHE_DIR/LOCALMODELS_REUSE_DIRSdirectly;RuntimeEnvironmentalready passes those through. Update the README paragraph to match. If the alias has to stay, it must be read in the config module and listed inscripts/env-inventory.json, and a test must go throughruntimeProviderEnvironment.
P2
2. PI_CODING_AGENT_DIR is resolved in two places — apps/computer/local-daemon/internal/localmodels/tool.go:85-106
runtimeProviderEnvironment(main.go:804) already setsPI_CODING_AGENT_DIRfromworkspace.PiSourceEnvironment, and that map is the only one passed toLibrary/Tool.commandArgsthen re-records it with case-preference logic and callsPiSourceEnvironmentagain. Two copies of the same rule can drift apart.- Fix: drop the
piAgentDirhandling and thePiSourceEnvironmentcall fromcommandArgs, and keep the single alignment inruntimeProviderEnvironment.
3. buildLoadProgress invents step counts from magic numbers, so progress can go backwards — apps/computer/local-daemon/internal/localmodels/library.go:828
loadusestotal = min(100, rawTotal+2), butwarmis hard-coded to5+doneout of7. The step is guessed fromdone < 3/== 3. The PR's own test case (load,Total: 150) produces x/100.- Failure scenario: a model loads with
Total: 150and reaches 98/100, then the firstwarmevent reports 5/7. The UI's "Loading … · N%" drops from 98% to 71%. - Fix: pass through what
localmodelsreports (load_step,done,total) and validate it. If a field is missing, leaveloadunset instead of making up a step model inside the Daemon.
4. The workspace-grant selection rule now exists three times, and the copies disagree — apps/web/src/features/local-models/local-model-agents.ts:170-182
buildLocalModelRuntimeUpdatekeeps any grant the Agent already holds (even a read-only one), and otherwise falls back toworkspace_grants[0], which may also be read-only.- The existing rule,
findWritableGrant/isMoveTargetComputerinapps/web/src/features/rooms/members/agent-move-target.ts:55-67, treats a Computer without a writable grant as an invalid target.direct-agent-model-switch.tsx:85-96adds a third copy that requires a writable retained grant. - Failure scenario: on a Computer that has only a
read-onlygrant, "Use with " PATCHes the Agent onto a read-only workspace. The Room's switch menu hides that same Computer. - Fix: use
findWritableGrant(plus a "keep the current grant if it is writable" check) in both new call sites.
5. The quick-switch menu re-implements ActionMenu — apps/web/src/features/rooms/chat/direct-agent-model-switch.tsx:326-480
QuickLocalModelMenuhand-rolls about 150 lines: portal, positioning with scroll/resize/ResizeObserver, outside-click on bothpointerdownandmousedown, Escape, focus of the first item, and Arrow/Home/End navigation, pluscomputePopoverPosition.apps/web/src/components/ui/action-menu.tsxalready providesheader,placement="top-start",itemswithdisabled/separatorBefore, and keyboard handling, and it is used byaccount-menu.tsxand others.- Fix: render the options as
ActionMenuitems, with the Computer name and the "Local models" link inheaderor in items. Then delete the custom position and keyboard code anddirect-agent-model-switch.cssif nothing else needs it.
P3
6. The localmodels-library/ prefix constant has four new copies — apps/web/src/features/rooms/members/use-agent-model-selection.ts:13, rooms/chat/direct-agent-model-switch.tsx:43, local-computer/computer-detail.tsx:63, local-computer/computer-directory.tsx:23
local-models-rules.ts:13already definespiLibraryModelPrefix. Export it, or export a smallisLocalLibraryModel(id)helper, and reuse it everywhere.
Verified as fine
- The background Pi provisioning in
Libraryis single-flight (piEnsuring), backs off exponentially up to 5 min, cancels its retry timer when no model is loaded, andClose()cancels the context and waits onpiWg. It runs afterrefreshMuis released, so it is off theuser message → provider_readypath, as the PR states.go test -race -count=1 ./internal/localmodels/passes locally (114 s). - The harness plan is checked against the schema, the runtime and the 64-hex ID before
apply --approve. The temporary plan dir is removed. Harness output reads are bounded (4 MiB). withManagedPiPath/withManagedPiEnvironmentnever override a user-configuredruntime_paths.pi. Provisioning is skipped when Pi is already discovered externally.- Contracts: the new
download.source/connectionsandloadfields are optional in bothenvelope.schema.jsonandlocal-models.yaml. The generated Go and TS files are consistent with them. TeamHub'svalidLocalModelsSnapshotenforces the same bounds as the Daemon'scheckModel. Note that the TeamHub internal decode is strict (DisallowUnknownFields) and the envelope hasadditionalProperties: false, so TeamHub and the Agent Service must be deployed before Daemons that emitload. - The Computers page summary is derived from
computer.runtimesonly, with no/local-modelsrequest. "Use when ready" clears onfailed/available/unavailable/missing, and skips busy Agents and Agents already on the model. apps/web/AGENTS.mdand the daemon README are updated (apart from the cache-dir claim in finding 1).git merge-treeagainst currentorigin/mainshows no conflicts.
Process notes
- The whole feature (Daemon Pi provisioning, contract telemetry fields, and a large Web UX rework) lands as one 7.5k-line commit. Since
maintakes rebase merges, consider splitting it along those three boundaries so each can be understood and reverted on its own. - No merge commits or fixup commits.
CI
Only Analyze (actions) and CodeQL ran on 320f96a, and both pass. The main CI workflow (fast checks, Go/TS tests, contracts verify) has no run on this head, so it needs to run and pass before merge.
I ran go test -race -count=1 -p 4 ./internal/localmodels/ in apps/computer/local-daemon and it passed. I did not run the Web Vitest suites locally.
Automated review by Claude Code
Automated review of 320f96a by Claude Code.
|
Closing before the 0.1.4 release (decided by the author). Reasons: rebasing onto main conflicts in 11 files / 47 hunks (daemon main.go and the web local-models files rewritten by #222, #223 and #242); it changes contracts and TeamHub without a green CI run; its background Pi provisioning installs Pi under state/local-models/harness instead of the runtime/harness root the installer manages (two Pis on one Computer), reads only harness-error/v1 lines so RUNTIME_EXTENSIONS_FAILED, RUNTIME_ACTION_FAILED and pi-extensions-unavailable (localmodels dev40) are never recognized, and without PI_CODING_AGENT_DIR it would use the personal ~/.pi/agent profile. #245 re-does part of the same feature. A smaller follow-up built on the model source work (#222, #242) is planned after 0.1.4. |
What and why
End-to-end UX, runtime setup, and telemetry improvements for Local Models:
PI_CODING_AGENT_DIRwith the managed Pi environment (workspace.PiSourceEnvironment).localmodels harness status/plan/apply) when a local model reachesloaded.LINGER_LOCALMODELS_CACHE_DIR/LINGER_LOCALMODELS_REUSE_DIRStosimplex-localmodels(LOCALMODELS_CACHE_DIR/LOCALMODELS_REUSE_DIRS) for cross-container weight reuse.download.source(huggingface|modelscope|custom|cache),download.connections, andload(prepare|start|load|warm,done_steps,total_steps) across Runner Gateway and OpenAPI contracts.Settings > Local models:localStoragepersistence with· N loaded/· Offlinepicker hints.AutoHeightexpand transitions, and skeleton loading states.Use with <Agent>,Open chat,Use when readyqueued auto-switch, Make Room handoff option, top-pinned diagnostic callouts, and 2-columnModelFacts(Switch Agent…, pre-filled+ New Agent).Transfertransparency (ModelScope mirror/Hugging Face/Local cache· parallel connections ·binary MB/s (MiB/s)) and determinateLoadingstep progress (Loading weights to GPU 0 · 57%).Settings > Computers& Rooms:Computersderived strictly fromcomputer.runtimes(zero/local-modelsHTTP requests).localmodels-library/*model names across Room profiles and dialogs, directLocal modelslinks when Pi has no loaded models, and a 1-clickLocal models (Pi)quick-switcher menu (role="menu") in the Chat composer.How it was verified
go test -race ./internal/localmodels/...,go test -race ./internal/app -run 'Test.*LocalModels', Vitest suites acrosslocal-models,local-computer, androoms, and headless Chromium end-to-end visual verification)make check BASE=origin/mainor the fast checks of every touched app (make check BASE=origin/mainexited0,531.9s;make check-packages,lint-go,lint-go-daemon0 issues;pnpm --filter @linger/web run build:assetspassed initial JS budgets at546.26 kBminified /184.86 kBgzip /160.97 kBBrotli)contracts/openapi/changed (make contracts-generate && make contracts-verifyexited0)Boundary
apps/computer/local-daemon/README.mdandapps/web/AGENTS.md.user message -> provider_readycritical path: adds no network round trip or file walk while the user waits (managed Pi provisioning runs asynchronously in a background singleflight when the library snapshot observes aloadedmodel).download.source,download.connections, andloadare optional in Runner Gateway and OpenAPI schemas, so Linger remains backward-compatible with oldersimplex-localmodelsbuilds and surfaces transfer/load progress automatically when paired with an updatedsimplex-localmodelsrelease.