Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion react/src/hooks/useStartSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { useTranslation } from 'react-i18next';
import { fetchQuery, graphql, useRelayEnvironment } from 'react-relay';
import { useStartSessionCreationQuery } from 'src/__generated__/useStartSessionCreationQuery.graphql';
import { transformPortValuesToNumbers } from 'src/components/PortSelectFormItem';
import { RESOURCE_ALLOCATION_INITIAL_FORM_VALUES } from 'src/components/SessionFormItems/ResourceAllocationFormItems';
import {
RESOURCE_ALLOCATION_INITIAL_FORM_VALUES,
AUTOMATIC_DEFAULT_SHMEM,
} from 'src/components/SessionFormItems/ResourceAllocationFormItems';
import { compareNumberWithUnits } from 'src/helper';
import {
SessionLauncherFormValue,
SessionResources,
Expand Down Expand Up @@ -144,6 +148,20 @@ export const useStartSession = () => {
minimumValues: StartSessionWithDefaultValue,
) => {
const mergedValue = _.merge({}, defaultFormValues, minimumValues);

// Apply automatic shmem calculation if enabledAutomaticShmem is true
if (mergedValue.enabledAutomaticShmem && mergedValue.resource?.mem) {
const mem = mergedValue.resource.mem;

// Apply the same logic as ResourceAllocationFormItems
// If mem > 4G, set shmem to 1G, otherwise use AUTOMATIC_DEFAULT_SHMEM (64m)
if (compareNumberWithUnits(mem, '4g') >= 0) {
mergedValue.resource.shmem = '1g';
} else {
mergedValue.resource.shmem = AUTOMATIC_DEFAULT_SHMEM;
}
}
Comment on lines 152 to 163
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The automatic shmem calculation logic is inconsistent with the original implementation in ResourceAllocationFormItems.tsx.

Issues:

  1. The runShmemAutomationRule function in ResourceAllocationFormItems.tsx expects M_plus_S (Memory + Shared Memory combined), but this implementation only uses mem (Memory alone)
  2. Missing validation: The original logic checks if M+S > M+1G to ensure there's enough memory to allocate 1GB for shmem
  3. Missing check: The original verifies compareNumberWithUnits('1g', AUTOMATIC_DEFAULT_SHMEM) > 0 to avoid downgrading shmem

Recommended fix:

// Apply automatic shmem calculation if enabledAutomaticShmem is true
if (mergedValue.enabledAutomaticShmem && mergedValue.resource?.mem) {
  const mem = mergedValue.resource.mem;
  const currentShmem = mergedValue.resource.shmem || AUTOMATIC_DEFAULT_SHMEM;
  const M_plus_S = addNumberWithUnits(mem, currentShmem, 'g') || '0g';

  // Apply the same logic as ResourceAllocationFormItems
  if (
    compareNumberWithUnits(M_plus_S, '4g') >= 0 &&
    compareNumberWithUnits(M_plus_S, addNumberWithUnits(mem, '1g') || '0b') >= 0 &&
    compareNumberWithUnits('1g', AUTOMATIC_DEFAULT_SHMEM) > 0
  ) {
    mergedValue.resource.shmem = '1g';
  } else {
    mergedValue.resource.shmem = AUTOMATIC_DEFAULT_SHMEM;
  }
}

Note: You'll also need to import addNumberWithUnits from the helper module.

Copilot uses AI. Check for mistakes.

return startSession(mergedValue as SessionLauncherFormValue);
};
const startSession = async (values: SessionLauncherFormValue) => {
Expand Down
Loading