import sqlite3, json
c=sqlite3.connect("/home/ultimo/.n8n/database.sqlite")
def q(s,p=()): return c.execute(s,p).fetchall()
KW=["error","fail","cannot","undefined","abort","econn","timeout","refused","not found","enoent","offline","not registered","forbidden","401","403","409","spawn","runner","python"]
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,))
    if not r: continue
    d=q("SELECT data FROM execution_data WHERE executionId=?",(r[0][0],))
    print("===",nm,"===")
    try: arr=json.loads(d[0][0])
    except Exception as e: print("  parse err",e); continue
    errs=[]
    for x in arr:
        if isinstance(x,str) and 12<len(x)<260 and any(k in x.lower() for k in KW):
            if x not in errs: errs.append(x)
    for e in errs[:5]: print("  -",e[:200])
