Latest artifact download link often does not work for manually triggered jobs

Summary

Link to download latest artifacts from job (https://gitlab.com/gitlab-org/gitlab-ce/-/jobs/artifacts/master/download?job=coverage) often does not work for manually triggered jobs. It works only when manually triggered job is really launched in last pipeline. It should return artifacts from last run of manually triggered job, not from last pipeline. Manually triggered job was probably not launched in last pipeline.

Steps to reproduce

  1. Launch pipeline and run manually triggered job
  2. Link to download last artifacts from manually triggered job works as expected
  3. Launch another pipeline and do NOT run manually triggered job
  4. Link to download last artifacts from manually triggered job does NOT work

Example Project

snapshot-database:
  when: manual
  stage: deploy
  script: - ******
  artifacts:
    paths:
    - database.sql
    expire_in: 1 week

What is the current bug behavior?

Link to download last artifacts from manually triggered job sometimes does NOT work

What is the expected correct behavior?

Link to download last artifacts from manually triggered job always works

Possible fixes

Do not query artifacts from last pipeline, but return artifacts from last pipeline where the manually triggered job was actually launched.