import sqlite3, re
c=sqlite3.connect("/home/ultimo/.n8n/database.sqlite")
def q(s,p=()): return c.execute(s,p).fetchall()
for wfid,nm in [("4457PCm16VZaxvOW","REDATOR BOT"),("qBWf8H9yx6JkR1or","DISPATCHER")]:
    r=q("SELECT id FROM execution_entity WHERE workflowId=? AND status IN (\"error\",\"crashed\") ORDER BY id DESC LIMIT 1",(wfid,))
    print("===",nm,"(exec",(r[0][0] if r else "?"),") ===")
    if r:
        d=q("SELECT data FROM execution_data WHERE executionId=?",(r[0][0],))
        data=d[0][0] if d else ""
        msgs=list(dict.fromkeys(re.findall(r"\"(?:message|description)\":\"([^\"]{6,160})\"",data)))
        for m in msgs[:4]: print("  -",m)
        ln=re.findall(r"\"lastNodeExecuted\":\"([^\"]+)\"",data)
        if ln: print("  último nó:",ln[0])
