Explorer
/proc/thread-self/root/tmp/aa050_release132.py
← Zurück ↓ Download
import sqlite3, subprocess, datetime, json, os
DB='/opt/struktur/youtube-research/knowledge.db'; R='/opt/struktur/graphiti/request-data/requests.db'; qid=132
now=datetime.datetime.now(datetime.timezone.utc).isoformat()
q=sqlite3.connect('file:'+DB+'?mode=ro',uri=True); q.row_factory=sqlite3.Row
row=dict(q.execute('select id,video_id,obsidian_path,content_hash,import_identity,graphiti_status,attempt_count,locked_at,updated_at,last_http_status,last_error_class,last_error_message,remote_outcome,graphiti_episode_id,next_attempt_at from graphiti_import_queue where id=?',(qid,)).fetchone()); q.close()
r=sqlite3.connect('file:'+R+'?mode=ro',uri=True); r.row_factory=sqlite3.Row
active=[dict(x) for x in r.execute("select request_id,status,http_status,episode_uuid,started_at,completed_at from graphiti_requests where queue_id=? and status in ('started','processing')",(str(qid),))]; r.close()
name='aa043_'+str(row.get('import_identity') or '')
cy="MATCH (n:Episodic) WHERE n.name='"+name+"' RETURN n.uuid AS uuid,n.name AS name LIMIT 2"
p=subprocess.run(['docker','exec','graphiti-neo4j','cypher-shell','-u','neo4j','-p','graphiti2026','--format','plain',cy],capture_output=True,text=True)
patch=subprocess.run(['docker','exec','graphiti-service','sh','-c',"grep -n -A2 -B2 \"summary=(node_data.get('summary') or '')\" /usr/local/lib/python3.12/site-packages/graphiti_core/utils/maintenance/node_operations.py"],capture_output=True,text=True)
health=subprocess.run(['curl','-fsS','http://127.0.0.1:8644/health'],capture_output=True,text=True)
print(json.dumps({'checked_at_utc':now,'row':row,'active_requests':active,'neo4j_exact_name':{'name':name,'rc':p.returncode,'stdout':p.stdout.strip(),'stderr':p.stderr.strip()},'patch_active':{'rc':patch.returncode,'stdout':patch.stdout.strip()},'health':health.stdout.strip()},indent=2,default=str))
# strict release gate
if row is None or row['graphiti_status']!='retry_wait' or row['graphiti_episode_id'] is not None or active or p.returncode!=0 or p.stdout.strip() or patch.returncode!=0 or not patch.stdout.strip() or health.returncode!=0: raise SystemExit('RELEASE_ABORTED')
if row['remote_outcome'] not in ('REQUEUED_AA050','PROVIDER_RATE_LIMIT',None): raise SystemExit('RELEASE_ABORTED_REMOTE_OUTCOME_'+str(row['remote_outcome']))
con=sqlite3.connect(DB); con.execute('BEGIN IMMEDIATE'); con.execute("update graphiti_import_queue set next_attempt_at=?, locked_at=NULL, lock_owner=NULL, lock_token=NULL, lease_expires_at=NULL, heartbeat_at=NULL, updated_at=?, remote_outcome='REQUEUED_AA050' where id=? and graphiti_status='retry_wait' and graphiti_episode_id is null",(now,now,qid));
if con.total_changes!=1: con.rollback(); raise SystemExit('RELEASE_UPDATE_FAILED')
con.commit(); con.close(); print('RELEASED',qid,now)