fix: fresh install archives stale state of a previous installation; a fatal Agent loop error stops the service instead of leaving a dead 'Running' one; 1.2.3

Found by uninstall + fresh install on the clean Windows Sandbox: the old agent_state.sqlite identity conflicted with the new enrollment and the service sat idle.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
gti
2026-09-25 12:25:53 -03:00
co-authored by Claude Sonnet 5
parent 2e5598ce9c
commit 6f0f072d84
23 changed files with 81 additions and 25 deletions
+16
View File
@@ -333,3 +333,19 @@ def audit_event(agent_token: str, hub: str, event_type: str, message: str) -> No
response.raise_for_status()
except Exception: # noqa: BLE001 — best effort only
return
def archive_stale_state(install: Path) -> list[str]:
"""A NEW enrollment (fresh install with a code) means a NEW identity. A state database left behind by a previous installation (uninstall keeps local data) still carries
the old installation_id, which the Agent refuses to mix with the new credential: rename it aside (never delete) so the new installation starts clean."""
moved = []
stamp = time.strftime("%Y%m%d-%H%M%S")
for name in ("agent_state.sqlite", "agent_state.sqlite-wal", "agent_state.sqlite-shm", "agent_state.sqlite-journal"):
path = Path(install) / name
if path.exists():
target = path.with_name(f"{name}.previous-{stamp}")
path.rename(target)
moved.append(target.name)
if moved:
ilog(f"archived state from a previous installation: {', '.join(moved)}")
return moved
+1
View File
@@ -106,6 +106,7 @@ def install_flow(code: str, *, hub: str | None = None, install_dir_path: str | N
progress("Instalando o serviço…")
extract_payload(install)
common.archive_stale_state(install)
started = heartbeat = False
service_detail = ""