Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

fix(models): scope memory guidance and handle legacy localmodels kits

Dongdong Chen5da4a3e1d93f
diff --git a/apps/computer/local-daemon/internal/localmodels/source.go b/apps/computer/local-daemon/internal/localmodels/source.go
index e6ba4d4c..fe322b51 100644
--- a/apps/computer/local-daemon/internal/localmodels/source.go
+++ b/apps/computer/local-daemon/internal/localmodels/source.go
@@ -1,6 +1,7 @@
package localmodels
import (
+ "bytes"
"context"
"encoding/json"
"errors"
@@ -335,6 +336,9 @@ func (m *ModelSource) Status(ctx context.Context) (wire.ModelSourceStatus, error
}
}
if exitCode != 0 {
+ if unsupported := unsupportedSourceCommand(exitCode, stdout); unsupported != nil {
+ return wire.ModelSourceStatus{}, unsupported
+ }
return wire.ModelSourceStatus{}, parseToolFailure(stdout, CodeToolFailed, "Could not read model source status on this Computer.")
}
return parseSourceStatus(stdout)
@@ -405,6 +409,9 @@ func (m *ModelSource) runEndpointCommand(ctx context.Context, input wire.ByokCon
Retryable: true,
}
}
+ if unsupported := unsupportedSourceCommand(exitCode, stdout); unsupported != nil {
+ return unsupported
+ }
var outcome struct {
Schema string `json:"schema"`
OK bool `json:"ok"`
@@ -506,6 +513,9 @@ func (m *ModelSource) Apply(ctx context.Context, apply ModelSourceApply) (wire.M
}
}
if exitCode != 0 {
+ if unsupported := unsupportedSourceCommand(exitCode, stdout); unsupported != nil {
+ return wire.ModelSourceStatus{}, unsupported
+ }
return wire.ModelSourceStatus{}, parseToolFailure(stdout, CodeToolFailed, "Could not switch model source on this Computer.")
}
status, err := parseSourceStatus(stdout)
@@ -624,6 +634,20 @@ func parseSourceStatus(stdout []byte) (wire.ModelSourceStatus, error) {
return status, nil
}
+// unsupportedSourceCommand detects a localmodels CLI without the source
+// subcommand, which exits with CLI usage status 2 and empty stdout whereas
+// structured source failures emit JSON on stdout.
+func unsupportedSourceCommand(exitCode int, stdout []byte) error {
+ if exitCode == 2 && len(bytes.TrimSpace(stdout)) == 0 {
+ return &ModelSourceError{
+ Code: CodeModelSourceUnsupported,
+ Message: "The localmodels tool on this Computer does not support model sources.",
+ Retryable: false,
+ }
+ }
+ return nil
+}
+
func parseToolFailure(stdout []byte, fallbackCode, fallbackMessage string) error {
var errDoc struct {
Code string `json:"code"`
diff --git a/apps/computer/local-daemon/internal/localmodels/source_test.go b/apps/computer/local-daemon/internal/localmodels/source_test.go
index ac1d3951..66602529 100644
--- a/apps/computer/local-daemon/internal/localmodels/source_test.go
+++ b/apps/computer/local-daemon/internal/localmodels/source_test.go
@@ -264,3 +264,46 @@ func TestAgentRuntimeModelPrefersTargetThenCatalogDefault(t *testing.T) {
})
}
}
+
+func TestModelSourceReportsUnsupportedWhenToolLacksSourceCommand(t *testing.T) {
+ ft := newFakeTool(t)
+ for _, verb := range []string{"status", "apply", "check", "models"} {
+ if err := os.WriteFile(filepath.Join(ft.state, "source-"+verb+".json"), nil, 0o600); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(ft.state, "source-"+verb+"-exit"), []byte("2"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ }
+ ms := NewModelSource(ModelSourceOptions{Tool: &ft.tool})
+
+ assertUnsupported := func(name string, err error) {
+ t.Helper()
+ var sourceErr *ModelSourceError
+ if !errors.As(err, &sourceErr) {
+ t.Fatalf("%s: expected *ModelSourceError, got %v", name, err)
+ }
+ if sourceErr.Code != CodeModelSourceUnsupported || sourceErr.Retryable {
+ t.Fatalf("%s: got %+v, want non-retryable %s", name, sourceErr, CodeModelSourceUnsupported)
+ }
+ }
+
+ _, err := ms.Status(t.Context())
+ assertUnsupported("Status", err)
+
+ _, err = ms.Apply(t.Context(), ModelSourceApply{Mode: "subscription", Runtime: "claude"})
+ assertUnsupported("Apply", err)
+
+ _, err = ms.TestByok(t.Context(), "claude", wire.ByokConfigInput{
+ BaseURL: "https://api.example.com/v1",
+ APIKey: "sk-unused",
+ ModelID: "gpt-5.4",
+ })
+ assertUnsupported("TestByok", err)
+
+ _, err = ms.ListByokModels(t.Context(), wire.ByokConfigInput{
+ BaseURL: "https://api.example.com/v1",
+ APIKey: "sk-unused",
+ })
+ assertUnsupported("ListByokModels", err)
+}
diff --git a/apps/computer/local-daemon/internal/localmodels/status.go b/apps/computer/local-daemon/internal/localmodels/status.go
index 1c55c3f3..4f340162 100644
--- a/apps/computer/local-daemon/internal/localmodels/status.go
+++ b/apps/computer/local-daemon/internal/localmodels/status.go
@@ -23,8 +23,9 @@ const (
// Unavailable reason codes of a LocalModelsSnapshot, and the refusal codes
// the Daemon adds to the tool's own.
const (
- CodeToolNotInstalled = "TOOL_NOT_INSTALLED"
- CodeToolFailed = "TOOL_FAILED"
+ CodeToolNotInstalled = "TOOL_NOT_INSTALLED"
+ CodeToolFailed = "TOOL_FAILED"
+ CodeModelSourceUnsupported = "MODEL_SOURCE_UNSUPPORTED"
)
// errorCodes is the tool's closed error set (LocalModelErrorCode).
diff --git a/apps/node-services/src/agent/executor/http/local-computer-http.ts b/apps/node-services/src/agent/executor/http/local-computer-http.ts
index 59e8d1b9..5831135e 100644
--- a/apps/node-services/src/agent/executor/http/local-computer-http.ts
+++ b/apps/node-services/src/agent/executor/http/local-computer-http.ts
@@ -528,6 +528,7 @@ const modelSourceRequestError = (error: unknown): Error => {
return new LocalComputerHttpError(400, error.code, error.message);
}
if (
+ error.code === "MODEL_SOURCE_UNSUPPORTED" ||
error.code === "RUNTIME_NOT_ENABLED" ||
error.code === "TOOL_NOT_INSTALLED"
) {
diff --git a/apps/node-services/tests/agent/executor/http/local-computer-model-source-http.test.ts b/apps/node-services/tests/agent/executor/http/local-computer-model-source-http.test.ts
index b2a1bda1..506ddaa9 100644
--- a/apps/node-services/tests/agent/executor/http/local-computer-model-source-http.test.ts
+++ b/apps/node-services/tests/agent/executor/http/local-computer-model-source-http.test.ts
@@ -230,4 +230,34 @@ describe("Agent Management model-source routes", () => {
});
expect((await offlineApp.request(basePath)).status).toBe(503);
});
+
+ it("maps MODEL_SOURCE_UNSUPPORTED from localmodels to HTTP 409", async () => {
+ const app = buildTestApp(async () => {
+ throw new LocalModelSourceError(
+ "MODEL_SOURCE_UNSUPPORTED",
+ "The localmodels tool on this Computer does not support model sources.",
+ false,
+ );
+ });
+
+ const getRes = await app.request(basePath);
+ expect(getRes.status).toBe(409);
+ expect(await getRes.json()).toEqual({
+ code: "MODEL_SOURCE_UNSUPPORTED",
+ message:
+ "The localmodels tool on this Computer does not support model sources.",
+ });
+
+ const postRes = await app.request(basePath, {
+ method: "POST",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({ mode: "subscription", runtime: "claude" }),
+ });
+ expect(postRes.status).toBe(409);
+ expect(await postRes.json()).toEqual({
+ code: "MODEL_SOURCE_UNSUPPORTED",
+ message:
+ "The localmodels tool on this Computer does not support model sources.",
+ });
+ });
});
diff --git a/apps/web/src/app/router.test.tsx b/apps/web/src/app/router.test.tsx
index 0f2f3fcd..fbabe055 100644
--- a/apps/web/src/app/router.test.tsx
+++ b/apps/web/src/app/router.test.tsx
@@ -124,6 +124,37 @@ describe("Web app route contract", () => {
it("opens every unified Document through one stable identity route", () => {
expect(routePaths()).toContain("documents/:documentId");
});
+
+ it("redirects legacy settings/local-models URLs to settings/models with query params", async () => {
+ const routes = createAppRoutes(
+ new QueryClient({ defaultOptions: { queries: { retry: false } } }),
+ createTestTeamHubRuntime(),
+ );
+ const matched = matchRoutes(routes, "/t/tenant-a/settings/local-models");
+ const route = matched?.at(-1)?.route;
+ expect(route?.path).toBe("local-models");
+ const loader = route?.loader as LoaderFunction;
+ let thrown: unknown;
+ try {
+ await loader({
+ context: new RouterContextProvider(),
+ params: { tenantId: "tenant-a" },
+ pattern: "/t/:tenantId/settings/local-models",
+ request: new Request(
+ "http://localhost/t/tenant-a/settings/local-models?computer=comp-1",
+ ),
+ url: new URL(
+ "http://localhost/t/tenant-a/settings/local-models?computer=comp-1",
+ ),
+ });
+ } catch (error) {
+ thrown = error;
+ }
+ expect(thrown).toBeInstanceOf(Response);
+ expect((thrown as Response).headers.get("Location")).toBe(
+ "/t/tenant-a/settings/models?computer=comp-1",
+ );
+ });
});
function routePaths() {
diff --git a/apps/web/src/app/router.tsx b/apps/web/src/app/router.tsx
index 0638bf11..f63fa5b9 100644
--- a/apps/web/src/app/router.tsx
+++ b/apps/web/src/app/router.tsx
@@ -685,6 +685,19 @@ function createSettingsRoute(): RouteObject {
);
}
+ function openModels({
+ params,
+ request,
+ }: {
+ params: { tenantId?: string };
+ request: Request;
+ }): never {
+ const tenantId = requireRoomRouteParam(params.tenantId, "Tenant");
+ throw redirect(
+ `/t/${tenantId}/settings/models${new URL(request.url).search}`,
+ );
+ }
+
return {
children: [
{ index: true, loader: openProfile },
@@ -717,6 +730,7 @@ function createSettingsRoute(): RouteObject {
}),
path: "models",
},
+ { loader: openModels, path: "local-models" },
{ loader: openProfile, path: "administration" },
],
ErrorBoundary: PanelRouteErrorSurface,
@@ -768,7 +782,7 @@ function NotFoundRoute({ inShell = false }: { inShell?: boolean }) {
void navigate(tenantId ? `/t/${tenantId}/rooms` : "/");
}}
>
- Open Message
+ Open Messages
</Button>
</main>
);
diff --git a/apps/web/src/app/teamhub-router.test.tsx b/apps/web/src/app/teamhub-router.test.tsx
index ce15d84b..12c06818 100644
--- a/apps/web/src/app/teamhub-router.test.tsx
+++ b/apps/web/src/app/teamhub-router.test.tsx
@@ -586,6 +586,21 @@ describe("TeamHub routes", () => {
screen.getByRole("heading", { name: "TeamHub unavailable" }),
).toBeVisible();
});
+
+ it("offers Open Messages on unknown Space paths", async () => {
+ const runtime = createTestTeamHubRuntime();
+ const queryClient = testQueryClient();
+ const router = createMemoryRouter(createAppRoutes(queryClient, runtime), {
+ initialEntries: ["/t/tenant-northstar/no-such-page"],
+ });
+
+ renderApp(queryClient, runtime, router);
+
+ expect(
+ await screen.findByRole("heading", { name: "Page not found" }),
+ ).toBeVisible();
+ expect(screen.getByRole("button", { name: "Open Messages" })).toBeVisible();
+ });
});
function renderApp(
diff --git a/apps/web/src/features/local-models/local-models-copy.ts b/apps/web/src/features/local-models/local-models-copy.ts
index 08b01b2a..8b19e115 100644
--- a/apps/web/src/features/local-models/local-models-copy.ts
+++ b/apps/web/src/features/local-models/local-models-copy.ts
@@ -235,6 +235,17 @@ export function modelSourceErrorCopy(code: string | undefined) {
: "Something went wrong. Try again.";
}
+/** Why reading a Computer's model source failed. */
+export function modelSourceReadErrorCopy(code: string | undefined) {
+ if (code === "MODEL_SOURCE_SERVICE_UNAVAILABLE") {
+ return modelSourceRefusals.MODEL_SOURCE_SERVICE_UNAVAILABLE;
+ }
+ if (code === "MODEL_SOURCE_UNCONFIRMED") {
+ return "The computer didn't answer in time. Try again.";
+ }
+ return "Couldn't read how Agents on this computer get their model. Try again.";
+}
+
export const modelSourceModeLabels: Record<Schemas["ModelSourceMode"], string> =
{ byok: "BYOK", local: "Local model", subscription: "Subscription" };
diff --git a/apps/web/src/features/local-models/local-models-page.test.tsx b/apps/web/src/features/local-models/local-models-page.test.tsx
index 0753a3e4..bc7403e9 100644
--- a/apps/web/src/features/local-models/local-models-page.test.tsx
+++ b/apps/web/src/features/local-models/local-models-page.test.tsx
@@ -1247,6 +1247,9 @@ describe("LocalModelsPage", () => {
expect(
screen.queryByRole("button", { name: "Details" }),
).not.toBeInTheDocument();
+ expect(
+ screen.queryByRole("button", { name: "Recheck memory" }),
+ ).not.toBeInTheDocument();
},
);
@@ -2707,4 +2710,19 @@ describe("Model source", () => {
screen.queryByRole("button", { name: "Recheck memory" }),
).not.toBeInTheDocument();
});
+
+ it("shows a readable error while keeping the library when reading model source fails", async () => {
+ const fixture = setup();
+ fixture.runtime.server.on("GET", modelSourcePath, () =>
+ teamHubErrorResponse(502, "MODEL_SOURCE_FAILED"),
+ );
+
+ await renderPage(fixture);
+ await findModels();
+
+ const alert = await screen.findByRole("alert");
+ expect(alert).toHaveTextContent(
+ "Couldn't read how Agents on this computer get their model. Try again.",
+ );
+ });
});
diff --git a/apps/web/src/features/local-models/local-models-page.tsx b/apps/web/src/features/local-models/local-models-page.tsx
index 77270204..8e0e8731 100644
--- a/apps/web/src/features/local-models/local-models-page.tsx
+++ b/apps/web/src/features/local-models/local-models-page.tsx
@@ -50,6 +50,7 @@ import {
actionErrorCopy,
libraryUnavailableCopy,
memoryGuidanceCopy,
+ modelSourceReadErrorCopy,
} from "./local-models-copy";
import {
actOnLocalComputerModel,
@@ -289,7 +290,9 @@ function ComputerModels({
}),
});
const canRecheck = Boolean(
- view && view.viewer_is_owner && view.computer.status === "online",
+ view?.available &&
+ view.viewer_is_owner &&
+ view.computer.status === "online",
);
const guidance = view?.available ? memoryGuidance(view) : null;
const subscriptionGuidanceCopy = guidance
@@ -351,6 +354,19 @@ function ComputerModels({
value={shownTab}
/>
) : null}
+ {source.isError &&
+ !switcher.failure &&
+ view?.computer.status !== "offline" ? (
+ <div className="mt-4">
+ <FormFeedback tone="danger">
+ {modelSourceReadErrorCopy(
+ source.error instanceof TeamHubError
+ ? source.error.code
+ : undefined,
+ )}
+ </FormFeedback>
+ </div>
+ ) : null}
{switcher.failure ? (
<div className="mt-4">
<FormFeedback tone="danger">{switcher.failure}</FormFeedback>
diff --git a/apps/web/src/features/local-models/local-models-rules.test.ts b/apps/web/src/features/local-models/local-models-rules.test.ts
index b3d8cf50..ed6ca2e2 100644
--- a/apps/web/src/features/local-models/local-models-rules.test.ts
+++ b/apps/web/src/features/local-models/local-models-rules.test.ts
@@ -31,6 +31,7 @@ import {
labView,
localModel,
macView,
+ memoryPool,
modelView,
} from "./local-models-test-support";
@@ -221,6 +222,60 @@ describe("local models rules", () => {
kind: "blocked_load",
otherBytes: gb(14),
});
+
+ const multiSpaceGpu = {
+ ...gpuPool(0, 96, [{ gb: 21, id: "loaded:Q4", name: "Loaded" }]),
+ used_bytes: gb(83),
+ };
+ const multiSpaceSystem = {
+ ...memoryPool("system", 400),
+ used_bytes: gb(340),
+ };
+ const gpuConstrainedWithBusyRam = labView({
+ models: [
+ modelView(
+ localModel({
+ id: "big-gpu:Q4",
+ memory_bytes: gb(40),
+ name: "Big GPU Model",
+ pool: "gpu:0",
+ }),
+ ),
+ ],
+ pools: [multiSpaceGpu, multiSpaceSystem],
+ });
+ expect(memoryGuidance(gpuConstrainedWithBusyRam)).toEqual({
+ freeBytes: gb(13),
+ gpu: true,
+ kind: "constrained_pool",
+ otherBytes: gb(62),
+ totalBytes: gb(96),
+ });
+
+ const cleanGpuBusyRam = labView({
+ models: [
+ modelView(
+ localModel({
+ fit: "system",
+ id: "ram-only:Q4",
+ memory_bytes: gb(80),
+ name: "System RAM Model",
+ pool: "system",
+ }),
+ ),
+ ],
+ pools: [
+ gpuPool(0, 96, [{ gb: 21, id: "loaded:Q4", name: "Loaded" }]),
+ multiSpaceSystem,
+ ],
+ });
+ expect(memoryGuidance(cleanGpuBusyRam)).toEqual({
+ freeBytes: gb(60),
+ gpu: false,
+ kind: "constrained_pool",
+ otherBytes: gb(340),
+ totalBytes: gb(400),
+ });
});
it("orders local switch targets with loaded models first, then recommended, then largest", () => {
diff --git a/apps/web/src/features/local-models/local-models-rules.ts b/apps/web/src/features/local-models/local-models-rules.ts
index 7972e58f..19bfc01c 100644
--- a/apps/web/src/features/local-models/local-models-rules.ts
+++ b/apps/web/src/features/local-models/local-models-rules.ts
@@ -148,20 +148,29 @@ export function poolReclaimableBytes(pool: LocalModelPool) {
return poolFreeBytes(pool) + poolOtherBytes(pool);
}
-/** What the header adds up: GPU memory when the Computer has GPUs, else its memory. */
-export function memorySummary(view: LocalModelsView) {
- const gpus = view.pools.filter((pool) => pool.kind === "gpu");
- const pools = gpus.length ? gpus : view.pools;
+function summarizePools(pools: readonly LocalModelPool[], gpu: boolean) {
const totalBytes = pools.reduce((sum, pool) => sum + pool.total_bytes, 0);
const usedBytes = pools.reduce((sum, pool) => sum + pool.used_bytes, 0);
+ const otherBytes = pools.reduce((sum, pool) => sum + poolOtherBytes(pool), 0);
return {
freeBytes: Math.max(0, totalBytes - usedBytes),
- gpu: gpus.length > 0,
+ gpu,
+ otherBytes,
totalBytes,
usedBytes,
};
}
+/** What the header adds up: GPU memory when the Computer has GPUs, else its memory. */
+export function memorySummary(view: LocalModelsView) {
+ const gpus = view.pools.filter((pool) => pool.kind === "gpu");
+ const { freeBytes, gpu, totalBytes, usedBytes } = summarizePools(
+ gpus.length ? gpus : view.pools,
+ gpus.length > 0,
+ );
+ return { freeBytes, gpu, totalBytes, usedBytes };
+}
+
export interface MemoryGuidance {
kind: "blocked_download" | "blocked_load" | "constrained_pool";
gpu: boolean;
@@ -201,85 +210,101 @@ export function memoryReclaimable(
) {
return false;
}
+ const gpus = view.pools.filter((pool) => pool.kind === "gpu");
+ const pools = gpus.length ? gpus : view.pools;
return (
- view.pools.some((pool) => poolOtherBytes(pool) > 0) &&
+ pools.some((pool) => poolOtherBytes(pool) > 0) &&
reason.need_bytes <= maxHardwareCapacity(view)
);
}
/**
* Whether external apps hold enough GPU or system memory that closing them
- * and rechecking could let a larger model download or load.
+ * and rechecking could let a larger model download or load. Pool metrics are
+ * scoped per physical memory space so system RAM is never added into GPU VRAM.
*/
export function memoryGuidance(view: LocalModelsView): MemoryGuidance | null {
if (!view.available || !view.pools.length) return null;
- const summary = memorySummary(view);
- const externalPools = view.pools
- .map((pool) => ({ external: poolOtherBytes(pool), pool }))
- .filter((item) => item.external > 0)
- .sort((left, right) => right.external - left.external);
- if (!externalPools.length) return null;
-
- const top = externalPools[0]!;
- const otherBytes = externalPools.reduce(
- (sum, item) => sum + item.external,
- 0,
- );
- const blockedLoad = modelEntries(view).some((entry) => {
- const { model, status } = entry;
- if (status !== "idle" && status !== "failed") return false;
- const pool = poolOf(view, model.pool);
- const poolHasExternal = pool ? poolOtherBytes(pool) > 0 : false;
- if (!poolHasExternal) return false;
- return (
- model.note?.code === "NO_ROOM_TO_LOAD" ||
- model.error?.code === "LOAD_NO_ROOM" ||
- model.error?.code === "OUT_OF_MEMORY" ||
- loadCheck(view, model) !== null
- );
- });
- if (blockedLoad) {
- return {
- freeBytes: summary.freeBytes,
- gpu: top.pool.kind === "gpu" || summary.gpu,
- kind: "blocked_load",
- otherBytes,
- totalBytes: summary.totalBytes,
- };
+ const gpus = view.pools.filter((pool) => pool.kind === "gpu");
+ const nonGpus = view.pools.filter((pool) => pool.kind !== "gpu");
+ const groups = [
+ ...(gpus.length ? [{ gpu: true, pools: gpus }] : []),
+ ...(nonGpus.length ? [{ gpu: false, pools: nonGpus }] : []),
+ ];
+ if (!groups.length) return null;
+
+ const entries = modelEntries(view);
+
+ for (const group of groups) {
+ const stats = summarizePools(group.pools, group.gpu);
+ if (stats.otherBytes <= 0) continue;
+ const poolIds = new Set(group.pools.map((pool) => pool.id));
+ const blockedLoad = entries.some(({ model, status }) => {
+ if (status !== "idle" && status !== "failed") return false;
+ if (model.pool === undefined || !poolIds.has(model.pool)) return false;
+ const pool = poolOf(view, model.pool);
+ if (!pool || poolOtherBytes(pool) <= 0) return false;
+ return (
+ model.note?.code === "NO_ROOM_TO_LOAD" ||
+ model.error?.code === "LOAD_NO_ROOM" ||
+ model.error?.code === "OUT_OF_MEMORY" ||
+ loadCheck(view, model) !== null
+ );
+ });
+ if (blockedLoad) {
+ return {
+ freeBytes: stats.freeBytes,
+ gpu: group.gpu,
+ kind: "blocked_load",
+ otherBytes: stats.otherBytes,
+ totalBytes: stats.totalBytes,
+ };
+ }
}
- const blockedDownload = modelEntries(view).some(
- (entry) =>
- entry.status === "unavailable" && memoryReclaimable(view, entry.model),
- );
- if (blockedDownload) {
+ const primary = groups[0]!;
+ const primaryStats = summarizePools(primary.pools, primary.gpu);
+ if (
+ primaryStats.otherBytes > 0 &&
+ entries.some(
+ (entry) =>
+ entry.status === "unavailable" && memoryReclaimable(view, entry.model),
+ )
+ ) {
return {
- freeBytes: summary.freeBytes,
- gpu: top.pool.kind === "gpu" || summary.gpu,
+ freeBytes: primaryStats.freeBytes,
+ gpu: primary.gpu,
kind: "blocked_download",
- otherBytes,
- totalBytes: summary.totalBytes,
+ otherBytes: primaryStats.otherBytes,
+ totalBytes: primaryStats.totalBytes,
};
}
- const constrainedAvailable = modelEntries(view).some((entry) => {
- if (entry.status !== "available") return false;
- const pool = poolOf(view, entry.model.pool);
- return (
- pool !== undefined &&
- poolOtherBytes(pool) > 0 &&
- entry.model.memory_bytes > poolFreeBytes(pool)
- );
- });
const twoGigabytes = 2 * 1024 ** 3;
- if (otherBytes >= twoGigabytes && constrainedAvailable) {
- return {
- freeBytes: summary.freeBytes,
- gpu: top.pool.kind === "gpu" || summary.gpu,
- kind: "constrained_pool",
- otherBytes,
- totalBytes: summary.totalBytes,
- };
+ for (const group of groups) {
+ const stats = summarizePools(group.pools, group.gpu);
+ if (stats.otherBytes < twoGigabytes) continue;
+ const poolIds = new Set(group.pools.map((pool) => pool.id));
+ const constrainedAvailable = entries.some((entry) => {
+ if (entry.status !== "available") return false;
+ const modelPool = entry.model.pool;
+ if (modelPool === undefined || !poolIds.has(modelPool)) return false;
+ const pool = poolOf(view, modelPool);
+ return (
+ pool !== undefined &&
+ poolOtherBytes(pool) > 0 &&
+ entry.model.memory_bytes > poolFreeBytes(pool)
+ );
+ });
+ if (constrainedAvailable) {
+ return {
+ freeBytes: stats.freeBytes,
+ gpu: group.gpu,
+ kind: "constrained_pool",
+ otherBytes: stats.otherBytes,
+ totalBytes: stats.totalBytes,
+ };
+ }
}
return null;
}
diff --git a/contracts/README.md b/contracts/README.md
index ce8f9b36..584926d5 100644
--- a/contracts/README.md
+++ b/contracts/README.md
@@ -131,8 +131,9 @@ Web → TeamHub → Agent Service → Computer → `localmodels source`:
`listLocalComputerByokModels` under
`/v1/tenants/{tenantId}/owners/{ownerActorId}/local-computers/{computerId}/model-source`.
3. Agent Service sends `execute` with kind `model_source` (`status`, `test`,
- `models` or `apply`), only to Computer 0.54.0 or later; an older one answers
- `MODEL_SOURCE_UNSUPPORTED` without the command. The Daemon runs
+ `models` or `apply`), only to Computer 0.54.0 or later; an older Computer,
+ or one whose installed `localmodels` tool lacks the `source` command, answers
+ `MODEL_SOURCE_UNSUPPORTED`. The Daemon runs
`localmodels source status|check|models|apply` and answers `executed`. A BYOK
API key travels in the request and the envelope only, reaches `localmodels`
on stdin, and is kept on the Computer in an owner-only file.