Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

feat(api): record workflow last_run_at with touch endpoint

joshistoastb3621b032484
diff --git a/invokeai/app/api/routers/workflows.py b/invokeai/app/api/routers/workflows.py
index 768a8f4e8d..43743686d8 100644
--- a/invokeai/app/api/routers/workflows.py
+++ b/invokeai/app/api/routers/workflows.py
@@ -477,3 +477,13 @@ async def update_opened_at(
user_id = None if current_user.is_admin else current_user.user_id
ApiDependencies.invoker.services.workflow_records.update_opened_at(workflow_id, user_id=user_id)
+
+
+@workflows_router.put(
+ "/i/{workflow_id}/last_run_at",
+ operation_id="update_workflow_last_run_at",
+ status_code=204,
+)
+async def update_workflow_last_run_at(workflow_id: str = Path(description="The workflow to update")) -> None:
+ """Updates the last_run_at field of a workflow"""
+ ApiDependencies.invoker.services.workflow_records.update_last_run_at(workflow_id)
diff --git a/invokeai/app/services/shared/sqlite_migrator/migrations/migration_2026_08_18_add_workflow_last_run_at.py b/invokeai/app/services/shared/sqlite_migrator/migrations/migration_2026_08_18_add_workflow_last_run_at.py
new file mode 100644
index 0000000000..ee23e84111
--- /dev/null
+++ b/invokeai/app/services/shared/sqlite_migrator/migrations/migration_2026_08_18_add_workflow_last_run_at.py
@@ -0,0 +1,25 @@
+"""Add the `last_run_at` column to `workflow_library`.
+
+Mirrors `opened_at`: a nullable timestamp, updated by a dedicated "touch" endpoint rather than as
+a side effect of any existing write. `opened_at` records when a workflow was last viewed in the
+editor; `last_run_at` records when a workflow was last completed as a run, so the frontend can
+show "Your last run · 2 days ago" on library cards.
+"""
+
+import sqlite3
+
+from invokeai.app.services.shared.sqlite_migrator.sqlite_migrator_common import Migration
+
+
+class AddWorkflowLastRunAtCallback:
+ def __call__(self, cursor: sqlite3.Cursor) -> None:
+ cursor.execute("ALTER TABLE workflow_library ADD COLUMN last_run_at DATETIME;")
+
+
+def build_migration() -> Migration:
+ """Build the migration that adds the nullable `last_run_at` column to `workflow_library`."""
+ return Migration(
+ id="2026_08_18_add_workflow_last_run_at",
+ depends_on="2026_08_08_repair_image_subfolder_move_tables",
+ callback=AddWorkflowLastRunAtCallback(),
+ )
diff --git a/invokeai/app/services/workflow_records/workflow_records_base.py b/invokeai/app/services/workflow_records/workflow_records_base.py
index c07daa2662..85740e4916 100644
--- a/invokeai/app/services/workflow_records/workflow_records_base.py
+++ b/invokeai/app/services/workflow_records/workflow_records_base.py
@@ -87,6 +87,11 @@ class WorkflowRecordsStorageBase(ABC):
"""Open a workflow. When user_id is provided, the UPDATE is scoped to that user."""
pass
+ @abstractmethod
+ def update_last_run_at(self, workflow_id: str) -> None:
+ """Records that a workflow was just run by setting its last_run_at timestamp to now."""
+ pass
+
@abstractmethod
def get_all_tags(
self,
diff --git a/invokeai/app/services/workflow_records/workflow_records_common.py b/invokeai/app/services/workflow_records/workflow_records_common.py
index 178dd5a8cf..c0d0b87a26 100644
--- a/invokeai/app/services/workflow_records/workflow_records_common.py
+++ b/invokeai/app/services/workflow_records/workflow_records_common.py
@@ -122,6 +122,9 @@ class WorkflowRecordDTOBase(BaseModel):
opened_at: Optional[Union[datetime.datetime, str]] = Field(
default=None, description="The opened timestamp of the workflow."
)
+ last_run_at: Optional[Union[datetime.datetime, str]] = Field(
+ default=None, description="The timestamp of the last completed run of this workflow."
+ )
user_id: str = Field(description="The id of the user who owns this workflow.")
is_public: bool = Field(description="Whether this workflow is shared with all users.")
diff --git a/invokeai/app/services/workflow_records/workflow_records_sqlite.py b/invokeai/app/services/workflow_records/workflow_records_sqlite.py
index a62dbb9dfa..99ebe7961b 100644
--- a/invokeai/app/services/workflow_records/workflow_records_sqlite.py
+++ b/invokeai/app/services/workflow_records/workflow_records_sqlite.py
@@ -37,7 +37,7 @@ class SqliteWorkflowRecordsStorage(WorkflowRecordsStorageBase):
with self._db.transaction() as cursor:
cursor.execute(
"""--sql
- SELECT workflow_id, workflow, name, created_at, updated_at, opened_at, user_id, is_public
+ SELECT workflow_id, workflow, name, created_at, updated_at, opened_at, last_run_at, user_id, is_public
FROM workflow_library
WHERE workflow_id = ?;
""",
@@ -186,6 +186,7 @@ class SqliteWorkflowRecordsStorage(WorkflowRecordsStorageBase):
created_at,
updated_at,
opened_at,
+ last_run_at,
tags,
user_id,
is_public
@@ -442,6 +443,17 @@ class SqliteWorkflowRecordsStorage(WorkflowRecordsStorageBase):
(workflow_id,),
)
+ def update_last_run_at(self, workflow_id: str) -> None:
+ with self._db.transaction() as cursor:
+ cursor.execute(
+ f"""--sql
+ UPDATE workflow_library
+ SET last_run_at = STRFTIME('{SQL_TIME_FORMAT}', 'NOW')
+ WHERE workflow_id = ?;
+ """,
+ (workflow_id,),
+ )
+
def get_all_tags(
self,
categories: Optional[list[WorkflowCategory]] = None,
diff --git a/tests/app/services/workflow_records/test_workflow_last_run_at.py b/tests/app/services/workflow_records/test_workflow_last_run_at.py
new file mode 100644
index 0000000000..6a77546d56
--- /dev/null
+++ b/tests/app/services/workflow_records/test_workflow_last_run_at.py
@@ -0,0 +1,61 @@
+"""Tests for the `last_run_at` column on workflow library records.
+
+`last_run_at` mirrors the existing `opened_at` machinery: a nullable timestamp set only by a
+dedicated "touch" method/endpoint, never as a side effect of `get`/`create`/`update`. This lets
+the frontend show "Your last run · 2 days ago" on library cards.
+"""
+
+import pytest
+
+from invokeai.app.services.invoker import Invoker
+from invokeai.app.services.shared.sqlite.sqlite_common import SQLiteDirection
+from invokeai.app.services.workflow_records.workflow_records_common import (
+ WorkflowCategory,
+ WorkflowMeta,
+ WorkflowRecordOrderBy,
+ WorkflowWithoutID,
+)
+from invokeai.app.services.workflow_records.workflow_records_sqlite import SqliteWorkflowRecordsStorage
+
+
+def workflow_records_service(mock_invoker: Invoker) -> SqliteWorkflowRecordsStorage:
+ return mock_invoker.services.workflow_records
+
+
+def create_minimal_user_workflow() -> WorkflowWithoutID:
+ """Builds a minimal `WorkflowWithoutID` with `meta.category == "user"`."""
+ return WorkflowWithoutID(
+ name="Test Workflow",
+ author="",
+ description="A test workflow",
+ version="1.0.0",
+ contact="",
+ tags="",
+ notes="",
+ exposedFields=[],
+ meta=WorkflowMeta(version="3.0.0", category=WorkflowCategory.User),
+ nodes=[],
+ edges=[],
+ )
+
+
+def test_update_last_run_at_sets_timestamp(workflow_records_service: SqliteWorkflowRecordsStorage) -> None:
+ workflow = create_minimal_user_workflow()
+ created = workflow_records_service.create(workflow=workflow)
+ assert created.last_run_at is None
+
+ workflow_records_service.update_last_run_at(created.workflow_id)
+
+ fetched = workflow_records_service.get(created.workflow_id)
+ assert fetched.last_run_at is not None
+
+ listed = workflow_records_service.get_many(
+ order_by=WorkflowRecordOrderBy.CreatedAt,
+ direction=SQLiteDirection.Descending,
+ categories=None,
+ page=0,
+ per_page=10,
+ )
+ row = next(item for item in listed.items if item.workflow_id == created.workflow_id)
+ assert row.last_run_at is not None