feat(host-agent): make execution history authoritative
Tests / Test failed: 2, passed: 830

This commit is contained in:
2026-07-15 11:46:27 +08:00
parent ccde30e378
commit 77d4813bb2
46 changed files with 890 additions and 3132 deletions
+30 -5
View File
@@ -13,14 +13,20 @@ class TaskMetadataStore:
self.db_path.parent.mkdir(parents=True, exist_ok=True)
self._ensure_schema()
def create_task(self, task: Task) -> None:
def create_task(
self,
task: Task,
*,
source_task_id: str | None = None,
source_attempt: int | None = None,
) -> None:
with self._connect() as connection:
connection.execute(
"""
insert into tasks (
insert or ignore into tasks (
id, goal, device_id, status, created_at, updated_at,
completed_at, failure_reason
) values (?, ?, ?, ?, ?, ?, ?, ?)
completed_at, failure_reason, source_task_id, source_attempt
) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
(
task.id,
@@ -31,6 +37,8 @@ class TaskMetadataStore:
task.updated_at.isoformat(),
task.completed_at.isoformat() if task.completed_at else None,
task.failure_reason,
source_task_id,
source_attempt,
),
)
@@ -100,10 +108,27 @@ class TaskMetadataStore:
created_at text not null,
updated_at text not null,
completed_at text,
failure_reason text
failure_reason text,
source_task_id text,
source_attempt integer
)
"""
)
self._ensure_column(connection, "source_task_id", "text")
self._ensure_column(connection, "source_attempt", "integer")
@staticmethod
def _ensure_column(
connection: sqlite3.Connection,
name: str,
definition: str,
) -> None:
columns = {
str(row["name"])
for row in connection.execute("pragma table_info(tasks)").fetchall()
}
if name not in columns:
connection.execute(f"alter table tasks add column {name} {definition}")
def _connect(self) -> sqlite3.Connection:
connection = sqlite3.connect(self.db_path)