Skip to content

"Vibe-Trading: Your Personal Trading Agent"

feat(frontend): order runtime connectors by status

alex13b5ac124724
diff --git a/frontend/src/pages/Runtime.tsx b/frontend/src/pages/Runtime.tsx
index 62322dc7f..977f74ade 100644
--- a/frontend/src/pages/Runtime.tsx
+++ b/frontend/src/pages/Runtime.tsx
@@ -81,6 +81,7 @@ export function Runtime() {
}, [loadStatus]);
const summary = useMemo(() => summarizeRuntime(status), [status]);
+ const sortedBrokers = useMemo(() => sortBrokersByStatus(status), [status]);
return (
<div className="min-h-screen p-6 lg:p-8">
@@ -161,7 +162,7 @@ export function Runtime() {
</section>
) : (
<section className="grid gap-4">
- {status.brokers.map((broker) => (
+ {sortedBrokers.map((broker) => (
<BrokerRuntimeCard
key={broker.auth.profile_id || broker.auth.broker}
broker={broker}
@@ -366,28 +367,39 @@ function SdkBrokerRuntimeCard({ broker, t, onRefresh }: { broker: LiveBrokerStat
);
}
+type ConnectorKind = "not_configured" | "ready" | "connected" | "error" | "unknown";
+
+function connectorKind(auth: LiveBrokerStatus["auth"]): ConnectorKind {
+ if (auth.connection_state === "connected") return "connected";
+ if (auth.connection_state === "not_configured" || auth.configured === false) return "not_configured";
+ if (auth.connection_state === "error") return "error";
+ if (auth.connection_state === "ready") return "ready";
+ return "unknown";
+}
+
function connectorState(auth: LiveBrokerStatus["auth"], t: TFunction): {
- kind: "not_configured" | "ready" | "connected" | "error" | "unknown";
+ kind: ConnectorKind;
label: string;
tone: "success" | "danger" | "warning" | "neutral";
action?: "runtime.verifyConnection" | "runtime.retry";
} {
- if (auth.connection_state === "connected") {
+ const kind = connectorKind(auth);
+ if (kind === "connected") {
if (isReadOnlyCompatible(auth)) {
- return { kind: "connected", label: t("runtime.connectedReadOnly"), tone: "success" };
+ return { kind, label: t("runtime.connectedReadOnly"), tone: "success" };
}
- return { kind: "connected", label: t("runtime.connectedAccessUnknown"), tone: "neutral" };
+ return { kind, label: t("runtime.connectedAccessUnknown"), tone: "neutral" };
}
- if (auth.connection_state === "not_configured" || auth.configured === false) {
- return { kind: "not_configured", label: t("runtime.notConfigured"), tone: "neutral" };
+ if (kind === "not_configured") {
+ return { kind, label: t("runtime.notConfigured"), tone: "neutral" };
}
- if (auth.connection_state === "error") {
- return { kind: "error", label: t("runtime.connectionFailed"), tone: "danger", action: "runtime.retry" };
+ if (kind === "error") {
+ return { kind, label: t("runtime.connectionFailed"), tone: "danger", action: "runtime.retry" };
}
- if (auth.connection_state === "ready") {
- return { kind: "ready", label: t("runtime.readyToVerify"), tone: "warning", action: "runtime.verifyConnection" };
+ if (kind === "ready") {
+ return { kind, label: t("runtime.readyToVerify"), tone: "warning", action: "runtime.verifyConnection" };
}
- return { kind: "unknown", label: t("runtime.connectorStatusUnavailable"), tone: "neutral" };
+ return { kind, label: t("runtime.connectorStatusUnavailable"), tone: "neutral" };
}
function connectorDiagnostic(errorCode: string | null | undefined, t: TFunction): string {
@@ -526,6 +538,27 @@ function summarizeRuntime(status: LiveStatus | null) {
};
}
+function connectorRank(broker: LiveBrokerStatus, globalHalted: boolean): number {
+ const auth = broker.auth;
+ if (auth.transport === "broker_sdk") {
+ const kind = connectorKind(auth);
+ if (kind === "connected") return 0;
+ if (kind === "error") return 1;
+ if (kind === "ready") return 2;
+ return auth.sdk_installed === true ? 3 : 4;
+ }
+ if (auth.oauth_token_present || broker.runner?.alive || broker.mandate) return 0;
+ // `halted` is true for every broker while the global kill switch is set, so a broker's
+ // own switch is only visible when the global one is clear.
+ return broker.halted && !globalHalted ? 1 : 4;
+}
+
+function sortBrokersByStatus(status: LiveStatus | null): LiveBrokerStatus[] {
+ const globalHalted = status?.global_halted ?? false;
+ // Stable sort: peers keep the backend's alphabetical order, so a refresh never reshuffles them.
+ return [...(status?.brokers || [])].sort((a, b) => connectorRank(a, globalHalted) - connectorRank(b, globalHalted));
+}
+
function deriveRiskState(broker: LiveBrokerStatus, globalHalted: boolean, t: TFunction): {
label: string;
tone: "success" | "danger" | "warning" | "neutral";
diff --git a/frontend/src/pages/__tests__/Runtime.test.tsx b/frontend/src/pages/__tests__/Runtime.test.tsx
index 1b146b1c1..9f0bdfe10 100644
--- a/frontend/src/pages/__tests__/Runtime.test.tsx
+++ b/frontend/src/pages/__tests__/Runtime.test.tsx
@@ -528,4 +528,96 @@ describe("Runtime page", () => {
expect(screen.queryByRole("button", { name: "Retry" })).not.toBeInTheDocument();
expect(apiMock.verifyConnector).not.toHaveBeenCalled();
});
+
+ describe("connector order", () => {
+ function broker(
+ name: string,
+ auth: Partial<LiveBrokerStatus["auth"]> = {},
+ extra: Partial<LiveBrokerStatus> = {},
+ ): LiveBrokerStatus {
+ return {
+ auth: { broker: name, oauth_token_present: false, is_live_broker: false, transport: "broker_sdk", ...auth },
+ runner: { broker: name, alive: false, last_tick: null, last_tick_age_seconds: null },
+ mandate: null,
+ halted: false,
+ ...extra,
+ };
+ }
+
+ async function renderedOrder(brokers: LiveBrokerStatus[], globalHalted = false): Promise<string[]> {
+ apiMock.getLiveStatus.mockResolvedValue(makeStatus({ global_halted: globalHalted, brokers }));
+ render(<Runtime />);
+ await screen.findByText("Live / Paper Runtime Status");
+ return screen.getAllByRole("heading", { level: 2 }).map((heading) => heading.textContent ?? "");
+ }
+
+ it("lists connected, then failed, then ready, then unconfigured SDK connectors", async () => {
+ const order = await renderedOrder([
+ broker("alpha", { connection_state: "not_configured" }),
+ broker("bravo", { connection_state: "ready" }),
+ broker("charlie", { connection_state: "error" }),
+ broker("delta", { connection_state: "connected" }),
+ ]);
+
+ expect(order).toEqual(["delta", "charlie", "bravo", "alpha"]);
+ });
+
+ it("ranks an SDK connector by the state its status pill shows", async () => {
+ const order = await renderedOrder([
+ broker("alpha", { connection_state: "error", configured: false }),
+ broker("bravo", { connection_state: "ready" }),
+ ]);
+
+ expect(order).toEqual(["bravo", "alpha"]);
+ });
+
+ it("ranks an OAuth broker with a token or a live runner ahead of unconnected SDK connectors", async () => {
+ const order = await renderedOrder([
+ broker("alpha", { sdk_installed: true }),
+ broker("ibkr", { transport: "local_tws" }),
+ broker("kraken", { transport: "remote_mcp" }, {
+ runner: { broker: "kraken", alive: true, last_tick: null, last_tick_age_seconds: null },
+ }),
+ broker("robinhood", { transport: "remote_mcp", oauth_token_present: true }),
+ ]);
+
+ expect(order).toEqual(["kraken", "robinhood", "alpha", "ibkr"]);
+ });
+
+ it("moves only an OAuth broker with its own kill switch, since SDK cards show no halt", async () => {
+ const order = await renderedOrder([
+ broker("alpha"),
+ broker("bravo", { transport: "remote_mcp" }, { halted: true }),
+ broker("charlie", { connection_state: "connected" }),
+ broker("delta", {}, { halted: true }),
+ ]);
+
+ expect(order).toEqual(["charlie", "bravo", "alpha", "delta"]);
+ });
+
+ it("keeps the same order under the global kill switch, which marks every broker halted", async () => {
+ const order = await renderedOrder(
+ [
+ broker("alpha"),
+ broker("bravo", { transport: "remote_mcp" }),
+ broker("charlie", { connection_state: "ready" }),
+ broker("delta", { connection_state: "connected" }),
+ ].map((item) => ({ ...item, halted: true })),
+ true,
+ );
+
+ expect(order).toEqual(["delta", "charlie", "alpha", "bravo"]);
+ });
+
+ it("puts unreported connectors with the SDK installed first and otherwise keeps the backend order", async () => {
+ const order = await renderedOrder([
+ broker("alpha", { sdk_installed: false }),
+ broker("bravo", { sdk_installed: true }),
+ broker("charlie", { sdk_installed: null }),
+ broker("delta", { sdk_installed: true }),
+ ]);
+
+ expect(order).toEqual(["bravo", "delta", "alpha", "charlie"]);
+ });
+ });
});