Skip to content

feat(local-models): seamless Agent switching and automatic Pi setup - #251

Merged
oldwinter53 merged 3 commits into
mainfrom
ws/20261118-local-models-seamless-agent-ux-r3
Nov 19, 2026
Merged

oldwinter53 merged 3 commits into
mainfrom
ws/20261118-local-models-seamless-agent-ux-r3

Conversation

@oldwinter53

Copy link
Copy Markdown

Summary

Supersedes #245 and #250 (rebased cleanly onto latest main at 307f2ab4) and resolves every linger-review finding across both reviews (P1, P2, P3):

  • Pi provisioning timeouts (apps/computer/local-daemon/internal/localmodels): Match packages/local-installation/src/managed-runtimes.ts (2m harnessStatusTimeout / harnessPlanTimeout, 20m harnessApplyTimeout, 24m total defaultEnsurePiTimeout).
  • Setup-failure visibility & Pi readiness gating (main.go, library.go, local-model-details.tsx, local-models-page.tsx): Expose PiProvisionFailed() on Library, wake RuntimeChanged on initial provisioning failure so withPiProvisionStatus reports error (RUNTIME_DIAGNOSTIC_FAILED), distinguish missing !piRuntime (Bifrost · Pi not installed) from reported not_installed (Bifrost · Setting up Pi…), and gate Agent switching on ready Pi.
  • Shared badge rule & Router cleanup (local-models-rules.ts, local-model-row.tsx, edit-agent-runtime-dialog.tsx): Reuse usedByBadge(entry, names) across local-models-rules and ModelRow, and remove test-only useInRouterContext fallbacks in favor of MemoryRouter in unit tests.
  • Explicit busy-Agent handling in Make room handoff (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.
  • Deterministic lock test (fake_tool_test.go, pi_runtime_test.go): Replace the short DelayMS window with an explicit WaitFile (download-wait) gate sharing waitForGateRemoval with harness-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"]
Loading
  • Computer Daemon (internal/localmodels, linger-computer-daemon):
    • Align PI_CODING_AGENT_DIR in Tool.commandArgs with OverlayEnvironment (local mode) and workspace.PiSourceEnvironment so localmodels writes loaded models to the same profile the Daemon probes and runs.
    • When a local model is loaded on a Computer with Pi enabled and uninstalled, Library.scheduleEnsurePi asynchronously runs localmodels harness status/plan/apply (passing bundled --node when present, 2m status/plan and 20m apply budgets, backing off from 30s up to 5m on failure, outside refreshMu, awaited on Close()), then notifies RuntimeChanged so Pi comes online (or surfaces RUNTIME_DIAGNOSTIC_FAILED on failure).
    • user message -> provider_ready critical path: adds no network round trip or file walk while waiting on a turn; provisioning runs only in the background after localmodels library snapshots show a loaded model.
  • Web (Settings > Models, Room Composer & Runtime Dialog):
    • Show live Bifrost / Pi readiness in the expanded Gateway row (Ready · Bifrost (Pi), Bifrost · Registering with Pi…, Bifrost · Setting up Pi…, Bifrost · Pi not installed, Bifrost · Pi unavailable).
    • Gate per-Agent switching on ready Pi in local mode, adding one-click Use with <Another Me> (or sole Sponsor-owned Agent) + Open chat alongside Use for Agents, multi-Agent Switch Agent… in Used by, and Make room automatic Agent handoff.
    • Resolve localmodels-library/... names from localModelsQueryOptions in useResolvedAgentModelLabel (DirectAgentModelSwitch and ActorProfileContent) before Pi lists them, keep AgentInfoContent runtimeDetails hidden per Town room-surface invariants, and link Pi in EditAgentRuntimeDialog to Settings > Models.

Evidence

  • Before: Loading a local model on a Codex/Claude-only Computer left Pi uninstalled or misaligned on PI_CODING_AGENT_DIR, showed no Bifrost readiness or Agent-switching controls on the model card, forced manual runtime setup in Computers + Agent settings, and displayed raw localmodels-library/... IDs in Room headers until Pi refreshed.
  • After: Passed locally on ws/20261118-local-models-seamless-agent-ux-r3 rebased cleanly onto origin/main (307f2ab4):
    • make -C apps/teamhub lint-go-daemon BASE=origin/main — 0 issues
    • go test -race ./internal/localmodels ./cmd/linger-computer-daemon — passed (92.537s and 4.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) — passed
    • pnpm --filter @linger/web run build:assets — passed (547.63 kB minified / 185.44 kB gzip / 161.45 kB Brotli)
    • make check-repository-gate BASE=origin/main (commitlint, env inventory, Prettier/ESLint/English-only checks, script tests, doc links) — passed (147 fast + 166 passed | 3 skipped slow script tests, 99 Markdown link files resolved)
  • Issues: Checked open issues #157 and #220 in simplexai-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-daemon localmodels supervision and apps/web Settings > Models and Agent runtime selection components.

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.

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. apps/web/src/features/local-models/local-model-dialogs.tsx:102: the Make room handoff checkbox can promise a switch that never happens.

    • MakeRoomDialog shows the checked "Switch X to Y once loaded" box whenever the target has a pi_model and an affected Agent is idle. local-models-page.tsx:951 keeps the switch only when canSwitchAgents is true (Pi ready, local mode, online, owner).
    • Failure case: Pi is in error/not_installed, or the overlay mode is not local. The user leaves the box checked and confirms. The model loads, pendingSwitch is set to null, and no Agent is switched. No message tells the user.
    • Fix: pass assignableAgents={canSwitchAgents ? assignableAgents : []} to MakeRoomDialog. The checkbox then appears only when the page will carry out the switch.
  2. apps/web/src/features/local-models/local-model-agents.ts:131: usedByAgentNames dedupes by display name as well as by ID (user.name === agent.name).

    • Repo rule: behavior must not key on human-readable labels. used_by already has agent_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.name clause.

Verified as fine

  • Daemon locking. scheduleEnsurePi checks closed/piEnsuring/piRetryAt and calls piWg.Add under mu. Close sets closed under mu before piWg.Wait. Provisioning runs after refreshMu is released, and the subprocess is killed when l.ctx is cancelled.
  • Backoff and retry. Backoff runs from 30s and is capped at 5m. RuntimeChanged fires only on success or on the first failure. PiProvisionFailed only rewrites a not_installed Pi diagnostic to RUNTIME_DIAGNOSTIC_FAILED, a code the provider already uses.
  • Shared localModels variable in main.go. It is assigned before the monitor goroutines start, so the closures that read it do not race.
  • Tool.runBuffered refactor. It merges the old runOnce and ModelSource.runTool bodies. Stdout/stderr still go to temp files, not pipes, so the gateway child survives. The env cleaning and cancel/kill behavior are unchanged. jobOutput is still used by the long-job path.
  • PI_CODING_AGENT_DIR alignment. OverlayEnvironment plus workspace.PiSourceEnvironment decide the value, and TestToolCommandAlignsPiCodingAgentDir covers the default, explicit, overlay and subscription cases.
  • Harness plan check. Schema, runtime and id are validated before apply --approve. The executable must be an absolute path with an empty argvPrefix.
  • Agent PATCH. It sends expected_configuration_revision. TeamHub replaces the whole runtime (agent_update.go), so an omitted reasoning_effort clears 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 useInRouterContext fallbacks are gone. The badge rule is shared through usedByBadge(entry, names). Busy Agents are excluded from the handoff and reported in a banner. The lock test uses a WaitFile gate instead of a sleep. apps/web/AGENTS.md and the daemon README were updated.
  • Critical path. The user message → provider_ready path 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 ran go 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.

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:943 now passes canSwitchAgents ? assignableAgents : [] to MakeRoomDialog, so the dialog only shows the handoff checkbox when it will act on it. The handoff at line 951 was already gated on canSwitchAgents. The new test hides the Make room handoff checkbox when Pi is not ready for Agent switching is the existing positive handoff test with enableReadyPi removed, 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:130 now dedups only on agent_id. The new assertion in local-model-agents.test.ts covers 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

  • changes passed. web tests (1/2, 2/2), web-static, check (computer-go), check (desktop), repository-gate and 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.

@oldwinter53
oldwinter53 added this pull request to the merge queue Nov 19, 2026
Merged via the queue into main with commit 688850c Nov 19, 2026
15 checks passed
@oldwinter53
oldwinter53 deleted the ws/20261118-local-models-seamless-agent-ux-r3 branch November 19, 2026 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants