Skip to content

Commit 512a7e8

Browse files
committed
fix(FR-2815): add 'use memo' to ResourceAllocationFormItems and useResourceLimitAndRemaining
Resolves #7248(FR-2815) Hypothesis: /session/start throws 'Maximum update depth exceeded' on backend rc2 (10.122.10.97) but not on main (10.122.10.107). The most plausible root cause is an unstable-identity feedback loop in ResourceAllocationFormItems: acceleratorSlotsInRG is built via _.omitBy on every render, feeding supportedAcceleratorTypesInRGByImage (useMemo) which becomes the dep of an effect that calls form.setFieldsValue when length === 0. Each setFieldsValue renders, recomputes acceleratorSlotsInRG with new identity, fires the effect again. useResourceLimitAndRemaining has the same identity-instability amplifying through resourceLimits and allocatablePresetNames. Why only on rc2: the rc2 server response likely trips the length === 0 branch on every render (different image accelerator metadata); on main the branch is not taken so the instability is harmless. Fix: add 'use memo' to both files per .claude/rules/react-compiler-memoization.md. The React Compiler (annotation mode) then memoizes the derived values based on their actual inputs, breaking the feedback loop. Verification: Relay/Lint/Format PASS. TypeScript: pre-existing failures only. Needs verification on the test server.
1 parent 00572ee commit 512a7e8

2 files changed

Lines changed: 2 additions & 0 deletions

File tree

react/src/components/SessionFormItems/ResourceAllocationFormItems.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ const ResourceAllocationFormItems: React.FC<
104104
hideClusterFormItems = false,
105105
extraAcceleratorRules,
106106
}) => {
107+
'use memo';
107108
const form = Form.useFormInstance<MergedResourceAllocationFormValue>();
108109
const { t } = useTranslation();
109110
const { token } = theme.useToken();

react/src/hooks/useResourceLimitAndRemaining.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export const useResourceLimitAndRemaining = ({
116116
ignorePerContainerConfig = false,
117117
fetchKey,
118118
}: Props) => {
119+
'use memo';
119120
const baiClient = useSuspendedBackendaiClient();
120121
const [resourceSlots] = useResourceSlots();
121122
const acceleratorSlots = _.omit(resourceSlots, ['cpu', 'mem', 'shmem']);

0 commit comments

Comments
 (0)