Add stack trace logging to track duplicate send source

This commit is contained in:
daniel
2026-05-07 18:43:56 -05:00
parent b0b641b4c8
commit e35599b522

View File

@@ -72,14 +72,16 @@ _sent_hashes: set = set()
def send_telegram_direct(chat_id: str, token: str, text: str) -> None: def send_telegram_direct(chat_id: str, token: str, text: str) -> None:
import hashlib import hashlib, traceback as tb
h = hashlib.md5(f'{chat_id}:{text}'.encode()).hexdigest()[:12] h = hashlib.md5(f'{chat_id}:{text}'.encode()).hexdigest()[:12]
if h in _sent_hashes: if h in _sent_hashes:
print(f'[agent-runner] dedup: skipping duplicate message (hash={h})') print(f'[agent-runner] dedup: skipping duplicate message (hash={h})')
print(f'[agent-runner] dedup stack: {tb.format_stack()[-3].strip()}')
return return
_sent_hashes.add(h) _sent_hashes.add(h)
print(f'[agent-runner] SEND hash={h} text={repr(text[:40])}')
print(f'[agent-runner] SEND caller: {tb.format_stack()[-2].strip()}')
url = f'https://api.telegram.org/bot{token}/sendMessage' url = f'https://api.telegram.org/bot{token}/sendMessage'
data = json.dumps({'chat_id': chat_id, 'text': text}).encode()
req = urllib.request.Request(url, data=data, headers={'Content-Type': 'application/json'}) req = urllib.request.Request(url, data=data, headers={'Content-Type': 'application/json'})
urllib.request.urlopen(req, timeout=10) urllib.request.urlopen(req, timeout=10)