From 7eb2933ca585726bef1c8a881ef005e10c927625 Mon Sep 17 00:00:00 2001 From: oudecheng <13802883547@139.com> Date: Tue, 7 Jul 2026 17:45:07 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=B8=85=E7=90=86=20P0=20=E6=8A=80?= =?UTF-8?q?=E6=9C=AF=E5=80=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 web/src/components/Sidebar/.deprecated 目录(死代码) - 清理 useChat.ts/useWebSocket.ts 中 13 条调试 console.log - 修复 load_task_messages.rs 硬编码 task 状态: 新增 TaskSessionState::Unknown, DB 重建时返回 Unknown 而非误报 Completed, 前端显示"未知" --- src/command/handlers/load_task_messages.rs | 13 +- src/tools/task/types.rs | 2 + web/src/App.tsx | 1 + .../Sidebar/.deprecated/ChannelSelector.tsx | 127 ------------------ .../Sidebar/.deprecated/SessionSelector.tsx | 114 ---------------- web/src/hooks/useChat.ts | 15 --- web/src/hooks/useWebSocket.ts | 1 - 7 files changed, 13 insertions(+), 260 deletions(-) delete mode 100644 web/src/components/Sidebar/.deprecated/ChannelSelector.tsx delete mode 100644 web/src/components/Sidebar/.deprecated/SessionSelector.tsx diff --git a/src/command/handlers/load_task_messages.rs b/src/command/handlers/load_task_messages.rs index f44a2f2..5ce620a 100644 --- a/src/command/handlers/load_task_messages.rs +++ b/src/command/handlers/load_task_messages.rs @@ -149,6 +149,15 @@ fn reconstruct_task_from_db( let now = record.updated_at; + // DB 未持久化 task 状态字段,无法可靠区分 Running/Completed/Failed/Timeout。 + // 用 Unknown 表示"重启后从 DB 重建,真实状态不可知",避免把 failed/timeout + // 误报为 Completed 误导用户。前端会把 Unknown 显示为"未知"。 + tracing::warn!( + task_id = %task_id, + session_id = %session_id, + "Reconstructing task from DB after restart; true state unknown, marking as Unknown" + ); + Ok(Some(TaskSession { id: task_id.to_string(), session_id, @@ -158,9 +167,7 @@ fn reconstruct_task_from_db( parent_channel_name: record.channel_name.clone(), description, subagent_type, - // TODO: DB 重建时无法可靠推断 task 状态,暂硬编码为 Completed。 - // 实际 failed/timeout 的子智能体会被错误显示为 completed,需独立跟进。 - state: TaskSessionState::Completed, + state: TaskSessionState::Unknown, created_at: record.created_at, updated_at: now, summary: None, diff --git a/src/tools/task/types.rs b/src/tools/task/types.rs index 8365510..0b8f76e 100644 --- a/src/tools/task/types.rs +++ b/src/tools/task/types.rs @@ -14,6 +14,8 @@ pub enum TaskSessionState { Failed, /// 已超时 Timeout, + /// 状态未知(如重启后从 DB 重建时无法可靠推断原状态) + Unknown, } impl Default for TaskSessionState { diff --git a/web/src/App.tsx b/web/src/App.tsx index cfb4bc1..2d85860 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -753,6 +753,7 @@ function App() { level.status === 'timeout' ? '超时' : level.status === 'running' ? '执行中' : level.status === 'loading' ? '加载中...' : + level.status === 'unknown' ? '未知' : level.status const statusColor = level.status === 'completed' ? 'text-emerald-400' : diff --git a/web/src/components/Sidebar/.deprecated/ChannelSelector.tsx b/web/src/components/Sidebar/.deprecated/ChannelSelector.tsx deleted file mode 100644 index 923e386..0000000 --- a/web/src/components/Sidebar/.deprecated/ChannelSelector.tsx +++ /dev/null @@ -1,127 +0,0 @@ -import { useState } from 'react' -import { Monitor, Smartphone, MessageSquare, Hash, ChevronDown, Eye, Pencil } from 'lucide-react' -import type { Channel } from '../../types/protocol' - -interface ChannelSelectorProps { - channels: Channel[] - selectedChannel: string | null - onSelectChannel: (channelId: string) => void -} - -const CHANNEL_ICONS: Record = { - cli: , - websocket: , - feishu: , - weixin: , - wechat: , -} - -export function ChannelSelector({ - channels, - selectedChannel, - onSelectChannel, -}: ChannelSelectorProps) { - const [isOpen, setIsOpen] = useState(false) - - const selected = channels.find((c) => c.id === selectedChannel) - - return ( -
- {/* Header */} -
-

- - 通道 -

-
- - {/* Channel Dropdown */} -
- - - {/* Dropdown Menu */} - {isOpen && ( - <> -
setIsOpen(false)} - /> -
- {channels.length === 0 ? ( -
- 暂无可用通道 -
- ) : ( - channels.map((channel) => ( - - )) - )} -
- - )} -
-
- ) -} diff --git a/web/src/components/Sidebar/.deprecated/SessionSelector.tsx b/web/src/components/Sidebar/.deprecated/SessionSelector.tsx deleted file mode 100644 index 69b375b..0000000 --- a/web/src/components/Sidebar/.deprecated/SessionSelector.tsx +++ /dev/null @@ -1,114 +0,0 @@ -import { useState } from 'react' -import { FolderOpen, ChevronDown, Hash } from 'lucide-react' -import type { Session } from '../../hooks/useChat' - -interface SessionSelectorProps { - sessions: Session[] - selectedSession: string | null - channelId: string // 使用 channelId 而不是 channelName - onSelectSession: (sessionId: string) => void -} - -export function SessionSelector({ - sessions, - selectedSession, - channelId, - onSelectSession, -}: SessionSelectorProps) { - const [isOpen, setIsOpen] = useState(false) - - const selected = sessions.find((s) => s.id === selectedSession) - - // 按通道 ID 筛选 Session - const channelSessions = sessions.filter( - (s) => s.channel_name === channelId - ) - - return ( -
- {/* Header */} -
-

- - Session -

-
- - {/* Session Dropdown */} -
- - - {/* Dropdown Menu */} - {isOpen && ( - <> -
setIsOpen(false)} - /> -
- {channelSessions.length === 0 ? ( -
- 暂无 Session -
- ) : ( - channelSessions.map((session, index) => ( - - )) - )} -
- - )} -
-
- ) -} diff --git a/web/src/hooks/useChat.ts b/web/src/hooks/useChat.ts index 027415b..4cb6522 100644 --- a/web/src/hooks/useChat.ts +++ b/web/src/hooks/useChat.ts @@ -497,8 +497,6 @@ export function useChat(): UseChatReturn { }, []) const handleServerMessage = useCallback((message: WsOutbound) => { - console.log('Received message:', message) - // Route to scheduler job view if active const currentSchedulerView = schedulerViewRef.current if (currentSchedulerView) { @@ -639,33 +637,27 @@ export function useChat(): UseChatReturn { case 'session_established': { const msg = message as SessionEstablished setConnectionId(msg.session_id) - console.log('Connection established:', msg.session_id) break } case 'task_started': { const msg = message as TaskStarted - console.log('[useChat] task_started received:', { task_id: msg.task_id, topic_id: msg.topic_id, parent_task_id: msg.parent_task_id, selectedTopic: selectedTopicRef.current }) // 只 backfill 当前话题的 task tool_call,避免跨话题串扰 if (msg.topic_id && msg.topic_id !== selectedTopicRef.current) { - console.log('[useChat] task_started filtered by topic_id') break } // 孙智能体的 TaskStarted 不应 backfill 到主视图 if (msg.parent_task_id) { - console.log('[useChat] task_started filtered by parent_task_id') break } // 设置 navigateToTaskId,让用户可以点击查看实时进度 setMessages((prev) => { - console.log('[useChat] task_started searching messages for task tool_call, total messages:', prev.length, 'tool_call_id:', msg.tool_call_id) // 优先:按 tool_call_id 精确匹配 if (msg.tool_call_id) { const idx = prev.findIndex(m => m.toolCallId === msg.tool_call_id && m.type === 'tool_call' && m.toolName === 'task') if (idx >= 0 && !prev[idx].navigateToTaskId) { - console.log('[useChat] task_started EXACT MATCH at index', idx, 'task_id:', msg.task_id) const updated = [...prev] updated[idx] = { ...updated[idx], navigateToTaskId: msg.task_id } return updated @@ -674,13 +666,11 @@ export function useChat(): UseChatReturn { // 回退:backward-search (兼容无 tool_call_id 的旧版本) for (let i = prev.length - 1; i >= 0; i--) { if (prev[i].type === 'tool_call' && prev[i].toolName === 'task' && !prev[i].navigateToTaskId) { - console.log('[useChat] task_started BACKWARD MATCH at index', i, 'task_id:', msg.task_id) const updated = [...prev] updated[i] = { ...updated[i], navigateToTaskId: msg.task_id } return updated } } - console.log('[useChat] task_started NO matching task tool_call found in messages') return prev }) break @@ -688,8 +678,6 @@ export function useChat(): UseChatReturn { case 'session_list': { const msg = message as SessionList - console.log('Session list received:', msg) - // 清空旧数据(切换通道时避免数据污染) setTopics([]) setSelectedTopic(null) @@ -723,8 +711,6 @@ export function useChat(): UseChatReturn { case 'topic_list': { const msg = message as TopicList - console.log('Topic list received:', msg) - // 转换 topics 格式 const newTopics: Topic[] = msg.topics.map((t: TopicSummary) => ({ id: t.topic_id, @@ -955,7 +941,6 @@ export function useChat(): UseChatReturn { case 'channel_list': { const msg = message as ChannelList - console.log('Channel list received:', msg) setChannels(msg.channels) break } diff --git a/web/src/hooks/useWebSocket.ts b/web/src/hooks/useWebSocket.ts index 88ce2c4..9fc082e 100644 --- a/web/src/hooks/useWebSocket.ts +++ b/web/src/hooks/useWebSocket.ts @@ -114,7 +114,6 @@ export function useWebSocket({ useEffect(() => { // 首次挂载,或者 url 发生了变化,都要重连 if (prevUrlRef.current !== url) { - console.log(`WebSocket URL changed: ${prevUrlRef.current} → ${url}`) // 先断开旧连接 disconnect() prevUrlRef.current = url