Open Ne0os opened 1 month ago
That's a good catch, thank you. However, it seems the logic is still the same with this bug: if we got a symbol from exclude_symbols
we do not ask gpt in that case. We should definitely do it in a more graceful way though.
Thank you for the swift update and the changes to the function. The additional checks for sym
and sym.weight
are certainly helpful.
However, I noticed an issue with the sym.weight
value as shown in the following log lines:
bayes; bayes_classify: got ham probability -161.01 -> 0.00 and spam probability -26.97 -> 1.00, 68 tokens processed of 187 total tokens; 63 text tokens found of 169 text tokens
gpt; gpt.lua:116: symbol BAYES_SPAM has weight nil, but required 0.9
In this case, the BAYES_SPAM
symbol shows a nil
weight instead of the expected value of 0.99
. This suggests that there may be an issue with how the weight is being retrieved or set.
The updated function handles nil
values gracefully, but it seems that sym.weight
occasionally does not reflect the correct value. This discrepancy could indicate a problem in the symbol’s data retrieval or processing.
I temporarily added a log line that logged sym
to help identify the issue:
gpt; gpt.lua:110: Symbol details: {[1] = {[options] = {[1] = 99.99%}, [score] = 5.099999998407408, [groups] = {[1] = statistics}, [weight] = 0.9999999996877271, [group] = statistics}}
Changes Made:
default_condition
function to correctly access symbol weights.local sym_details = sym[1]
if sym_details and sym_details.weight then
if math.abs(sym_details.weight) >= required_weight then
return false, 'skip as "' .. s .. '" is found (weight: ' .. sym_details.weight .. ')'
end
end
I'm not a Lua expert, so I won't be making a pull request and I'm not entirely sure about my code.
Thank you again for your prompt response and efforts in addressing this issue. Your work is greatly appreciated!
Prerequisites
Describe the bug There is an error in the
gpt.lua
plugin where themath.abs
function is called with anil
value, leading to a failure in theGPT_CHECK
function. The issue occurs because the symbol weight retrieved fromtask:get_symbol(s)
can benil
.Steps to Reproduce
gpt.lua
plugin.settings.symbols_to_except
is present, but its weight is not set or isnil
.bad argument #1 to 'abs' (number expected, got nil)
.Expected behavior The script should handle cases where
sym
orsym.weight
isnil
and not attempt to callmath.abs
on anil
value.Versions
Rspamd version: Rspamd daemon version 3.9.0 OS: Debian GNU/Linux 11 (bullseye), x86_64
Additional Information
Example code causing the issue:
Proposed fix to handle
nil
values:This enhancement ensures that
sym
andsym.weight
are checked fornil
values before callingmath.abs
, preventing the error.