fix: Agent survives slow Hub on large syncs (25-product chunks, 120s timeout, retry) and keeps heartbeating during jobs; 1.1.4

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
gti
2026-09-24 09:33:54 -03:00
co-authored by Claude Sonnet 5
parent d1104589cc
commit e40e9500a4
19 changed files with 75 additions and 26 deletions
+21
View File
@@ -1,6 +1,7 @@
"""Agent side of the zero-touch model: delta sync via fingerprint cache, read-only guarantee,
blockers/operational summary in the job result, central pause, Firebird credential resolution."""
import json
import time
import pytest
@@ -125,3 +126,23 @@ def test_central_resume_after_pause_makes_agent_poll_again(monkeypatch, tmp_path
monkeypatch.setattr(service.time, "sleep", lambda s: None)
service.run(_config(agent_id="2", poll_interval_seconds=0, state_db=str(tmp_path / "a.db")), {"AGENT_ID": "2"}, stopper=stopper)
assert calls["next_job"] == 1 # first cycle paused (no poll), second cycle resumed (polled)
def test_heartbeats_keep_flowing_while_a_long_job_runs(monkeypatch, tmp_path):
beats = []
class Hub:
def identity(self): return {"agent_id": 2, "installation_id": "00000000-0000-4000-8000-000000000222"}
def heartbeat_metadata(self, payload): beats.append(payload["status"]); return {"processing_enabled": True}
def next_job(self): return {"job_id": 5, "kind": "INITIAL_SYNC", "agent_id": 2, "payload": {}}
def complete_job(self, job_id, summary): stopper.stop = True
def fail_job(self, job_id, error): stopper.stop = True
class Stopper: stop = False
stopper = Stopper()
monkeypatch.setattr(service, "BUSY_HEARTBEAT_SECONDS", 0.05)
monkeypatch.setattr(service, "HubClient", lambda *a, **k: Hub())
monkeypatch.setattr(service, "load_executor", lambda: _FakeExecutor())
monkeypatch.setattr(service, "execute_job", lambda *a, **k: (time.sleep(0.4), ({"ok": 1}, None))[1])
service.run(_config(agent_id="2", poll_interval_seconds=0, state_db=str(tmp_path / "a.db")), {"AGENT_ID": "2"}, stopper=stopper)
assert beats.count("BUSY") >= 3 # heartbeats during the job, not only before it