Skip to content

Delete CLI output-cache file during init - #4097

Closed
mario-campos wants to merge 1 commit into
mainfrom
mario-campos/delete-cache-file
Closed

Delete CLI output-cache file during init#4097
mario-campos wants to merge 1 commit into
mainfrom
mario-campos/delete-cache-file

Conversation

@mario-campos

Copy link
Copy Markdown
Contributor

The CLI output-cache file, which was introduced in #4081, is not meant to be used between runs—only steps. On non-ephemeral (i.e. self-hosted) runners, if the temp directories are not cleared between runs, the Action may load a previous ("stale") cache file, which may lead to unexpected results if the CLI has changed.

To prevent that from happening, with this PR, the Action will proactively delete the cache file at the expected location early in the init step, if one exists.

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, Code Quality, ...).

Products:

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

Environments:

  • Dotcom - Impacts CodeQL workflows on github.com and/or GitHub Enterprise Cloud with Data Residency.
  • GHES - Impacts CodeQL workflows on GitHub Enterprise Server.

How did/will you validate this change?

  • Test repository - This change will be tested on a test repository before merging.

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

  • 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.
    • 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.

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.

@mario-campos
mario-campos requested a review from mbg August 14, 2026 04:42
@mario-campos
mario-campos requested a review from a team as a code owner August 14, 2026 04:42
Copilot AI balanced review requested due to automatic review settings August 14, 2026 04:42
@github-actions github-actions Bot added the size/XS Should be very easy to review label Aug 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

  • Copilot's review of this pull request may be incomplete because some of the changed files are excluded by your Copilot content exclusion settings. See Excluding content from Copilot for details.

Pull request overview

Prevents stale CodeQL CLI output caches from persisting across runs on self-hosted runners.

Changes:

  • Exports the command-cache path helper.
  • Deletes the cache during initialization.
  • Updates generated JavaScript.
Show a summary per file
File Description
src/init-action.ts Adds cache deletion during initialization.
src/cli/output-cache.ts Exports the cache-path helper.
lib/entry-points.js Generated artifact; excluded from review.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Files excluded by content exclusion policy (1)
  • lib/entry-points.js
  • Files reviewed: 2/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread src/init-action.ts
Comment on lines +300 to +303
// Delete the CLI output-cache file if it exists, to avoid
// accidentally reusing a stale version from a previous run.
try {
fs.unlinkSync(getCommandCacheFilePath(actionState.env));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is true.

@mbg mbg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copilot raised a valid point, but there is also another big issue with the approach here:

The init Action is not necessarily the first to run. We also have start-proxy (in Default Setup), setup-codeql, and upload-sarif. In theory, any of them might be exposed to a stale cache file. While not all of these may use the CLI commands that we are currently/planning to cache, it would be easy to shoot ourselves in the foot in the future by only deleting the file in init. In general, we don't know which action comes first (while there is some logic to try and inspect the workflow file, that's just a best-effort implementation and doesn't cover all cases).

I think a potentially more straight-forward solution is to take advantage of my recent change to the Job UUID generation. The Job UUID is expected to be the same for a given job and the new logic in getJobUUID ensures that we either generate one if there isn't one already, or use the existing one that we generated for the workflow job.

I think a straight-forward solution to the problem here is therefore to store that UUID in the output cache file and compare it to the current job UUID when loading the output cache from disk. If they don't match, discard the content from the output cache and delete the file.

Comment thread src/init-action.ts
Comment on lines +300 to +303
// Delete the CLI output-cache file if it exists, to avoid
// accidentally reusing a stale version from a previous run.
try {
fs.unlinkSync(getCommandCacheFilePath(actionState.env));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is true.

@mario-campos

Copy link
Copy Markdown
Contributor Author

Yup, makes sense! I'll go with the UUID then.

@mario-campos
mario-campos deleted the mario-campos/delete-cache-file branch August 14, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Should be very easy to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants