Limnoria icon indicating copy to clipboard operation
Limnoria copied to clipboard

config written back with inconsistent list ordering

Open ajakk opened this issue 2 years ago • 2 comments

I keep my bot's configuration in git and deploy it in docker via ansible. Ansible automatically restarts the Limnoria container whenever the configuration changes, and ansible will forcibly overwrite any changes to the configuration repository when it pulls from the git repository for updates. After running the bot for some time, I find that the configuration has changed while the bot is running, with this diff:

diff --git a/mervin.conf b/mervin.conf
index 0056a38..d464207 100644
--- a/mervin.conf
+++ b/mervin.conf
@@ -109,9 +109,9 @@ supybot.alwaysJoinOnInvite: False
 # docs/CAPABILITIES if you don't understand why these default to what
 # they do.
 #
-# Default value: -scheduler.remove -scheduler.repeat -admin -aka.set -scheduler.add -alias.remove -aka.add -trusted -owner -aka.remove -alias.add
+# Default value: -scheduler.add -admin -aka.set -owner -aka.remove -alias.remove -scheduler.remove -alias.add -scheduler.repeat -aka.add -trusted
 ###
-supybot.capabilities: -admin -trusted -owner
+supybot.capabilities: -owner -admin -trusted

 ###
 # Determines whether the bot by default will allow users to have a
@@ -170,9 +170,9 @@ supybot.commands.defaultPlugins.ignore: Admin
 # change this if you don't know what you're doing; if you do know what
 # you're doing, then also know that this set is case-sensitive.
 #
-# Default value: User Misc Config Owner Admin Channel
+# Default value: Owner Channel Misc User Admin Config
 ###
-supybot.commands.defaultPlugins.importantPlugins: User Misc Config Owner Admin Channel
+supybot.commands.defaultPlugins.importantPlugins: Owner Channel Misc User Admin Config
 supybot.commands.defaultPlugins.list: Misc
 supybot.commands.defaultPlugins.reload: Owner
 supybot.commands.defaultPlugins.removecapability: Admin
@@ -815,7 +815,7 @@ supybot.pidFile:
 #
 # Default value:
 ###
-supybot.plugins: User RSS Misc Config NickAuth AutoMode Owner Admin Channel Utilities Network
+supybot.plugins: Owner Channel Admin Network Utilities RSS Misc User AutoMode NickAuth Config

 ###
 # Determines whether this plugin is loaded by default.
@@ -1130,7 +1130,7 @@ supybot.plugins.RSS: True
 # Default value:
 ###
 supybot.plugins.RSS.announce:
-supybot.plugins.RSS.announce.#gentoo-security-bots: nvdrss nvdrssanalyzed freshlinux
+supybot.plugins.RSS.announce.#gentoo-security-bots: nvdrssanalyzed freshlinux nvdrss

 ###
 # The format the bot will use for displaying headlines of a RSS feed
@@ -1154,7 +1154,7 @@ supybot.plugins.RSS.defaultNumberOfHeadlines: 1
 #
 # Default value:
 ###
-supybot.plugins.RSS.feeds: nvdrss nvdrssanalyzed freshlinux secbugs
+supybot.plugins.RSS.feeds: nvdrssanalyzed secbugs freshlinux nvdrss

 ###
 # The URL for the feed freshlinux. Note that because announced lines are

Whenever ansible runs, it detects the changes to the git repository and overwrites them - leading to the configuration state being changed and the bot restarting. This restart is obviously unecessary since the configuration is equivalent.

So, could the lists be sorted before they're written back to minimize changing the configuration unecessarily?

ajakk avatar Sep 07 '22 21:09 ajakk

Uh, I assumed Python >= 3.7 would preserve the order. I'll look into it.

In the meantime, could you make Ansible send a SIGHUP to Limnoria, it will make it reload its configuration without restarting.

progval avatar Sep 07 '22 21:09 progval

TIL that Python sets do not share dicts' implementation https://stackoverflow.com/a/61467874/539465

Anyway, there is a flag that can be toggled to make this happen: https://github.com/progval/Limnoria/blob/fccb4f705bb5ead64059a1f5994ef5e593095062/src/registry.py#L832

I just need to make sure it won't break anything before changing it

progval avatar Sep 07 '22 21:09 progval

Can you check dc94f8dc689ea5614c5a4a87c40b8fd923e70185 makes the order deterministic?

progval avatar Oct 14 '22 21:10 progval

Looks good to me after running for several days! Strangely, the deterministic ordering isn't quite sorted:

diff --git a/mervin.conf b/mervin.conf
index 0056a38..6d8b7c2 100644
--- a/mervin.conf
+++ b/mervin.conf
@@ -109,9 +109,9 @@ supybot.alwaysJoinOnInvite: False
 # docs/CAPABILITIES if you don't understand why these default to what
 # they do.
 #
-# Default value: -scheduler.remove -scheduler.repeat -admin -aka.set -scheduler.add -alias.remove -aka.add -trusted -owner -aka.remove -alias.add
+# Default value: -aka.remove -owner -scheduler.remove -aka.set -scheduler.repeat -alias.add -trusted -alias.remove -scheduler.add -aka.add -admin
 ###
-supybot.capabilities: -admin -trusted -owner
+supybot.capabilities: -trusted -owner -admin

 ###
 # Determines whether the bot by default will allow users to have a
@@ -170,9 +170,9 @@ supybot.commands.defaultPlugins.ignore: Admin
 # change this if you don't know what you're doing; if you do know what
 # you're doing, then also know that this set is case-sensitive.
 #
-# Default value: User Misc Config Owner Admin Channel
+# Default value: Admin Channel Config Misc Owner User
 ###
-supybot.commands.defaultPlugins.importantPlugins: User Misc Config Owner Admin Channel
+supybot.commands.defaultPlugins.importantPlugins: Admin Channel Config Misc Owner User
 supybot.commands.defaultPlugins.list: Misc
 supybot.commands.defaultPlugins.reload: Owner
 supybot.commands.defaultPlugins.removecapability: Admin
@@ -815,7 +815,7 @@ supybot.pidFile:
 #
 # Default value:
 ###
-supybot.plugins: User RSS Misc Config NickAuth AutoMode Owner Admin Channel Utilities Network
+supybot.plugins: Admin AutoMode Channel Config Misc Network NickAuth Owner RSS User Utilities

 ###
 # Determines whether this plugin is loaded by default.
@@ -1130,7 +1130,7 @@ supybot.plugins.RSS: True
 # Default value:
 ###
 supybot.plugins.RSS.announce:
-supybot.plugins.RSS.announce.#gentoo-security-bots: nvdrss nvdrssanalyzed freshlinux
+supybot.plugins.RSS.announce.#gentoo-security-bots: freshlinux nvdrss nvdrssanalyzed

 ###
 # The format the bot will use for displaying headlines of a RSS feed
@@ -1154,7 +1154,7 @@ supybot.plugins.RSS.defaultNumberOfHeadlines: 1
 #
 # Default value:
 ###
-supybot.plugins.RSS.feeds: nvdrss nvdrssanalyzed freshlinux secbugs
+supybot.plugins.RSS.feeds: nvdrssanalyzed freshlinux secbugs nvdrss

 ###
 # The URL for the feed freshlinux. Note that because announced lines are

But in any case, the determinism bit is what I cared about. Thanks!

ajakk avatar Oct 20 '22 15:10 ajakk

@ajakk indeed, I missed a few values. This should be fixed now

progval avatar Oct 20 '22 16:10 progval