mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-29 19:35:20 +02:00
A run can contain zero, one, or N agent_task steps. A single agent_session_id at the run level holds at most one of them, so the column is the wrong shape for the data. Per-step session ids (LangGraph thread/checkpoint reference for an agent_task step) live inside step_results[i] alongside the rest of the per-step bag (status, timings, output). Each agent step records its own; non-agent steps record nothing. Run-level "primary session" is a UI concern, not a schema concern. Trade-off: trace -> run reverse lookup is now a JSONB query, not an index hit. Usually traversal goes run -> trace; if the reverse becomes hot we add a GIN index on step_results or a generated column — both additive. Changes: - AutomationRun: drop the agent_session_id column; module docstring notes where per-step session ids now live. - Migration 144: drop the column from the CREATE TABLE; downgrade unchanged. Safe to edit migration 144 in place (vs. add 145 with ALTER ... DROP): this branch has not shipped and the table has never existed in any deployed database.
60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
"""``automation_runs`` table — immutable per-fire execution record.
|
|
|
|
Per-step metadata (incl. any LangGraph session id for an ``agent_task`` step)
|
|
lives inside ``step_results[i]``, since a single run may contain zero, one,
|
|
or N agent steps.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from sqlalchemy import (
|
|
TIMESTAMP,
|
|
Column,
|
|
Enum as SQLAlchemyEnum,
|
|
ForeignKey,
|
|
Integer,
|
|
)
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
|
|
from app.db import BaseModel, TimestampMixin
|
|
|
|
from ..enums.run_status import RunStatus
|
|
|
|
|
|
class AutomationRun(BaseModel, TimestampMixin):
|
|
__tablename__ = "automation_runs"
|
|
|
|
automation_id = Column(
|
|
Integer,
|
|
ForeignKey("automations.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
index=True,
|
|
)
|
|
|
|
trigger_id = Column(
|
|
Integer,
|
|
ForeignKey("automation_triggers.id", ondelete="SET NULL"),
|
|
nullable=True,
|
|
index=True,
|
|
)
|
|
|
|
status = Column(
|
|
SQLAlchemyEnum(RunStatus, name="automation_run_status"),
|
|
nullable=False,
|
|
default=RunStatus.PENDING,
|
|
server_default=RunStatus.PENDING.value,
|
|
index=True,
|
|
)
|
|
|
|
# locked at fire time so historical runs always show the exact code path
|
|
definition_snapshot = Column(JSONB, nullable=False)
|
|
|
|
trigger_payload = Column(JSONB, nullable=True)
|
|
resolved_inputs = Column(JSONB, nullable=False, server_default="{}")
|
|
step_results = Column(JSONB, nullable=False, server_default="[]")
|
|
output = Column(JSONB, nullable=True)
|
|
artifacts = Column(JSONB, nullable=False, server_default="[]")
|
|
error = Column(JSONB, nullable=True)
|
|
|
|
started_at = Column(TIMESTAMP(timezone=True), nullable=True)
|
|
finished_at = Column(TIMESTAMP(timezone=True), nullable=True)
|