mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-20 15:11:09 +00:00
fc4e3a52d4
- Fix naive datetime.now() → datetime.now(UTC) in all ORM models - Fix seq race condition in DbRunEventStore.put() with FOR UPDATE and UNIQUE(thread_id, seq) constraint - Encapsulate _store access in RunManager.update_run_completion() - Deduplicate _store.put() logic in RunManager via _persist_to_store() - Add update_run_completion to RunStore ABC + MemoryRunStore - Wire follow_up_to_run_id through the full create path - Add error recovery to RunJournal._flush_sync() lost-event scenario - Add migration note for search_threads breaking change - Fix test_checkpointer_none_fix mock to set database=None Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
"""ORM model for run events."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC, datetime
|
|
|
|
from sqlalchemy import JSON, DateTime, Index, String, Text, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from deerflow.persistence.base import Base
|
|
|
|
|
|
class RunEventRow(Base):
|
|
__tablename__ = "run_events"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
thread_id: Mapped[str] = mapped_column(String(64), nullable=False)
|
|
run_id: Mapped[str] = mapped_column(String(64), nullable=False)
|
|
event_type: Mapped[str] = mapped_column(String(32), nullable=False)
|
|
category: Mapped[str] = mapped_column(String(16), nullable=False)
|
|
# "message" | "trace" | "lifecycle"
|
|
content: Mapped[str] = mapped_column(Text, default="")
|
|
event_metadata: Mapped[dict] = mapped_column(JSON, default=dict)
|
|
seq: Mapped[int] = mapped_column(nullable=False)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=lambda: datetime.now(UTC))
|
|
|
|
__table_args__ = (
|
|
UniqueConstraint("thread_id", "seq", name="uq_events_thread_seq"),
|
|
Index("ix_events_thread_cat_seq", "thread_id", "category", "seq"),
|
|
Index("ix_events_run", "thread_id", "run_id", "seq"),
|
|
)
|