fix: drain backlog only once
This commit is contained in:
@@ -330,6 +330,16 @@ def run(
|
||||
offset: Optional[int] = None
|
||||
ignore_backlog = bool(ignore_backlog)
|
||||
|
||||
if ignore_backlog:
|
||||
try:
|
||||
updates = bot.get_updates(offset=offset, timeout_s=0, allowed_updates=["message"])
|
||||
except Exception as e:
|
||||
log(f"[startup] backlog drain failed: {e}")
|
||||
updates = []
|
||||
if updates:
|
||||
offset = updates[-1]["update_id"] + 1
|
||||
log(f"[startup] drained {len(updates)} pending update(s)")
|
||||
|
||||
log(f"[startup] pwd={startup_pwd}")
|
||||
log("Option1 bridge running (codex exec). Long-polling Telegram...")
|
||||
if startup_ids:
|
||||
@@ -484,13 +494,6 @@ def run(
|
||||
time.sleep(2.0)
|
||||
continue
|
||||
|
||||
if ignore_backlog:
|
||||
if updates:
|
||||
offset = updates[-1]["update_id"] + 1
|
||||
log(f"[startup] drained {len(updates)} pending update(s)")
|
||||
continue
|
||||
ignore_backlog = False
|
||||
|
||||
for upd in updates:
|
||||
offset = upd["update_id"] + 1
|
||||
msg = upd.get("message") or {}
|
||||
|
||||
@@ -293,6 +293,16 @@ def run(
|
||||
offset: Optional[int] = None
|
||||
ignore_backlog = bool(ignore_backlog)
|
||||
|
||||
if ignore_backlog:
|
||||
try:
|
||||
updates = bot.get_updates(offset=offset, timeout_s=0, allowed_updates=["message"])
|
||||
except Exception as e:
|
||||
print(f"[startup] backlog drain failed: {e}")
|
||||
updates = []
|
||||
if updates:
|
||||
offset = updates[-1]["update_id"] + 1
|
||||
print(f"[startup] drained {len(updates)} pending update(s)")
|
||||
|
||||
print("Option2 bridge running (codex mcp-server). Long-polling Telegram...")
|
||||
|
||||
# Single worker queue so we never overlap tools/call
|
||||
@@ -348,13 +358,6 @@ def run(
|
||||
time.sleep(2.0)
|
||||
continue
|
||||
|
||||
if ignore_backlog:
|
||||
if updates:
|
||||
offset = updates[-1]["update_id"] + 1
|
||||
print(f"[startup] drained {len(updates)} pending update(s)")
|
||||
continue
|
||||
ignore_backlog = False
|
||||
|
||||
for upd in updates:
|
||||
offset = upd["update_id"] + 1
|
||||
msg = upd.get("message") or {}
|
||||
|
||||
@@ -45,6 +45,16 @@ def run(
|
||||
|
||||
offset: Optional[int] = None
|
||||
ignore_backlog = bool(ignore_backlog)
|
||||
|
||||
if ignore_backlog:
|
||||
try:
|
||||
updates = bot.get_updates(offset=offset, timeout_s=0, allowed_updates=["message"])
|
||||
except Exception as e:
|
||||
print(f"[startup] backlog drain failed: {e}")
|
||||
updates = []
|
||||
if updates:
|
||||
offset = updates[-1]["update_id"] + 1
|
||||
print(f"[startup] drained {len(updates)} pending update(s)")
|
||||
print("Option3 reply bot running (tmux injector). Long-polling Telegram...")
|
||||
|
||||
while True:
|
||||
@@ -55,13 +65,6 @@ def run(
|
||||
time.sleep(2.0)
|
||||
continue
|
||||
|
||||
if ignore_backlog:
|
||||
if updates:
|
||||
offset = updates[-1]["update_id"] + 1
|
||||
print(f"[startup] drained {len(updates)} pending update(s)")
|
||||
continue
|
||||
ignore_backlog = False
|
||||
|
||||
for upd in updates:
|
||||
offset = upd["update_id"] + 1
|
||||
msg = upd.get("message") or {}
|
||||
|
||||
Reference in New Issue
Block a user