Repository navigation
Closed
Labels
bugbroken, incorrect, or confusing behavior
Milestone
Description
What happened?
I have state like:
/srv/storage/example/config/auth:
file.managed:
- contents: |
some config
- user: 1000
- group: root
- mode: 600
- makedirs: true
- dir_mode: 755
example:
docker_image.present:
- name: myexampleimage
- tag: latest
- force: true
docker_container.running:
- hostname: example
- image: myexampleimage:latest
- restart_policy: unless-stopped
- command:
- --password=/config/auth
- binds:
- /srv/storage/config/config:/config
- skip_translate: port_bindings
- networks:
- ipv4
- require:
- docker_image: config
- docker_network: ipv4
- watch:
- file: /srv/storage/example/config/auth
The issue is that when I change auth contents this is correctly detected as a change:
ID: /srv/storage/example/config/auth
Function: file.managed
Result: True
Comment: File /srv/storage/example/config/auth updated
Started: 08:34:42.215555
Duration: 2.488 ms
Changes:
----------
diff:
---
+++
@@ -1 +1 @@
-old config
+some config
But docker container is not recreated. There is unrelated change though, but there is no recreate:
ID: example
Function: docker_container.running
Result: True
Comment: Container 'example' is already configured as specified. Reconnected to network 'ipv4' with updated configuration.
Started: 08:34:44.375705
Duration: 549.806 ms
Changes:
----------
container:
----------
Networks:
----------
ipv4:
----------
Gateway:
----------
new:
172.18.0.1
old:
None
IPAMConfig:
----------
new:
None
old:
----------
IPv4Address:
172.18.0.5
IPv6Address:
IPAddress:
----------
new:
172.18.0.5
old:
None
(It is a side question why it is detecting this networking change - it should not - but this issue is not about that. I think it is connected with #66408.)
Type of salt install
pip (pypi)
Major version
3007.x
What supported OS are you seeing the problem on? Can select multiple. (If bug appears on an unsupported OS, please open a GitHub Discussion instead)
ubuntu-24.04
salt --versions-report output
salt3new) mitar@gagea:~/Documents/Projects/plast8-servers$ salt --versions-report
Salt Version:
Salt: 3007.9
Python Version:
Python: 3.12.3 (main, Mar 3 2026, 12:15:18) [GCC 13.3.0]
Dependency Versions:
cffi: 2.0.0
cherrypy: 18.10.0
cryptography: 46.0.3
dateutil: 2.9.0.post0
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
Jinja2: 3.1.6
libgit2: Not Installed
looseversion: 1.3.0
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 1.1.2
msgpack-pure: Not Installed
mysql-python: Not Installed
packaging: 25.0
pycparser: 2.23
pycrypto: Not Installed
pycryptodome: 3.23.0
pygit2: Not Installed
python-gnupg: 0.5.5
PyYAML: 6.0.3
PyZMQ: 27.1.0
relenv: Not Installed
smmap: Not Installed
timelib: 0.3.0
Tornado: 6.5.2
ZMQ: 4.3.5
Salt Package Information:
Package Type: Not Installed
System Versions:
dist: ubuntu 24.04.4 noble
locale: utf-8
machine: x86_64
release: 6.8.0-110-generic
system: Linux
version: Ubuntu 24.04.4 nobleMetadata
Metadata
Assignees
Labels
bugbroken, incorrect, or confusing behavior
Activity
mitar commentedon Apr 17, 2026
Claude says the issue is in:
It's in salt/state.py, not in docker_container.py — it's a watch-mechanism design flaw that got hit because your run had unrelated
changes on the same state.
salt/state.py:3386-3394 (the core):
Read that carefully: mod_watch is called only if the normal run returned no changes. If the normal run already produced any changes, mod_watch is silently skipped — the watched state's restart trigger is thrown away.
Now match that against your run:
If mod_watch had been called, it would have gone to docker_container.py:2517-2524, which sets watch_kwargs["force"] = True and re-invokes running(). With force=True, line 1724 sets skip_comparison=True, bypassing the comparison branch, and lines 2004-2011 call _replace(name, temp_container), which stops/removes the old container and renames the temp container in. That's the actual restart — and it never ran.
So the headline:
Fix mod_watch to run even with unrelated changes
mitar commentedon Apr 17, 2026
I made PR to fix this: #68960
Fix mod_watch to run even with unrelated changes
whytewolf commentedon Apr 20, 2026
and this is what we get when we believe AI. a stupid answer.
The issue is the logic getting to this point. not the BS claude fed you. it hallucinated and you fell for it. and decided to wag the dog based on its BS.
the actual answer is that you should have used prereq to call
docker_container.absenthttps://docs.saltproject.io/en/3006/ref/states/requisites.html#prereq if the file changed. since your config is unstable and will have changes that do not reflect the environment.you don't need to wag the dog.
mitar commentedon Apr 20, 2026
Thanks for this interesting info. I did investigate the output from Claude and also the PR I made which changes this behavior works great for me: I tested it against our Docker container which requires restart/recreation after file change and it does exactly what expected. I looked now at prereq but it looks to me a very heavy hammer for this problem. To me it is pretty clear that there is something wrong with how "file.watch" interacts with "docker_container.running". My problem is not that container should not be running with there is a new config file. But that Docker is not restarted when a new config file is deployed IF at the same time some other container's config changes. If nothing else changes, then Docker container is restarted on new config file. But for example, if Salt recreates the network (#66408) and then reconnects the container (which Salt can do without restarting) then new config file is not picked up. This behavior is unexpected and I think wrong. Now, if Claude found the right source of this problem or not, I do not know. But it does not look to me like the state configuration I am describing with "file.watch" + "docker_container.running" is ill defined, it is pretty clear that container should be restarted if file changes.
mitar commentedon Apr 23, 2026
#68960 contains now an updated approach which I think addresses issues raised above.
Allow watching states to opt-in to mod_watch when normal run had chan…
Set force_mod_watch in docker_container.running for lightweight changes
Set force_mod_watch in docker_container.running for lightweight changes