Different build target behavior with --force-remote

In a CI build with a github self-hosted runner, I was using

pio remote run --force-remote -t clean -t upload

Which worked fine - the firmware was cleaned, built and uploaded. However, because environment variables are not propagated, I had to switch to a local build, without --force-remote.

When I did this, the behavior changed. Instead of building the firmware, it performed the clean operation twice, and then attempted to upload a non-existent .elf file.

Here’s the logs

Building project locally
Processing bw_swan_r5 (platform: ststm32; board: bw_swan_r5; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
Removing .pio/build/bw_swan_r5
Done cleaning
========================= [SUCCESS] Took 0.40 seconds =========================
Uploading firmware remotely
Processing bw_swan_r5 (platform: ststm32; board: bw_swan_r5; framework: arduino)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
Removing .pio/build/bw_swan_r5
Done cleaning
Verbose mode can be enabled via `-v, --verbose` option
*** [upload] Source `.pio/build/bw_swan_r5/firmware.elf' not found, needed by target `upload'.

I was hoping there was a build target or similar, but didn’t find one. Is there some other way to make this work? The workaround I used is to invoke pio run twice with each target separately.

Can you file a bug in Issues · platformio/platformio-core · GitHub?