Skip to content

Conversation

@yomybaby
Copy link
Member

@yomybaby yomybaby commented Nov 14, 2025

Resolves (FR-1681)

Summary

Implement automatic shared memory (shmem) calculation in the startSessionWithDefault function to ensure consistency with UI-based session creation.

Changes

  • Added automatic shmem calculation logic in useStartSession.tsx
  • When enabledAutomaticShmem is enabled and memory is allocated:
    • If memory ≥ 4GB → shmem = 1GB
    • If memory < 4GB → shmem = 64MB (default)
  • Imports AUTOMATIC_DEFAULT_SHMEM constant and compareNumberWithUnits helper

Background

Previously, the ResourceAllocationFormItems component had automatic shmem calculation logic, but programmatic session creation through useStartSession hook did not apply the same logic. This created inconsistency between UI-based and programmatic session creation, potentially leading to suboptimal resource allocation.

Test Plan

  • Verify shmem is automatically set to 1GB when memory ≥ 4GB
  • Verify shmem is automatically set to 64MB when memory < 4GB
  • Confirm consistency with ResourceAllocationFormItems behavior

@github-actions github-actions bot added the size:S 10~30 LoC label Nov 14, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • flow:merge-queue - adds this PR to the back of the merge queue
  • flow:hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has required the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions
Copy link

github-actions bot commented Nov 14, 2025

Coverage report for ./react

St.
Category Percentage Covered / Total
🔴 Statements
4.69% (+0% 🔼)
547/11669
🔴 Branches
3.82% (+0% 🔼)
314/8221
🔴 Functions
2.91% (-0% 🔻)
104/3577
🔴 Lines
4.64% (+0% 🔼)
529/11410
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🔴
... / ImportAndRunPage.tsx
0% 100% 0% 0%

Test suite run success

125 tests passing in 14 suites.

Report generated by 🧪jest coverage report action from a627ebb

@yomybaby yomybaby requested a review from ironAiken2 November 14, 2025 10:41
@yomybaby yomybaby marked this pull request as ready for review November 14, 2025 10:41
Copilot AI review requested due to automatic review settings November 14, 2025 10:41
Copilot finished reviewing on behalf of yomybaby November 14, 2025 10:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements automatic shared memory (shmem) calculation in the startSessionWithDefault function to ensure consistency with UI-based session creation.

Key Changes:

  • Added automatic shmem calculation logic that sets shmem to 1GB when memory ≥ 4GB, otherwise 64MB
  • Imports AUTOMATIC_DEFAULT_SHMEM constant and compareNumberWithUnits helper function
  • Logic is applied when enabledAutomaticShmem flag is enabled and memory is allocated

Comment on lines 152 to 163
// 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;
}
}
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.
@yomybaby yomybaby requested a review from agatha197 November 18, 2025 09:43
Copy link
Contributor

@agatha197 agatha197 left a comment

Choose a reason for hiding this comment

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

please check copilot's reviews.

@yomybaby yomybaby marked this pull request as draft November 19, 2025 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10~30 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants