[Rspamd-Users] Calling task:learn() in Lua postfilter leads to task abortion

Marcel Menzel mail at mcl.gg
Sat Dec 20 16:43:54 UTC 2025


Hello List,

I am currently trying to write a Lua module to dynamically train Bayes 
Ham / Spam and different classifiers automatically, but when I call 
task:learn() in a postfilter, it leads to a tempfail:

rspamd[40613]: <e2302f>; task; fuzzy_controller_io_callback: added fuzzy 
hash (bin) 
d2e845d4b485b25a0482720b621f84cd9330f2a9b58886ff8f5e1058d3d9679e3a7c48aabe7f08cd961d7bf38e5c329ed1d6cfd817dcd9079eb420a2906442f4, 
list: LOCAL_FUZZY_DENIED:5 for message <redacted>
rspamd[40613]: <e2302f>; task; fuzzy_controller_io_callback: added fuzzy 
hash (bin) 
647ca86e6ca58424709ecd5574051b13b680829a7c454fd463a0b56046229c61a7d74c81f3486c462381b2b3f31851146828fa5dace58a8adcbef57ac34ecf2f, 
list: LOCAL_FUZZY_DENIED:5 for message <redacted>
rspamd[40613]: <e2302f>; task; rspamd_stat_classifier_is_skipped: learn 
condition for classifier bayes returned: already in class spam; 
probability 99.20%; skip classifier
rspamd[40613]: <e2302f>; task; rspamd_task_process: skip learning: all 
learn conditions denied learning spam in default classifier
rspamd[40611]: <e2302f>; milter; rspamd_milter_send_task_results: cannot 
find action in results, tempfail
postfix/cleanup[40672]: 153202F0A8: milter-reject: END-OF-MESSAGE from 
[...]: 4.7.1 Service unavailable - try again later; from=<redacted> 
to=<redacted> proto=ESMTP

Fuzzy learning and bayes learning seems to work itself according to 
above logs, but I am currently not understanding why task:learn() leads 
to a task abortion. Maybe the postfilter stage is still too early to 
call this function?

My problem being that the idempotent stage instead of the postfilter 
stage seems to be too late, as I am also using the force action module 
to set a passthrough result (for example reject on banned ASNs) so the 
idempotent symbol never gets called in this case although I'd also like 
to train bayes in this case if my conditions match.

This is a simplified version of my Lua script with the task failing:

rspamd_config:register_symbol({
   name = 'CUSTOM_AUTOLEARN',
   type = 'postfilter',
   callback = function(task)
     local res = task:get_metric_result()
     if not res or not res.action then
       return
     end

     if res.score > 30 and res.action == "reject" then
       -- flag, weight
       local fuzzylearn = rspamd_plugins.fuzzy_check.learn(task, 5, 10)

       local bayeslearn = task:learn(true)
     end
   end
})

I've looked at the source code and saw the possibility for setting 
task:set_flag("learn_spam") (which autolearn also uses), but I haven't 
tried this yet.
Also with this, I am currently not seeing a way to set the bayes 
classifier, it might be possible with a flag via 
RSPAMD_TASK_FLAG_LEARN_CLASS? But how would I pass the class string to 
task:set_flag()?


Thank you & kind regards,

Marcel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0x49235D0D4F8ACED4.asc
Type: application/pgp-keys
Size: 6474 bytes
Desc: OpenPGP public key
URL: <https://lists.rspamd.com/pipermail/users/attachments/20251220/97fcc245/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://lists.rspamd.com/pipermail/users/attachments/20251220/97fcc245/attachment-0001.bin>


More information about the Users mailing list