fix: avoid MySQL thread_meta refresh races and harden roundtable bootstrap

Skip post-commit ORM refresh on threads_meta creates so concurrent MySQL
read/write-split deployments no longer fail with Could not refresh instance;
clean up partial roundtable threads on checkpoint failure, and ship related
position-roundtable/frontend build fixes.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
董宏凯andCursor committed 2026-07-31 21:00:56 +08:00
1 parent e52261fc3d
commit a9d66536c3
12 files changed
+503 -127

No files matched your search

@@ -30,6 +30,12 @@ class ThreadMetaStore(abc.ABC):
display_name: str | None = None,
metadata: dict | None = None,
) -> dict:
"""Create one metadata row.
Implementations must assemble the returned dict from the values passed
in, without a post-commit read-back: on MySQL such a read can be routed
to a lagging replica behind a read/write-splitting endpoint and fail.
"""
pass
@abc.abstractmethod
@@ -45,6 +45,7 @@ class ThreadMetaRepository(ThreadMetaStore):
assistant_id=assistant_id,
user_id=resolved_user_id,
display_name=display_name,
status="idle",
metadata_json=metadata or {},
created_at=now,
updated_at=now,
@@ -52,7 +53,14 @@ class ThreadMetaRepository(ThreadMetaStore):
async with self._sf() as session:
session.add(row)
await session.commit()
await session.refresh(row)
# Deliberately no session.refresh(): every column above is assigned
# explicitly and the session factory uses expire_on_commit=False, so
# the in-memory row is already complete. The re-SELECT would run on a
# different pooled connection than the INSERT, which a MySQL
# read/write-splitting endpoint can route to a lagging replica --
# the row comes back empty and SQLAlchemy raises
# "Could not refresh instance". Concurrency makes that far more
# likely, so a single-user deployment never sees it.
return self._row_to_dict(row)
async def get(