fix(v2): fix "Validar e executar" bug (real root cause), expand generic-phrase blacklist, add FORCE_SEND

Root cause found for why the real Slack message showed "→ Validar e
executar" for nearly every ACTIONABLE_NOW ticket: logic/message.js's
ACTION_LABELS map had a hardcoded entry for ACTIONABLE_NOW that always
won over the AI's actual next_action field in shortActionLabel(). The
AI's real, specific, already-validated-as-non-generic next_action (e.g.
"Realizar inventário das máquinas") was being silently discarded for
display purposes on every single message. Fixed by removing the
ACTIONABLE_NOW entry -- it now falls through to the existing
next_action-based fallback (already there, just unreachable for that
class before). UNASSIGNED_ACTIONABLE intentionally keeps its fixed
"Atribuir técnico" label -- that IS the correct display for that class.

logic/classification.js: expanded GENERIC_NEXT_ACTION_PHRASES with the
exact phrase that leaked through ("validar e executar") plus the
mission's additional list (validar chamado, prosseguir atendimento,
executar chamado, tratar chamado, analisar chamado). Bumped
AI_CLASSIFIER_VERSION 3->4 since this changes what next_action values
validate as non-generic -- forces reclassification of any cached
candidate that only passed under the older, narrower blacklist.

n8n/nodes/validate-ai-response.node.js: generic-next-action rejections
now get their own distinct fallback_reason ('generic_or_unsupported_
next_action') instead of being lumped into 'invalid_json', matching the
same pattern already used for the technician-vendor conflict.

logic/slack.js + logic/config.js: added FORCE_SEND (default false).
Manual-triggered runs now never send for real even with SEND_ENABLED=
true in production, unless FORCE_SEND is also explicitly set -- protects
against someone clicking "Execute Workflow" in production and
accidentally re-sending today's digest.

Added format-safety regression tests (no literal backslash-n, URL never
bleeds into the next item's id, no markdown-wrapped URLs) -- verified
these were never actually triggered in a real send (the reported
corruption was n8n's raw JSON data-inspector view, not a delivered
Slack message; both manual runs in question had shouldSend:false).

169/169 tests passing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Gustavo
2026-08-24 21:49:42 -03:00
co-authored by Claude Sonnet 5
parent 26b06e07d5
commit 124516e64a
10 changed files with 138 additions and 19 deletions
+8 -2
View File
@@ -7,7 +7,10 @@ const VALID_CLASSIFICATIONS = [
// Versao do prompt/classificador. Bump manual sempre que o system prompt ou as regras de
// validacao mudarem de forma que mudaria o julgamento da IA -- forca cache miss em TODO
// chamado (ver logic/cache.js -> buildCacheKey), sem precisar apagar a Data Table na mao.
const AI_CLASSIFIER_VERSION = 3;
// v4: lista de frases genericas rejeitadas expandida ("Validar e executar" e variantes --
// missao "correcao final", secao 5). Bump forca reclassificacao de qualquer candidato
// cacheado sob a v3 cujo next_action so passava porque a v3 nao conhecia essas frases.
const AI_CLASSIFIER_VERSION = 4;
// O modelo, apesar do schema permitir null de verdade em blocker_type/waiting_for, as vezes
// devolve a STRING "null" (ou variantes equivalentes) em vez do valor JSON null. Normaliza
@@ -27,10 +30,13 @@ function normalizeNullableString(value) {
// do suporte; nas demais classes o campo descreve o que se espera de terceiros, entao uma
// frase curta ("aguardar resposta") e legitima ali.
const ACTIONABLE_CLASSES_REQUIRING_CONCRETE_NEXT_ACTION = new Set(['ACTIONABLE_NOW', 'UNASSIGNED_ACTIONABLE']);
// Lista expandida na missao "correcao final" (secao 5) -- "Validar e executar" era o rotulo
// fixo que a mensagem real mostrou pra quase todo ACTIONABLE_NOW (ver logic/message.js).
const GENERIC_NEXT_ACTION_PHRASES = new Set([
'revisar chamado', 'revisar o chamado', 'dar andamento', 'dar andamento no chamado',
'analisar situacao', 'analisar a situacao', 'verificar chamado', 'verificar o chamado',
'analisar situacao', 'analisar a situacao', 'analisar chamado', 'verificar chamado', 'verificar o chamado',
'acompanhar', 'acompanhar chamado', 'acompanhar o chamado',
'validar e executar', 'validar chamado', 'prosseguir atendimento', 'executar chamado', 'tratar chamado',
]);
function normalizeForComparison(text) {