Compare commits

...
Author SHA1 Message Date
jialinandjialin 29b965ebbd style(cluster): center pool replicas cell
CI / deps (push) Has been cancelled
CI / build (push) Has been cancelled
CI / build-publish (push) Has been cancelled
CI / trigger-backend (push) Has been cancelled
2026-07-23 20:49:23 +08:00
jialinandjialin aca6490da1 fix(llmodels): stale instances lingering after missed DELETE watch events 2026-07-23 15:53:21 +08:00
jialinandjialin 04511a63a3 fix(models): cluster auto-selection mismatch when org scope settles late 2026-07-23 15:33:42 +08:00
jialinandjialin 28da5d52e8 style(cluster): col width 2026-07-22 16:29:04 +08:00
7 changed files with 97 additions and 29 deletions
+28 -14
View File
@@ -8,24 +8,38 @@ const findValidJSONStrings = (inputStr: string) => {
const openingBraceIndex = inputStr.indexOf('{', startIndex);
if (openingBraceIndex === -1) break; // No more opening braces
let closingBraceIndex = openingBraceIndex;
// find the matching closing brace, ignoring braces inside string
// literals (e.g. a state_message containing `{`/`}`)
let closingBraceIndex = -1;
let braceCount = 0;
let inString = false;
let escaped = false;
// find couple of braces
while (closingBraceIndex < inputStr.length) {
if (inputStr[closingBraceIndex] === '{') {
for (let i = openingBraceIndex; i < inputStr.length; i++) {
const char = inputStr[i];
if (inString) {
if (escaped) {
escaped = false;
} else if (char === '\\') {
escaped = true;
} else if (char === '"') {
inString = false;
}
} else if (char === '"') {
inString = true;
} else if (char === '{') {
braceCount++;
} else if (inputStr[closingBraceIndex] === '}') {
} else if (char === '}') {
braceCount--;
if (braceCount === 0) {
closingBraceIndex = i;
break;
}
}
if (braceCount === 0) {
break;
}
closingBraceIndex++;
}
if (braceCount !== 0) {
// no matching closing brace
if (closingBraceIndex === -1) {
// no matching closing brace yet, wait for more data
break;
}
@@ -37,11 +51,11 @@ const findValidJSONStrings = (inputStr: string) => {
try {
const parsedData = JSON.parse(jsonString);
validJSONStrings.push(parsedData);
startIndex = closingBraceIndex + 1;
} catch (error) {
// mabye invalid JSON
break;
// skip the malformed segment instead of breaking, otherwise it jams
// the buffer and every later event on this stream is lost
}
startIndex = closingBraceIndex + 1;
}
return {
+4 -1
View File
@@ -43,8 +43,11 @@ export const createAxiosToken = (): CancelTokenSource => {
};
export const sliceData = (data: string, loaded: number, loadedSize: any) => {
// `loaded` is a byte count while `data` is a UTF-16 string; with any
// non-ASCII payload the two drift apart, so track consumed characters by
// string length only
const result = data.slice(loadedSize.current);
loadedSize.current = loaded;
loadedSize.current = data.length;
return result;
};
@@ -163,7 +163,11 @@ const PoolRows: React.FC<PoolRowsProps> = ({
key={col.dataIndex || col.key}
span={spanFor(col.dataIndex)}
style={{
color: 'var(--ant-color-text-secondary)'
color: 'var(--ant-color-text-secondary)',
// CellContent shrinks to its content inside the flex
// cell, so its own align class can't center it —
// center at the cell level instead.
justifyContent: col.align
}}
>
<CellContent
@@ -153,7 +153,7 @@ const useClusterColumns = (
span: 3,
render: (text: string, record: ClusterListItem) => (
<>
<AutoTooltip ghost title={text}>
<AutoTooltip ghost title={text} minWidth={20}>
<span className="text-primary">{record.name}</span>
</AutoTooltip>
{record.is_default && (
@@ -186,23 +186,24 @@ const useClusterColumns = (
{
title: intl.formatMessage({ id: 'dashboard.totalgpus' }),
dataIndex: 'gpus',
span: 2,
sorter: tableSorter(3),
width: 100,
sorter: tableSorter(3),
render: (value: number) => <span>{value}</span>
},
{
title: intl.formatMessage({ id: 'clusters.table.deployments' }),
dataIndex: 'models',
sorter: tableSorter(4),
width: 100,
span: spans.deployments,
maxWidth: 150,
render: (value: number) => <span>{value}</span>
},
{
title: intl.formatMessage({ id: 'resources.nodes' }),
dataIndex: 'workers',
minWidth: 100,
maxWidth: 120,
sorter: tableSorter(5),
width: 100,
render: (value: number, record: ClusterListItem) => (
<span>
{record.ready_workers} / {record.workers}
@@ -213,6 +214,7 @@ const useClusterColumns = (
title: intl.formatMessage({ id: 'common.table.status' }),
dataIndex: 'state',
span: spans.status,
minWidth: 80,
align: 'center',
render: (value: number, record: ClusterListItem) => (
<StatusTag
@@ -116,6 +116,7 @@ const usePoolsColumns = (
dataIndex: 'replicas',
span: 6,
key: 'replicas',
align: 'center',
editable: {
valueType: 'number',
title: intl.formatMessage({ id: 'models.table.replicas.edit' })
+21 -1
View File
@@ -248,7 +248,13 @@ const Models = forwardRef((props, ref) => {
chunkInstanceRequedtRef.current = setModelInstanceChunkRequest({
url: `${MODEL_INSTANCE_API}`,
params: {},
handler: updateInstanceHandler
handler: updateInstanceHandler,
beforeReconnect() {
// treat the reconnect snapshot as the new baseline, otherwise
// instances deleted while the stream was down linger in the cache
// (their DELETE events are never re-sent)
cacheInsDataListRef.current = [];
}
});
} catch (error) {
// ignore
@@ -452,6 +458,20 @@ const Models = forwardRef((props, ref) => {
};
}, []);
// watch events can still be lost (stream hiccup, reconnect gap); a low
// frequency relist keeps the instance cache eventually consistent, so a
// missed DELETE event can't leave a stale instance behind for good
useEffect(() => {
const timer = setInterval(() => {
if (!isPageHidden.current) {
getAllModelInstances();
}
}, 60 * 1000);
return () => {
clearInterval(timer);
};
}, []);
const setDisableExpand = useMemoizedFn((record: any) => {
return !record?.replicas;
});
+31 -7
View File
@@ -153,26 +153,50 @@ const BasicForm: React.FC<BasicFormProps> = (props) => {
// Use the seed callback (not handleClusterChange) so this auto-pick refreshes
// options without firing an evaluate request before a model is selected.
useEffect(() => {
if (!clusterOptions?.length) {
// Options derive from clusterList: an empty source list means clusters
// are still loading — leave the field alone until they arrive.
if (!clusterList?.length) {
return;
}
// Scope off the live form value, not the `useWatch` snapshot: the scope
// field's default lands in a child effect that flushes before this one,
// while the watch still reports the previous render's null — scoping off
// the watch would seed a cluster from the unscoped list here and only
// re-scope a render later.
const liveScopeOrgId = form.getFieldValue('organization_id') ?? null;
const scoped = clusterList.filter(
(item) =>
liveScopeOrgId == null || item.owner_principal_id === liveScopeOrgId
);
const current = form.getFieldValue('cluster_id');
const stillValid = clusterOptions.some((c) => c.value === current);
if (!scoped.length) {
// Clusters are loaded but the picked org owns none. Any leftover
// selection points at another org's cluster (seeded before the scope
// settled) and would make requests fail with "Cluster not found" —
// clear it so the required rule surfaces instead. Create only: an
// edit's cluster is existing data, not a seed.
if (action === PageAction.CREATE && current != null) {
form.setFieldValue('cluster_id', undefined);
}
return;
}
const stillValid = scoped.some((c) => c.value === current);
if (current != null && stillValid) {
return;
}
const next =
clusterOptions.find((c) => c.is_default)?.value ??
clusterOptions.find((c) => c.state === ClusterStatusValueMap.Ready)
?.value ??
clusterOptions[0]?.value ??
scoped.find((c) => c.is_default)?.value ??
scoped.find((c) => c.state === ClusterStatusValueMap.Ready)?.value ??
scoped[0]?.value ??
null;
if (next == null || next === current) {
return;
}
form.setFieldValue('cluster_id', next);
onClusterSeed?.(next);
}, [clusterOptions, form, onClusterSeed]);
// `clusterOptions` is the re-run trigger for scope changes: it recomputes
// whenever the watched org scope or the cluster list settles.
}, [clusterOptions, clusterList, action, form, onClusterSeed]);
const clusterOptionRender = (option: any) => {
const { data } = option;