Environment:on_stop job fails because reference is not a tree

Summary

I have an environment on_stop job that always fail because it is not able to check out the code, since I have remove branch selected when merging.

The error is:

Cloning repository...
Cloning into '/builds/rpadovani/rpadovani.com'...
Checking out 3ac9f991 as feature/aws-s3-gitlab-ci...
fatal: reference is not a tree: 3ac9f991ae3cee4d6e12d33e0138f4e631daec80
ERROR: Job failed: exit code 1

Steps to reproduce

Create a GitLab CI job to clean up an environment after a branch is merged/deleted:

deploys3:
  {..}
  environment:
    name: ${CI_COMMIT_REF_SLUG}
    on_stop: clean_s3

clean_s3:
  environment:
    name: ${CI_COMMIT_REF_SLUG}
    action: stop
  when: manual

When you merge a branch, and select Remove source branch, you will have this error:

Cloning repository...
Cloning into '/builds/rpadovani/rpadovani.com'...
Checking out 3ac9f991 as feature/aws-s3-gitlab-ci...
fatal: reference is not a tree: 3ac9f991ae3cee4d6e12d33e0138f4e631daec80
ERROR: Job failed: exit code 1

Example Project

https://gitlab.com/rpadovani/rpadovani.com

https://gitlab.com/rpadovani/rpadovani.com/-/jobs/64469957

What is the current bug behavior?

The clean job fails because it tries to checkout in a non more existing commit, since the branch has been deleted

What is the expected correct behavior?

The job works nonetheless - maybe it delays the branch deletion, or it doesn't try to check it out

Relevant logs and/or screenshots

Cloning repository...
Cloning into '/builds/rpadovani/rpadovani.com'...
Checking out 3ac9f991 as feature/aws-s3-gitlab-ci...
fatal: reference is not a tree: 3ac9f991ae3cee4d6e12d33e0138f4e631daec80
ERROR: Job failed: exit code 1

Output of checks

This bug happens on GitLab.com