Skip to content

Commit 23b8195

Browse files
only21milclaude
andcommitted
fix(web): Auto balance says unavailable when every machine is too busy
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1d626d0 commit 23b8195

4 files changed

Lines changed: 30 additions & 14 deletions

File tree

‎apps/web/src/components/chat/composerSend.logic.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { threadContextReference } from "../../lib/composerContextRecords";
66
import { threadContextRecord } from "@t3tools/shared/composerContextReferences";
77
import {
88
approvalRedirectNotice,
9+
autoBalanceLabel,
910
loadBalancingSendWarning,
1011
multipleModelSendBlock,
1112
referencedThreadContexts,
@@ -25,6 +26,16 @@ describe("referencedThreadContexts", () => {
2526
});
2627
});
2728

29+
describe("autoBalanceLabel", () => {
30+
it.each([
31+
["stays neutral with no candidate machine", false, 0, null, "Auto balance"],
32+
["stays neutral once a machine is picked", false, 2, remote, "Auto balance"],
33+
["is unavailable when every candidate is too busy", false, 2, null, "Auto balance unavailable"],
34+
] as const)("%s", (_case, pending, candidateCount, environmentId, label) => {
35+
expect(autoBalanceLabel({ pending, candidateCount, environmentId })).toBe(label);
36+
});
37+
});
38+
2839
describe("loadBalancingSendWarning", () => {
2940
it("asks the user to wait while resource checks run", () => {
3041
expect(

‎apps/web/src/components/chat/composerSend.logic.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ export function referencedThreadContexts(draft: {
1111
return draft.threadContexts.filter((record) => referenced.has(record.contextId));
1212
}
1313

14+
/** Auto's label: unavailable once every checked candidate machine is too busy or failed. */
15+
export function autoBalanceLabel(input: {
16+
readonly pending: boolean;
17+
readonly candidateCount: number;
18+
readonly environmentId: EnvironmentId | null;
19+
}) {
20+
if (input.pending) return "Checking machines…";
21+
return input.candidateCount > 0 && input.environmentId === null
22+
? "Auto balance unavailable"
23+
: "Auto balance";
24+
}
25+
1426
/** Why a send waits for the user to pick a machine when no machine was chosen automatically. */
1527
export function loadBalancingSendWarning(input: {
1628
readonly pending: boolean;

‎apps/web/src/components/chat/useDraftEnvironmentRouting.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { scopeProjectRef } from "@t3tools/client-runtime/environment";
1313
import { useEffect, useLayoutEffect, useRef, useState } from "react";
1414
import { toastManager } from "../ui/toast";
15+
import { autoBalanceLabel } from "./composerSend.logic";
1516
import {
1617
deriveLogicalProjectKeyFromSettings,
1718
selectProjectGroupingSettings,
@@ -156,13 +157,11 @@ export function useDraftEnvironmentRouting(input: DraftEnvironmentRoutingInput)
156157
};
157158
const onAutoEnvironmentStable = useStableCallback(onAutoEnvironment);
158159
const autoEnvironmentLabel = automaticEnvironment
159-
? draftThread?.loadBalancedEnvironmentId
160-
? "Auto balance"
161-
: loadBalancing.pending
162-
? "Checking machines…"
163-
: loadBalancing.failed
164-
? "Auto balance unavailable"
165-
: "Auto balance"
160+
? autoBalanceLabel({
161+
pending: loadBalancing.pending,
162+
candidateCount: loadBalancingCandidates.length,
163+
environmentId: loadBalancing.environmentId,
164+
})
166165
: undefined;
167166

168167
// A change in flight belongs to the draft and project it started on.

‎apps/web/src/hooks/useLoadBalancedEnvironment.ts‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const hostResourcesAtom = Atom.family((environmentIdsKey: string) =>
2222
resources: result._tag === "Success" ? result.value : null,
2323
receivedAt: result._tag === "Success" ? result.timestamp : 0,
2424
pending: result._tag === "Initial" || result.waiting,
25-
failed: result._tag === "Failure",
2625
};
2726
});
2827
// Re-read when the next fresh snapshot ages out, so a frozen evaluatedAt never selects it.
@@ -59,10 +58,5 @@ export function useLoadBalancedEnvironment(
5958
})),
6059
evaluatedAt,
6160
) as EnvironmentId | null;
62-
return {
63-
refresh,
64-
pending,
65-
environmentId,
66-
failed: !pending && environmentId === null && resources.some((resource) => resource.failed),
67-
};
61+
return { refresh, pending, environmentId };
6862
}

0 commit comments

Comments
 (0)