Repository navigation
feat(local-models): seamless Agent switching and automatic Pi setup - #251
Conversation
Align PI_CODING_AGENT_DIR across OverlayEnvironment and workspace.PiSourceEnvironment so localmodels registers loaded models into the exact profile the daemon discovers and runs. Share HarnessRoot and Tool.runBuffered across library, source, and daemon startup, match the installer's 2 m status/plan and 20 m apply timeouts, surface RUNTIME_DIAGNOSTIC_FAILED after a failed setup attempt, and run localmodels harness status/plan/apply (--node with exponential backoff outside refreshMu) when a local model is loaded without Pi.
Show live Bifrost (Pi) Gateway readiness above Endpoint (distinguishing uninstalled, setting up, registering, and failed states), gate row/card Agent switching on ready Pi, add Use with <Another Me> and Open chat actions alongside Used by switching and Make room automatic Agent handoff (excluding busy Agents and surfacing busy-handoff warnings), reuse usedByBadge in local-models-rules, drop test-only useInRouterContext fallbacks, link Pi setup to Settings > Models, and resolve localmodels-library IDs via useResolvedAgentModelLabel.
There was a problem hiding this comment.
Approve with nits (2 P3)
Scope: base main at merge-base 307f2ab4 (branch is up to date); 2 commits, 25 files reviewed. Helper skills loaded: ponytail-review, karpathy-guidelines; coderbook was not loaded, so its sections were applied from the review checklist only. Ran in a separate session.
Findings
P3
-
apps/web/src/features/local-models/local-model-dialogs.tsx:102: the Make room handoff checkbox can promise a switch that never happens.MakeRoomDialogshows the checked "Switch X to Y once loaded" box whenever the target has api_modeland an affected Agent is idle.local-models-page.tsx:951keeps the switch only whencanSwitchAgentsis true (Piready,localmode, online, owner).- Failure case: Pi is in
error/not_installed, or the overlay mode is notlocal. The user leaves the box checked and confirms. The model loads,pendingSwitchis set tonull, and no Agent is switched. No message tells the user. - Fix: pass
assignableAgents={canSwitchAgents ? assignableAgents : []}toMakeRoomDialog. The checkbox then appears only when the page will carry out the switch.
-
apps/web/src/features/local-models/local-model-agents.ts:131:usedByAgentNamesdedupes by display name as well as by ID (user.name === agent.name).- Repo rule: behavior must not key on human-readable labels.
used_byalready hasagent_id. - Failure case: Agent A "Helper" is in
used_by. Agent B, also named "Helper", was just switched onto the model and is not in the snapshot yet. B is dropped, so the badge and the "Used by" list show one Agent too few until the next snapshot. - Fix: remove the
|| user.name === agent.nameclause.
- Repo rule: behavior must not key on human-readable labels.
Verified as fine
- Daemon locking.
scheduleEnsurePichecksclosed/piEnsuring/piRetryAtand callspiWg.Addundermu.ClosesetsclosedundermubeforepiWg.Wait. Provisioning runs afterrefreshMuis released, and the subprocess is killed whenl.ctxis cancelled. - Backoff and retry. Backoff runs from 30s and is capped at 5m.
RuntimeChangedfires only on success or on the first failure.PiProvisionFailedonly rewrites anot_installedPi diagnostic toRUNTIME_DIAGNOSTIC_FAILED, a code the provider already uses. - Shared
localModelsvariable inmain.go. It is assigned before the monitor goroutines start, so the closures that read it do not race. Tool.runBufferedrefactor. It merges the oldrunOnceandModelSource.runToolbodies. Stdout/stderr still go to temp files, not pipes, so the gateway child survives. The env cleaning and cancel/kill behavior are unchanged.jobOutputis still used by the long-job path.PI_CODING_AGENT_DIRalignment.OverlayEnvironmentplusworkspace.PiSourceEnvironmentdecide the value, andTestToolCommandAlignsPiCodingAgentDircovers the default, explicit, overlay and subscription cases.- Harness plan check. Schema, runtime and
idare validated beforeapply --approve. The executable must be an absolute path with an emptyargvPrefix. - Agent PATCH. It sends
expected_configuration_revision. TeamHub replaces the whole runtime (agent_update.go), so an omittedreasoning_effortclears the old Codex/Claude effort instead of carrying it over. TeamHub rejects Agents with active runs, and the UI disables busy Agents. - Claims in the PR body. The
useInRouterContextfallbacks are gone. The badge rule is shared throughusedByBadge(entry, names). Busy Agents are excluded from the handoff and reported in a banner. The lock test uses aWaitFilegate instead of a sleep.apps/web/AGENTS.mdand the daemon README were updated. - Critical path. The user message →
provider_readypath is unaffected: provisioning runs only in the background after Refresh.
Process notes
- The branch is up to date with
main. No merge commits and no fixup commits.
CI
- All checks pass (
computer-go,web tests 1/2 and 2/2,web-static,desktop,repository-gate, CodeQL). - CI runs the daemon Go tests without
-race. I rango test -race -count=1 -p 4 ./internal/localmodels -run 'Pi|Harness|Ensure'locally: it passed in 33s.
Automated review by Claude Code
Automated review of b00a65c by Claude Code.
Pass assignableAgents to MakeRoomDialog only when canSwitchAgents is true so the handoff checkbox never promises a switch while Pi is unavailable or a non-local model source is active, and deduplicate usedByAgentNames by agent_id rather than display name.
There was a problem hiding this comment.
Approve (0 findings)
Scope: follow-up review on b00a65c → 332ad81. Base main, merge base 307f2ab4, 3 commits in the PR. This pass reviewed only the new commit 332ad81 (4 files, +47/−4). Helper skills (coderbook, ponytail-review, karpathy-guidelines) were not loaded separately for this small follow-up; their checklists were applied from the review instructions. The review ran in a separate session.
Previous findings
- P3 Make room checkbox promised a switch that could be silently dropped: Resolved.
apps/web/src/features/local-models/local-models-page.tsx:943now passescanSwitchAgents ? assignableAgents : []toMakeRoomDialog, so the dialog only shows the handoff checkbox when it will act on it. The handoff at line 951 was already gated oncanSwitchAgents. The new testhides the Make room handoff checkbox when Pi is not ready for Agent switchingis the existing positive handoff test withenableReadyPiremoved, so it fails without the fix. - P3 Used-by dedup matched on display name: Resolved.
apps/web/src/features/local-models/local-model-agents.ts:130now dedups only onagent_id. The new assertion inlocal-model-agents.test.tscovers two different Agents that share the name "Helper", and both are listed.
Findings
None.
Verified as fine
canSwitchAgents(local-models-page.tsx:503) requires the Computer to be online, the viewer to be the owner, Pi to be ready, and local mode. So the checkbox and the switch it triggers now use the same rule.- The used-by change is tied to the Agent ID, which is the correct context. The earlier expectations that use different names still hold.
- The new commit does no unrelated work and needs no doc changes.
Process notes
- No merge commits. The branch is up to date with
main(0 behind). Merge state is BLOCKED only because CI checks are still pending.
CI
changespassed.web tests (1/2, 2/2),web-static,check (computer-go),check (desktop),repository-gateand CodeQL were still pending when this review ran. Contracts, teamhub, teamhub-cli, packages and installer were skipped as not affected.- I ran no tests myself. The follow-up diff is a two-line Web change with matching unit tests, which CI's web test jobs run.
Automated review by Claude Code
Automated review of 332ad81 by Claude Code.
Summary
Supersedes
#245and#250(rebased cleanly onto latestmainat307f2ab4) and resolves everylinger-reviewfinding across both reviews (P1,P2,P3):apps/computer/local-daemon/internal/localmodels): Matchpackages/local-installation/src/managed-runtimes.ts(2mharnessStatusTimeout/harnessPlanTimeout,20mharnessApplyTimeout,24mtotaldefaultEnsurePiTimeout).Pireadiness gating (main.go,library.go,local-model-details.tsx,local-models-page.tsx): ExposePiProvisionFailed()onLibrary, wakeRuntimeChangedon initial provisioning failure sowithPiProvisionStatusreportserror(RUNTIME_DIAGNOSTIC_FAILED), distinguish missing!piRuntime(Bifrost · Pi not installed) from reportednot_installed(Bifrost · Setting up Pi…), and gate Agent switching on readyPi.local-models-rules.ts,local-model-row.tsx,edit-agent-runtime-dialog.tsx): ReuseusedByBadge(entry, names)acrosslocal-models-rulesandModelRow, and remove test-onlyuseInRouterContextfallbacks in favor ofMemoryRouterin unit tests.local-model-dialogs.tsx,local-models-page.tsx): Exclude already-busy Agents from the handoff checkbox and show an explicit error banner when a selected Agent starts a turn before the replacement model finishes loading.fake_tool_test.go,pi_runtime_test.go): Replace the shortDelayMSwindow with an explicitWaitFile(download-wait) gate sharingwaitForGateRemovalwithharness-plan-wait.flowchart LR Load["localmodels load / Refresh"] --> Dir["Align PI_CODING_AGENT_DIR<br/>(OverlayEnvironment / PiSourceEnvironment)"] Load --> Bg["Background EnsurePi<br/>(harness status/plan/apply --node,<br/>2m/20m budgets + exponential backoff)"] Bg -->|pi_ready / pi_install_failed| Discover["RuntimeChanged -> Discover<br/>(withManagedPiPath / withPiProvisionStatus)"] Discover --> UI["Settings > Models<br/>Gateway row + Use with Another Me<br/>Open chat + Switch Agent..."] UI -->|PATCH agents runtime| Room["Room Composer & Runtime Dialog<br/>useResolvedAgentModelLabel fallback<br/>+ Settings > Models link"]internal/localmodels,linger-computer-daemon):PI_CODING_AGENT_DIRinTool.commandArgswithOverlayEnvironment(localmode) andworkspace.PiSourceEnvironmentsolocalmodelswrites loaded models to the same profile the Daemon probes and runs.Pienabled and uninstalled,Library.scheduleEnsurePiasynchronously runslocalmodels harness status/plan/apply(passing bundled--nodewhen present,2mstatus/plan and20mapply budgets, backing off from30sup to5mon failure, outsiderefreshMu, awaited onClose()), then notifiesRuntimeChangedsoPicomes online (or surfacesRUNTIME_DIAGNOSTIC_FAILEDon failure).user message -> provider_readycritical path: adds no network round trip or file walk while waiting on a turn; provisioning runs only in the background afterlocalmodelslibrary snapshots show a loaded model.Settings > Models, Room Composer & Runtime Dialog):Pireadiness in the expandedGatewayrow (Ready · Bifrost (Pi),Bifrost · Registering with Pi…,Bifrost · Setting up Pi…,Bifrost · Pi not installed,Bifrost · Pi unavailable).Piinlocalmode, adding one-clickUse with <Another Me>(or sole Sponsor-owned Agent) +Open chatalongsideUse for Agents, multi-AgentSwitch Agent…inUsed by, andMake roomautomatic Agent handoff.localmodels-library/...names fromlocalModelsQueryOptionsinuseResolvedAgentModelLabel(DirectAgentModelSwitchandActorProfileContent) beforePilists them, keepAgentInfoContentruntimeDetailshidden per Town room-surface invariants, and linkPiinEditAgentRuntimeDialogtoSettings > Models.Evidence
Piuninstalled or misaligned onPI_CODING_AGENT_DIR, showed noBifrostreadiness or Agent-switching controls on the model card, forced manual runtime setup inComputers+ Agent settings, and displayed rawlocalmodels-library/...IDs in Room headers untilPirefreshed.ws/20261118-local-models-seamless-agent-ux-r3rebased cleanly ontoorigin/main(307f2ab4):make -C apps/teamhub lint-go-daemon BASE=origin/main—0 issuesgo test -race ./internal/localmodels ./cmd/linger-computer-daemon— passed (92.537sand4.536s)pnpm --filter @linger/web test src/features/local-models/local-models-rules.test.ts src/features/local-models/local-model-agents.test.ts src/features/local-models/local-models-page.test.tsx src/features/rooms/chat/direct-agent-model-switch.test.tsx src/features/rooms/members/edit-agent-runtime-dialog.test.tsx— passed (5 files,108 tests)make check BASE=origin/main(check-repository,check-docs,check-desktop,check-web,check-node-services,check-computer) — passedpnpm --filter @linger/web run build:assets— passed (547.63 kBminified /185.44 kBgzip /161.45 kBBrotli)make check-repository-gate BASE=origin/main(commitlint, env inventory, Prettier/ESLint/English-only checks, script tests, doc links) — passed (147fast +166 passed | 3 skippedslow script tests,99Markdown link files resolved)#157and#220insimplexai-labs/linger; deliberate skip (neither relates to Local models, automatic Pi setup, or Agent switching).Merge Danger
Door: Two-way
Revert removes the additive UI controls and background harness provisioning cleanly with no schema, OpenAPI contract, or database migration changes.
Blast Radius: Low
Scoped to
apps/computer/local-daemonlocalmodelssupervision andapps/webSettings > Modelsand Agent runtime selection components.