feat(host-agent): add single-instance lock to prevent duplicate-process dispatch races

Acquire an exclusive, non-blocking filelock on the identity state directory
as the first action of create_application(), before resolve_host_identity()
or any enrollment/heartbeat side effect. A second process against the same
identity_path exits immediately with InstanceAlreadyRunningError naming the
lock path; the lock releases automatically on any process exit (including
SIGKILL) via OS-level advisory locking, and explicitly during run_async()'s
shutdown finally block. filelock is promoted from transitive to direct
dependency (version unchanged at 3.29.7).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-14 15:49:30 +08:00
co-authored by Claude Opus 4.6
parent 99bde4febb
commit d00ada67a5
9 changed files with 444 additions and 102 deletions
Generated
+2
View File
@@ -569,6 +569,7 @@ dependencies = [
{ name = "device-agent-runtime" },
{ name = "device-cloud-platform" },
{ name = "fastapi" },
{ name = "filelock" },
{ name = "httpx" },
{ name = "jinja2" },
{ name = "uvicorn", extra = ["standard"] },
@@ -579,6 +580,7 @@ requires-dist = [
{ name = "device-agent-runtime", editable = "." },
{ name = "device-cloud-platform", editable = "packages/cloud-platform" },
{ name = "fastapi", specifier = ">=0.115.0" },
{ name = "filelock", specifier = ">=3.0" },
{ name = "httpx", specifier = ">=0.27.0" },
{ name = "jinja2", specifier = ">=3.1" },
{ name = "uvicorn", extras = ["standard"], specifier = ">=0.30.0" },