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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user