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

@@ -82,8 +82,11 @@ import { listAgents } from "@/core/agents";
import { getStoredAuth } from "@/core/auth";
import {
POSITION_OPTIONS,
setRuntimePositionOptions,
type PositionOption,
type PositionId,
} from "@/position-roundtable/lib/positions";
import { usePositionRoles } from "@/strategy-components/api/position-roles";
import {
filterRecommendCandidates,
@@ -160,6 +163,33 @@ export default function BusinessChainEditorPage() {
// 岗位配置只由岗位协同页入口开启,普通圆桌编辑器完全不显示也不依赖该控件。
// `returnTo` 只接受站内绝对路径,避免把导航带往外部地址。
const positionConfigMode = searchParams.get("mode") === "position";
// This is the same directory the administrator edits in “岗位角色配置”.
// The editor used to read the static POSITION_OPTIONS array below, which
// meant a newly configured role never appeared in this seat dropdown.
const { data: configuredPositionRoles = [] } = usePositionRoles({
refreshOnMountOrFocus: positionConfigMode,
});
const positionOptions = useMemo<PositionOption[]>(
() =>
configuredPositionRoles.length > 0
? [...configuredPositionRoles]
.sort((left, right) => left.sortOrder - right.sortOrder)
.map((role) => ({
id: role.id,
name: role.name,
description: role.description,
isIntentPosition: role.roleType === "intent",
enabled: role.enabled,
isBuiltin: role.isBuiltin,
sortOrder: role.sortOrder,
}))
: [...POSITION_OPTIONS],
[configuredPositionRoles],
);
// Keep flow previews and historical seat labels on the same live directory.
useEffect(() => {
setRuntimePositionOptions(positionOptions);
}, [positionOptions]);
const requestedReturnTo = searchParams.get("returnTo");
const returnPath =
positionConfigMode && requestedReturnTo?.startsWith("/")
@@ -1244,6 +1274,7 @@ export default function BusinessChainEditorPage() {
onSeatSkillDirectiveChange={setSeatSkillDirectiveCb}
onSeatModeChange={setSeatModeCb}
positionConfigMode={positionConfigMode}
positionOptions={positionOptions}
onSeatPositionChange={setSeatPositionCb}
onStageGoalChange={setGoal}
goalOptimizingIdx={goalOptimizingIdx}
@@ -1426,6 +1457,7 @@ function StagesColumn({
onSeatSkillDirectiveChange,
onSeatModeChange,
positionConfigMode,
positionOptions,
onSeatPositionChange,
onStageGoalChange,
goalOptimizingIdx,
@@ -1447,6 +1479,8 @@ function StagesColumn({
onSeatModeChange: (agentId: string, mode: SeatMode | null) => void;
/** 仅岗位协同入口启用;普通圆桌编辑器不显示岗位控件。 */
positionConfigMode: boolean;
/** Live directory from the administrator's position-role configuration. */
positionOptions: readonly PositionOption[];
onSeatPositionChange: (agentId: string, positionId: PositionId | null) => void;
onStageGoalChange: (stageIdx: number, goal: string) => void;
/** 正在 AI 优化阶段目标的 stage 下标(null = 没有进行中的优化)。 */
@@ -1554,6 +1588,7 @@ function StagesColumn({
onSeatSkillDirectiveChange={onSeatSkillDirectiveChange}
onSeatModeChange={onSeatModeChange}
positionConfigMode={positionConfigMode}
positionOptions={positionOptions}
onSeatPositionChange={onSeatPositionChange}
onGoalChange={(goal) => onStageGoalChange(stageIdx, goal)}
goalOptimizing={goalOptimizingIdx === stageIdx}
@@ -1587,6 +1622,7 @@ function StageSection({
onSeatSkillDirectiveChange,
onSeatModeChange,
positionConfigMode,
positionOptions,
onSeatPositionChange,
onGoalChange,
goalOptimizing,
@@ -1609,6 +1645,7 @@ function StageSection({
onSeatSkillDirectiveChange: (agentId: string, enabled: boolean) => void;
onSeatModeChange: (agentId: string, mode: SeatMode | null) => void;
positionConfigMode: boolean;
positionOptions: readonly PositionOption[];
onSeatPositionChange: (agentId: string, positionId: PositionId | null) => void;
onGoalChange: (goal: string) => void;
/** 本 Stage 的阶段目标正在 AI 优化中。 */
@@ -1774,6 +1811,7 @@ function StageSection({
onSkillDirectiveChange={(enabled) => onSeatSkillDirectiveChange(seat.agent_id, enabled)}
onSeatModeChange={(mode) => onSeatModeChange(seat.agent_id, mode)}
showPositionConfig={positionConfigMode}
positionOptions={positionOptions}
onPositionChange={(positionId) => onSeatPositionChange(seat.agent_id, positionId)}
onDetail={() => onSeatDetail(seat.agent_id, seat.name)}
/>
@@ -1801,6 +1839,7 @@ function SeatStrip({
onSkillDirectiveChange,
onSeatModeChange,
showPositionConfig,
positionOptions,
onPositionChange,
onDetail,
}: {
@@ -1822,12 +1861,41 @@ function SeatStrip({
onSeatModeChange: (mode: SeatMode | null) => void;
/** 仅岗位协同入口展示的岗位配置。 */
showPositionConfig: boolean;
/** Current position directory, injected by the business-chain editor. */
positionOptions: readonly PositionOption[];
onPositionChange: (positionId: PositionId | null) => void;
onDetail: () => void;
}) {
const { attributes, listeners, setNodeRef, transform, transition, isDragging } =
useSortable({ id: SEAT_PREFIX + seat.agent_id });
const avatarType = getAvatarTypeFor(seat.agent_id, globalIndex);
const selectablePositionOptions = useMemo(() => {
const assignedId = seat.position_id ?? null;
const assigned = assignedId
? positionOptions.find((position) => position.id === assignedId)
: undefined;
const enabled = positionOptions.filter((position) => position.enabled !== false);
// Do not silently erase an archived configuration from a saved chain.
// It remains visible but cannot be selected for another seat.
const historical =
assignedId && (!assigned || assigned.enabled === false)
? [
{
label: assigned
? `${assigned.name}(已停用)`
: `${assignedId}(岗位已删除)`,
value: assignedId,
disabled: true,
},
]
: [];
return [
{ label: "未分配", value: "" },
...historical,
...enabled.map((position) => ({ label: position.name, value: position.id })),
];
}, [positionOptions, seat.position_id]);
return (
<div
ref={setNodeRef}
@@ -1880,13 +1948,7 @@ function SeatStrip({
<TSelect
size="small"
value={seat.position_id ?? ""}
options={[
{ label: "未分配", value: "" },
...POSITION_OPTIONS.map((position) => ({
label: position.name,
value: position.id,
})),
]}
options={selectablePositionOptions}
onChange={(value) =>
onPositionChange(value ? (String(value) as PositionId) : null)
}