Merge remote-tracking branch 'origin/master' into ji

# Conflicts:
#	.gitignore
#	frontend-web/src/components/workspace/input-box.tsx
#	frontend-web/src/core/threads/types.ts
#	frontend-web/src/pages/ChatPage.tsx
This commit is contained in:
吉鑫升 committed 2026-08-12 15:55:51 +08:00
commit c4fd9dd7da
233 files changed
+12524 -1163

No files matched your search

@@ -0,0 +1,69 @@
"""Index optional task-scoped position-roundtable history.
Revision ID: 20260808_01
Revises: 20260729_01
Create Date: 2026-08-08
"""
from __future__ import annotations
import sqlalchemy as sa
from alembic import op
from sqlalchemy import inspect
revision = "20260808_01"
down_revision = "20260729_01"
branch_labels = None
depends_on = None
_TABLE = "position_roundtable_sessions"
_INDEX = "ix_position_roundtable_sessions_task_updated"
def _has_table(table_name: str) -> bool:
return table_name in inspect(op.get_bind()).get_table_names()
def _has_column(table_name: str, column_name: str) -> bool:
if not _has_table(table_name):
return False
return any(
column["name"] == column_name
for column in inspect(op.get_bind()).get_columns(table_name)
)
def _has_index(table_name: str, index_name: str) -> bool:
if not _has_table(table_name):
return False
return index_name in {
index["name"] for index in inspect(op.get_bind()).get_indexes(table_name)
}
def upgrade() -> None:
if not _has_table(_TABLE):
return
# Historical records must stay in the original personal mode. New records
# set this flag only when a route taskId explicitly requests sharing.
if not _has_column(_TABLE, "task_scoped"):
op.add_column(
_TABLE,
sa.Column(
"task_scoped",
sa.Boolean(),
nullable=False,
server_default=sa.false(),
),
)
if not _has_index(_TABLE, _INDEX):
op.create_index(_INDEX, _TABLE, ["external_task_id", "updated_at"])
def downgrade() -> None:
if not _has_table(_TABLE):
return
if _has_index(_TABLE, _INDEX):
op.drop_index(_INDEX, table_name=_TABLE)
if _has_column(_TABLE, "task_scoped"):
op.drop_column(_TABLE, "task_scoped")
@@ -57,6 +57,7 @@ from deerflow.persistence.positions.model import PositionRow, PositionTagBinding
from deerflow.persistence.recommended_questions.model import RecommendedQuestionRow
from deerflow.persistence.research_templates.model import ResearchTemplateRow
from deerflow.persistence.roundtable_chains.model import RoundtableChainRow
from deerflow.persistence.roundtable_artifact_submissions.model import RoundtableArtifactSubmissionRow
from deerflow.persistence.roundtable_diagnostics.model import RoundtableDiagnosticRow
from deerflow.persistence.roundtable_draft_shares.model import RoundtableDraftShareRow
from deerflow.persistence.roundtable_drafts.model import (
@@ -121,6 +122,7 @@ __all__ = [
"RecommendedQuestionRow",
"ResearchTemplateRow",
"RoundtableChainRow",
"RoundtableArtifactSubmissionRow",
"RoundtableDraftRow",
"RoundtableDraftShareRow",
"RoundtableDiagnosticRow",
@@ -12,7 +12,7 @@ from __future__ import annotations
from datetime import UTC, datetime
from sqlalchemy import ForeignKey, Integer, String, UniqueConstraint
from sqlalchemy import Boolean, ForeignKey, Index, Integer, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column
from deerflow.persistence.base import Base
@@ -21,12 +21,23 @@ from deerflow.persistence.types import BeijingDateTime, PortableLongText
class PositionRoundtableSessionRow(Base):
__tablename__ = "position_roundtable_sessions"
__table_args__ = (
# History is read as "all conversations for one task, newest first".
# `user_id` remains audit data only; it must not partition a shared
# task workspace.
Index(
"ix_position_roundtable_sessions_task_updated",
"external_task_id",
"updated_at",
),
)
id: Mapped[str] = mapped_column(String(64), primary_key=True)
# Phase one uses normal account isolation. A future membership / role ACL
# can be added without changing the session or thread identifiers.
# Creator audit field. `task_scoped`, not merely external_task_id, opts a
# session into sharing. This keeps historical sidebar/mock rows private.
user_id: Mapped[str] = mapped_column(String(64), nullable=False, index=True)
external_task_id: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
task_scoped: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False, server_default="0")
task_snapshot: Mapped[str | None] = mapped_column(PortableLongText, nullable=True)
chain_id: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
chain_snapshot: Mapped[str | None] = mapped_column(PortableLongText, nullable=True)
@@ -46,11 +46,17 @@ class PositionRoundtableRepository:
def __init__(self, session_factory: async_sessionmaker[AsyncSession]) -> None:
self._sf = session_factory
@staticmethod
def _can_access(row: PositionRoundtableSessionRow, user_id: str) -> bool:
"""Task-bound sessions are shared; unbound legacy sessions stay private."""
return bool(row.task_scoped) or row.user_id == user_id
@staticmethod
def _session_dict(row: PositionRoundtableSessionRow) -> dict[str, Any]:
return {
"id": row.id,
"external_task_id": row.external_task_id,
"task_scoped": bool(row.task_scoped),
"task_snapshot": _loads(row.task_snapshot) or {},
"chain_id": row.chain_id,
"chain_snapshot": _loads(row.chain_snapshot),
@@ -98,12 +104,14 @@ class PositionRoundtableRepository:
*,
external_task_id: str | None,
task_snapshot: dict[str, Any] | None,
task_scoped: bool | None = None,
) -> dict[str, Any]:
now = datetime.now(UTC)
row = PositionRoundtableSessionRow(
id=uuid4().hex,
user_id=user_id,
external_task_id=external_task_id or None,
task_scoped=bool(external_task_id) if task_scoped is None else task_scoped,
task_snapshot=_dumps(task_snapshot or {}),
status="intent_pending",
created_at=now,
@@ -165,7 +173,8 @@ class PositionRoundtableRepository:
row = PositionRoundtableSessionRow(
id=session_id,
user_id=user_id,
external_task_id=session_payload.get("external_task_id") or None,
external_task_id=str(session_payload.get("external_task_id") or "").strip() or None,
task_scoped=False,
task_snapshot=_dumps(session_payload.get("task_snapshot") or {}),
chain_id=session_payload.get("chain_id") or None,
chain_snapshot=_dumps(session_payload.get("chain_snapshot")),
@@ -246,9 +255,17 @@ class PositionRoundtableRepository:
async def list_sessions(
self, user_id: str, *, external_task_id: str | None = None, limit: int = 50
) -> list[dict[str, Any]]:
stmt = select(PositionRoundtableSessionRow).where(PositionRoundtableSessionRow.user_id == user_id)
"""List shared task history or the caller's legacy personal history."""
if external_task_id:
stmt = stmt.where(PositionRoundtableSessionRow.external_task_id == external_task_id)
stmt = select(PositionRoundtableSessionRow).where(
PositionRoundtableSessionRow.external_task_id == external_task_id,
PositionRoundtableSessionRow.task_scoped.is_(True),
)
else:
stmt = select(PositionRoundtableSessionRow).where(
PositionRoundtableSessionRow.user_id == user_id,
PositionRoundtableSessionRow.task_scoped.is_(False),
)
stmt = stmt.order_by(PositionRoundtableSessionRow.updated_at.desc()).limit(limit)
async with self._sf() as session:
rows = (await session.execute(stmt)).scalars().all()
@@ -257,7 +274,7 @@ class PositionRoundtableRepository:
async def get_session(self, session_id: str, user_id: str) -> dict[str, Any] | None:
async with self._sf() as session:
row = await session.get(PositionRoundtableSessionRow, session_id)
if row is None or row.user_id != user_id:
if row is None or not self._can_access(row, user_id):
return None
return self._session_dict(row)
@@ -280,7 +297,7 @@ class PositionRoundtableRepository:
) -> dict[str, Any] | None:
async with self._sf() as session:
row = await session.get(PositionRoundtableSessionRow, session_id)
if row is None or row.user_id != user_id:
if row is None or not self._can_access(row, user_id):
return None
if task_snapshot is not _UNSET:
row.task_snapshot = _dumps(task_snapshot)
@@ -326,7 +343,7 @@ class PositionRoundtableRepository:
now = datetime.now(UTC)
async with self._sf() as session:
row = await session.get(PositionRoundtableSessionRow, session_id)
if row is None or row.user_id != user_id:
if row is None or not self._can_access(row, user_id):
return None
node_rows = (
await session.execute(
@@ -371,7 +388,7 @@ class PositionRoundtableRepository:
async def list_nodes(self, session_id: str, user_id: str) -> list[dict[str, Any]] | None:
async with self._sf() as session:
parent = await session.get(PositionRoundtableSessionRow, session_id)
if parent is None or parent.user_id != user_id:
if parent is None or not self._can_access(parent, user_id):
return None
rows = (
await session.execute(
@@ -384,16 +401,13 @@ class PositionRoundtableRepository:
async def get_node(self, session_id: str, node_key: str, user_id: str) -> dict[str, Any] | None:
async with self._sf() as session:
stmt = (
select(PositionRoundtableNodeRow)
.join(PositionRoundtableSessionRow, PositionRoundtableSessionRow.id == PositionRoundtableNodeRow.session_id)
.where(
PositionRoundtableNodeRow.session_id == session_id,
PositionRoundtableNodeRow.node_key == node_key,
PositionRoundtableSessionRow.user_id == user_id,
)
.limit(1)
)
parent = await session.get(PositionRoundtableSessionRow, session_id)
if parent is None or not self._can_access(parent, user_id):
return None
stmt = select(PositionRoundtableNodeRow).where(
PositionRoundtableNodeRow.session_id == session_id,
PositionRoundtableNodeRow.node_key == node_key,
).limit(1)
row = (await session.execute(stmt)).scalars().first()
return self._node_dict(row) if row is not None else None
@@ -415,16 +429,13 @@ class PositionRoundtableRepository:
increment_rejection: bool = False,
) -> dict[str, Any] | None:
async with self._sf() as session:
stmt = (
select(PositionRoundtableNodeRow)
.join(PositionRoundtableSessionRow, PositionRoundtableSessionRow.id == PositionRoundtableNodeRow.session_id)
.where(
PositionRoundtableNodeRow.session_id == session_id,
PositionRoundtableNodeRow.node_key == node_key,
PositionRoundtableSessionRow.user_id == user_id,
)
.limit(1)
)
parent = await session.get(PositionRoundtableSessionRow, session_id)
if parent is None or not self._can_access(parent, user_id):
return None
stmt = select(PositionRoundtableNodeRow).where(
PositionRoundtableNodeRow.session_id == session_id,
PositionRoundtableNodeRow.node_key == node_key,
).limit(1)
row = (await session.execute(stmt)).scalars().first()
if row is None:
return None
@@ -472,7 +483,7 @@ class PositionRoundtableRepository:
now = datetime.now(UTC)
async with self._sf() as session:
parent = await session.get(PositionRoundtableSessionRow, session_id)
if parent is None or parent.user_id != user_id:
if parent is None or not self._can_access(parent, user_id):
return None
rows = (
await session.execute(
@@ -538,19 +549,18 @@ class PositionRoundtableRepository:
return await self.update_session(session_id, user_id, status="archived")
async def delete_session(self, session_id: str, user_id: str) -> bool:
"""Delete one user-owned history record and all of its node snapshots."""
"""Delete a task-shared row or the caller's personal legacy row."""
async with self._sf() as session:
parent = (
await session.execute(
select(PositionRoundtableSessionRow)
.where(
PositionRoundtableSessionRow.id == session_id,
PositionRoundtableSessionRow.user_id == user_id,
)
.limit(1)
)
).scalar_one_or_none()
if parent is None:
if parent is None or not self._can_access(parent, user_id):
return False
# Do not rely on database-specific FK cascade settings. SQLite
@@ -564,7 +574,6 @@ class PositionRoundtableRepository:
await session.execute(
delete(PositionRoundtableSessionRow).where(
PositionRoundtableSessionRow.id == session_id,
PositionRoundtableSessionRow.user_id == user_id,
)
)
await session.commit()
@@ -0,0 +1,22 @@
"""Task-scoped roundtable artifact submission status persistence."""
from __future__ import annotations
from deerflow.persistence.roundtable_artifact_submissions.base import RoundtableArtifactSubmissionStore
from deerflow.persistence.roundtable_artifact_submissions.memory import MemoryRoundtableArtifactSubmissionStore
from deerflow.persistence.roundtable_artifact_submissions.model import RoundtableArtifactSubmissionRow
from deerflow.persistence.roundtable_artifact_submissions.sql import RoundtableArtifactSubmissionRepository
__all__ = [
"MemoryRoundtableArtifactSubmissionStore",
"RoundtableArtifactSubmissionRepository",
"RoundtableArtifactSubmissionRow",
"RoundtableArtifactSubmissionStore",
"make_roundtable_artifact_submission_store",
]
def make_roundtable_artifact_submission_store(session_factory):
if session_factory is None:
return MemoryRoundtableArtifactSubmissionStore()
return RoundtableArtifactSubmissionRepository(session_factory)
@@ -0,0 +1,44 @@
"""Persistence contract for task-scoped roundtable artifact submissions.
The store deliberately keeps only a stable reference to an artifact in a
DeerFlow thread sandbox. It does not copy the artifact body and never calls a
downstream task-delivery service.
"""
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import Any
class RoundtableArtifactSubmissionStore(ABC):
"""Shared submission-status store, partitioned only by task id."""
@abstractmethod
async def list_by_task(self, task_id: str, *, submitted: bool | None = True) -> list[dict[str, Any]]:
"""Return artifact submission records for one task, newest first."""
raise NotImplementedError
@abstractmethod
async def submit(
self,
task_id: str,
artifact: dict[str, Any],
*,
task_delivery_id: str | None = None,
actor_id: str | None = None,
) -> dict[str, Any]:
"""Create or update the idempotent submission record for an artifact."""
raise NotImplementedError
@abstractmethod
async def cancel(
self,
task_id: str,
artifact: dict[str, Any],
*,
submission_id: str | None = None,
actor_id: str | None = None,
) -> dict[str, Any] | None:
"""Mark a submission as cancelled without deleting its audit record."""
raise NotImplementedError
@@ -0,0 +1,127 @@
"""In-memory roundtable artifact-submission store."""
from __future__ import annotations
from copy import deepcopy
from datetime import UTC, datetime
from hashlib import sha256
from typing import Any
from uuid import uuid4
from deerflow.persistence.roundtable_artifact_submissions.base import RoundtableArtifactSubmissionStore
from deerflow.persistence.types import BEIJING_TZ
def submission_key(task_id: str, artifact: dict[str, Any]) -> str:
"""Return the canonical server-owned idempotency key for an artifact."""
source_key = str(artifact["source_key"])
path = str(artifact["path"])
revision = int(artifact["revision"])
raw = "\x1f".join((task_id, source_key, path, str(revision)))
return sha256(raw.encode("utf-8")).hexdigest()
def _now() -> str:
return datetime.now(UTC).astimezone(BEIJING_TZ).isoformat()
def _artifact_values(artifact: dict[str, Any]) -> dict[str, Any]:
return {
"session_id": artifact.get("session_id"),
"thread_id": artifact.get("thread_id"),
"node_key": artifact.get("node_key"),
"source_key": artifact["source_key"],
"path": artifact["path"],
"name": artifact.get("name"),
"mime_type": artifact.get("mime_type"),
"revision": int(artifact["revision"]),
}
class MemoryRoundtableArtifactSubmissionStore(RoundtableArtifactSubmissionStore):
def __init__(self) -> None:
self._rows: dict[tuple[str, str], dict[str, Any]] = {}
async def list_by_task(self, task_id: str, *, submitted: bool | None = True) -> list[dict[str, Any]]:
rows = [row for row in self._rows.values() if row["task_id"] == task_id and (submitted is None or row["submitted"] is submitted)]
rows.sort(key=lambda row: row["updated_at"], reverse=True)
return deepcopy(rows)
async def submit(
self,
task_id: str,
artifact: dict[str, Any],
*,
task_delivery_id: str | None = None,
actor_id: str | None = None,
) -> dict[str, Any]:
key = submission_key(task_id, artifact)
row = self._rows.get((task_id, key))
values = _artifact_values(artifact)
if row is None:
now = _now()
row = {
"id": uuid4().hex,
"task_id": task_id,
"idempotency_key": key,
**values,
"task_delivery_id": task_delivery_id,
"submitted": True,
"submitted_at": now,
"cancelled_at": None,
"created_by": actor_id,
"updated_by": actor_id,
"submitted_by": actor_id,
"cancelled_by": None,
"created_at": now,
"updated_at": now,
}
self._rows[(task_id, key)] = row
return deepcopy(row)
changed = (
not row["submitted"]
or row.get("task_delivery_id") != task_delivery_id
or any(row.get(name) != value for name, value in values.items())
)
if changed:
now = _now()
row.update(values)
row.update(
{
"task_delivery_id": task_delivery_id,
"submitted": True,
"submitted_at": now,
"cancelled_at": None,
"updated_by": actor_id,
"submitted_by": actor_id,
"cancelled_by": None,
"updated_at": now,
}
)
return deepcopy(row)
async def cancel(
self,
task_id: str,
artifact: dict[str, Any],
*,
submission_id: str | None = None,
actor_id: str | None = None,
) -> dict[str, Any] | None:
key = submission_key(task_id, artifact)
row = self._rows.get((task_id, key))
if row is None or (submission_id is not None and row["id"] != submission_id):
return None
if row["submitted"]:
now = _now()
row.update(
{
"submitted": False,
"cancelled_at": now,
"updated_by": actor_id,
"cancelled_by": actor_id,
"updated_at": now,
}
)
return deepcopy(row)
@@ -0,0 +1,56 @@
"""ORM model for task-scoped roundtable artifact submission status."""
from __future__ import annotations
from datetime import UTC, datetime
from sqlalchemy import Boolean, Index, Integer, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column
from deerflow.persistence.base import Base
from deerflow.persistence.types import BeijingDateTime
class RoundtableArtifactSubmissionRow(Base):
"""One auditable submission state for one task artifact revision.
The natural idempotency key is a SHA-256 digest of
``task_id + source_key + artifact_path + revision``. Keeping the digest
short avoids a MySQL unique-index limit while the component columns remain
available for diagnostics and response shaping.
"""
__tablename__ = "roundtable_artifact_submissions"
__table_args__ = (
UniqueConstraint("task_id", "idempotency_key", name="uq_roundtable_artifact_submission_task_key"),
Index("ix_roundtable_artifact_submission_task_state_updated", "task_id", "submitted", "updated_at"),
)
id: Mapped[str] = mapped_column(String(64), primary_key=True)
task_id: Mapped[str] = mapped_column(String(128), nullable=False, index=True)
idempotency_key: Mapped[str] = mapped_column(String(64), nullable=False)
source_key: Mapped[str] = mapped_column(String(512), nullable=False)
artifact_path: Mapped[str] = mapped_column(String(2048), nullable=False)
revision: Mapped[int] = mapped_column(Integer, nullable=False)
session_id: Mapped[str | None] = mapped_column(String(128), nullable=True)
thread_id: Mapped[str | None] = mapped_column(String(128), nullable=True)
node_key: Mapped[str | None] = mapped_column(String(256), nullable=True)
artifact_name: Mapped[str | None] = mapped_column(String(512), nullable=True)
mime_type: Mapped[str | None] = mapped_column(String(255), nullable=True)
task_delivery_id: Mapped[str | None] = mapped_column(String(255), nullable=True)
submitted: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
submitted_at: Mapped[datetime | None] = mapped_column(BeijingDateTime(), nullable=True)
cancelled_at: Mapped[datetime | None] = mapped_column(BeijingDateTime(), nullable=True)
created_by: Mapped[str | None] = mapped_column(String(64), nullable=True)
updated_by: Mapped[str | None] = mapped_column(String(64), nullable=True)
submitted_by: Mapped[str | None] = mapped_column(String(64), nullable=True)
cancelled_by: Mapped[str | None] = mapped_column(String(64), nullable=True)
created_at: Mapped[datetime] = mapped_column(BeijingDateTime(), nullable=False, default=lambda: datetime.now(UTC))
updated_at: Mapped[datetime] = mapped_column(
BeijingDateTime(),
nullable=False,
default=lambda: datetime.now(UTC),
onupdate=lambda: datetime.now(UTC),
)
@@ -0,0 +1,188 @@
"""SQLAlchemy-backed task-scoped roundtable artifact-submission store."""
from __future__ import annotations
from datetime import UTC, datetime
from typing import Any
from uuid import uuid4
from sqlalchemy import select
from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
from deerflow.persistence.roundtable_artifact_submissions.base import RoundtableArtifactSubmissionStore
from deerflow.persistence.roundtable_artifact_submissions.memory import submission_key
from deerflow.persistence.roundtable_artifact_submissions.model import RoundtableArtifactSubmissionRow
def _timestamp(value: datetime | None) -> str | None:
return value.isoformat() if isinstance(value, datetime) else value
def _to_dict(row: RoundtableArtifactSubmissionRow) -> dict[str, Any]:
return {
"id": row.id,
"task_id": row.task_id,
"idempotency_key": row.idempotency_key,
"session_id": row.session_id,
"thread_id": row.thread_id,
"node_key": row.node_key,
"source_key": row.source_key,
"path": row.artifact_path,
"name": row.artifact_name,
"mime_type": row.mime_type,
"revision": row.revision,
"task_delivery_id": row.task_delivery_id,
"submitted": row.submitted,
"submitted_at": _timestamp(row.submitted_at),
"cancelled_at": _timestamp(row.cancelled_at),
"created_by": row.created_by,
"updated_by": row.updated_by,
"submitted_by": row.submitted_by,
"cancelled_by": row.cancelled_by,
"created_at": _timestamp(row.created_at),
"updated_at": _timestamp(row.updated_at),
}
def _apply_artifact(row: RoundtableArtifactSubmissionRow, artifact: dict[str, Any]) -> None:
row.session_id = artifact.get("session_id")
row.thread_id = artifact.get("thread_id")
row.node_key = artifact.get("node_key")
row.source_key = artifact["source_key"]
row.artifact_path = artifact["path"]
row.artifact_name = artifact.get("name")
row.mime_type = artifact.get("mime_type")
row.revision = int(artifact["revision"])
def _requires_submission_update(
row: RoundtableArtifactSubmissionRow,
artifact: dict[str, Any],
task_delivery_id: str | None,
) -> bool:
return (
not row.submitted
or row.task_delivery_id != task_delivery_id
or row.session_id != artifact.get("session_id")
or row.thread_id != artifact.get("thread_id")
or row.node_key != artifact.get("node_key")
or row.artifact_name != artifact.get("name")
or row.mime_type != artifact.get("mime_type")
)
class RoundtableArtifactSubmissionRepository(RoundtableArtifactSubmissionStore):
def __init__(self, session_factory: async_sessionmaker[AsyncSession]) -> None:
self._sf = session_factory
async def list_by_task(self, task_id: str, *, submitted: bool | None = True) -> list[dict[str, Any]]:
stmt = select(RoundtableArtifactSubmissionRow).where(RoundtableArtifactSubmissionRow.task_id == task_id)
if submitted is not None:
stmt = stmt.where(RoundtableArtifactSubmissionRow.submitted.is_(submitted))
stmt = stmt.order_by(RoundtableArtifactSubmissionRow.updated_at.desc())
async with self._sf() as session:
result = await session.execute(stmt)
return [_to_dict(row) for row in result.scalars()]
async def submit(
self,
task_id: str,
artifact: dict[str, Any],
*,
task_delivery_id: str | None = None,
actor_id: str | None = None,
) -> dict[str, Any]:
key = submission_key(task_id, artifact)
stmt = select(RoundtableArtifactSubmissionRow).where(
RoundtableArtifactSubmissionRow.task_id == task_id,
RoundtableArtifactSubmissionRow.idempotency_key == key,
)
async with self._sf() as session:
result = await session.execute(stmt)
row = result.scalars().first()
now = datetime.now(UTC)
created = row is None
if row is None:
row = RoundtableArtifactSubmissionRow(
id=uuid4().hex,
task_id=task_id,
idempotency_key=key,
task_delivery_id=task_delivery_id,
submitted=True,
submitted_at=now,
created_by=actor_id,
updated_by=actor_id,
submitted_by=actor_id,
created_at=now,
updated_at=now,
)
_apply_artifact(row, artifact)
session.add(row)
elif _requires_submission_update(row, artifact, task_delivery_id):
_apply_artifact(row, artifact)
row.task_delivery_id = task_delivery_id
row.submitted = True
row.submitted_at = now
row.cancelled_at = None
row.updated_by = actor_id
row.submitted_by = actor_id
row.cancelled_by = None
row.updated_at = now
try:
await session.commit()
except IntegrityError:
# Two callers can both observe a missing row. The unique key
# turns that race into a normal idempotent retry instead of a
# 500. If their non-key metadata differs, apply this request
# after loading the winner so PUT still has upsert semantics.
await session.rollback()
if not created:
raise
result = await session.execute(stmt)
row = result.scalars().first()
if row is None:
raise
if _requires_submission_update(row, artifact, task_delivery_id):
now = datetime.now(UTC)
_apply_artifact(row, artifact)
row.task_delivery_id = task_delivery_id
row.submitted = True
row.submitted_at = now
row.cancelled_at = None
row.updated_by = actor_id
row.submitted_by = actor_id
row.cancelled_by = None
row.updated_at = now
await session.commit()
await session.refresh(row)
return _to_dict(row)
async def cancel(
self,
task_id: str,
artifact: dict[str, Any],
*,
submission_id: str | None = None,
actor_id: str | None = None,
) -> dict[str, Any] | None:
key = submission_key(task_id, artifact)
stmt = select(RoundtableArtifactSubmissionRow).where(
RoundtableArtifactSubmissionRow.task_id == task_id,
RoundtableArtifactSubmissionRow.idempotency_key == key,
)
async with self._sf() as session:
result = await session.execute(stmt)
row = result.scalars().first()
if row is None or (submission_id is not None and row.id != submission_id):
return None
if row.submitted:
now = datetime.now(UTC)
row.submitted = False
row.cancelled_at = now
row.updated_by = actor_id
row.cancelled_by = actor_id
row.updated_at = now
await session.commit()
await session.refresh(row)
return _to_dict(row)
@@ -8,7 +8,7 @@ SKILL_MD_FILE = "SKILL.md"
class SkillCategory(StrEnum):
"""Source category for a skill.
- ``PUBLIC``: built-in skill bundled with the platform, read-only.
- ``PUBLIC``: built-in skill bundled with the platform; administrator-managed.
- ``CUSTOM``: user-authored skill that can be edited or deleted.
"""