Skip to content

Conversation

@kaspersv
Copy link
Contributor

This PR modifies the init action to perform full analysis instead of overlay analysis if CodeQL will have less than 5GB of memory available for analysis. All non-slim GitHub hosted runners for public and private repos have +7GB of memory and the action will assign more than 5GB of memory to CodeQL on all such runners unless a lower memory limit has been manually specified. The limit is primarily intended to target self-hosted runners with little memory available for CodeQL as we have seen out-of-memory errors on self-hosted runners where CodeQL has only been given 3GB of memory for analysis.

Risk assessment

For internal use only. Please select the risk level of this change:

  • Low risk: Changes are fully under feature flags, or have been fully tested and validated in pre-production environments and are highly observable, or are documentation or test only.

Which use cases does this change impact?

Workflow types:

  • Advanced setup - Impacts users who have custom CodeQL workflows.
  • Managed - Impacts users with dynamic workflows (Default Setup, CCR, ...).

Products:

  • Code Scanning - The changes impact analyses when analysis-kinds: code-scanning.
  • Code Quality - The changes impact analyses when analysis-kinds: code-quality.

Environments:

  • Dotcom - Impacts CodeQL workflows on github.com.

How did/will you validate this change?

  • Test repository - This change will be tested on a test repository before merging.
  • Unit tests - I am depending on unit test coverage (i.e. tests in .test.ts files).

If something goes wrong after this change is released, what are the mitigation and rollback strategies?

  • Feature flags - All new or changed code paths can be fully disabled with corresponding feature flags.
  • Rollback - Change can only be disabled by rolling back the release or releasing a new version with a fix.

How will you know if something goes wrong after this change is released?

  • Telemetry - I rely on existing telemetry or have made changes to the telemetry.
    • Dashboards - I will watch relevant dashboards for issues after the release. Consider whether this requires this change to be released at a particular time rather than as part of a regular release.
    • Alerts - New or existing monitors will trip if something goes wrong with this change.

Are there any special considerations for merging or releasing this change?

  • No special considerations - This change can be merged at any time.
  • Special considerations - This change should only be merged once certain preconditions are met. Please provide details of those or link to this PR from an internal issue.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Consider adding a changelog entry for this change.
  • Confirm the readme and docs have been updated if necessary.

@github-actions github-actions bot added the size/S Should be easy to review label Nov 27, 2025
@kaspersv kaspersv force-pushed the kaspersv/overlay-memory-limit branch from 60d714b to bd8d26b Compare November 27, 2025 08:16
@kaspersv kaspersv marked this pull request as ready for review November 27, 2025 09:10
@kaspersv kaspersv requested a review from a team as a code owner November 27, 2025 09:10
Copilot AI review requested due to automatic review settings November 27, 2025 09:10
Copilot finished reviewing on behalf of kaspersv November 27, 2025 09:13
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 adds a memory check to the overlay analysis decision logic, falling back to full analysis when CodeQL has less than 5GB of memory available. This primarily targets self-hosted runners with limited memory to prevent out-of-memory errors during analysis.

Key Changes:

  • Added memory threshold check (5GB) alongside existing disk space check for overlay analysis
  • Memory check only applies when overlay analysis is feature-enabled, not when manually controlled via environment variable
  • Proper test coverage for both pull request and default branch scenarios with low memory

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/init-action.ts Passes ramInput parameter to config initialization
src/config-utils.ts Implements memory check (< 5GB) to disable overlay analysis, refactors if-else chain to handle memory constraint alongside disk space constraint
src/config-utils.test.ts Adds test cases for low memory scenarios on both PR and default branch, updates test infrastructure to stub getMemoryFlagValue

@kaspersv kaspersv requested a review from mbg November 27, 2025 09:44
Copy link
Member

@mbg mbg left a comment

Choose a reason for hiding this comment

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

Looks good to me. I added a few minor, non-blocking comments.

)
) {
const diskUsage = await checkDiskUsage(logger);
const memoryFlagValue = getMemoryFlagValue(ramInput, logger);
Copy link
Member

Choose a reason for hiding this comment

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

Minor: I wonder if it would make sense to rename getMemoryFlagValue since the result is now used for something other than the "memory flag".

"with caching because we are analyzing the default branch.",
);
}
} else if (memoryFlagValue < 5 * 1024) {
Copy link
Member

Choose a reason for hiding this comment

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

It might be good to turn 5 * 1024 into a constant (e.g. OVERLAY_MINIMUM_AVAILABLE_MEMORY_BYTES) for clarity and consistency.

Comment on lines +714 to +715
overlayDatabaseMode = OverlayDatabaseMode.None;
useOverlayDatabaseCaching = false;
Copy link
Member

Choose a reason for hiding this comment

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

This pattern of disabling overlay mode is now duplicated in a lot and might be worth de-duplicating. I think you might be doing that in #3333 already.

@kaspersv
Copy link
Contributor Author

Agreed. Will address comments in a follow up.

@kaspersv kaspersv merged commit c178e03 into main Nov 27, 2025
479 checks passed
@kaspersv kaspersv deleted the kaspersv/overlay-memory-limit branch November 27, 2025 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Should be easy to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants