Puppet agent not using last run environment when starting new run

Problem:

I have a host where the puppet agent starts its run using the environment configured in /etc/puppetlabs/puppet/puppet.conf (i.e “production”) instead of starting with the environment from the last run.

/etc/puppetlabs/puppet/puppet.conf

[main]
server = puppet.server.internal
certname = test.vm.local
environment = production
runinterval = 3600

As on the other hosts (which do not experience this issue) the puppet agent is configured to use the puppet environment from the last run:

[root@my-host ~]# puppet config print --section agent | grep use_last_environment
use_last_environment = true

Expected outcome:

Puppet agent starts run using the same puppet environment as when it ended its last run.

Puppet agent version: 6.28.0

The host is configured to use puppet environment “test” on Foreman.

Even after running puppet agent successfully by forcing the environment, on the next run it again starts with “production”.

[root@host-test ~]# puppet agent -t --environment test
Info: Using environment 'test'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Loading facts
Info: Caching catalog for host.test.local
Info: Applying configuration version 'bcd45df8353bc5d713449c770fada7aeb6ec114b'
Notice: Applied catalog in 66.28 seconds

[root@host-test ~]# puppet agent -t
Info: Using environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Loading facts
Error: Some puppet error
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run