refactor(automation): drop agent_session_id from AutomationRun

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.
This commit is contained in:
CREDO23 2026-05-27 11:41:32 +02:00
parent f0e00bd3ee
commit 35117a952d
2 changed files with 6 additions and 5 deletions

View file

@ -125,7 +125,6 @@ def upgrade() -> None:
error JSONB,
started_at TIMESTAMP WITH TIME ZONE,
finished_at TIMESTAMP WITH TIME ZONE,
agent_session_id VARCHAR(200),
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
"""

View file

@ -1,4 +1,9 @@
"""``automation_runs`` table — immutable per-fire execution record."""
"""``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
@ -8,7 +13,6 @@ from sqlalchemy import (
Enum as SQLAlchemyEnum,
ForeignKey,
Integer,
String,
)
from sqlalchemy.dialects.postgresql import JSONB
@ -54,5 +58,3 @@ class AutomationRun(BaseModel, TimestampMixin):
started_at = Column(TIMESTAMP(timezone=True), nullable=True)
finished_at = Column(TIMESTAMP(timezone=True), nullable=True)
agent_session_id = Column(String(200), nullable=True)