Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): clear stale run ownership on send
Dash90a5058edfc3
diff --git a/apps/desktop/src/renderer/__tests__/sessionStartingStore.test.ts b/apps/desktop/src/renderer/__tests__/sessionStartingStore.test.tsindex 21202d6ff8..96640b6aa9 100644--- a/apps/desktop/src/renderer/__tests__/sessionStartingStore.test.ts+++ b/apps/desktop/src/renderer/__tests__/sessionStartingStore.test.ts@@ -16,16 +16,27 @@ import {resetSessionStartingStoreForTests,SESSION_STARTING_TTL_MS,} from '@/lib/sessionStartingStore';+import {+ isSessionDoneSilenced,+ isSessionTerminalNotificationOwnedByScheduler,+ markNextSessionDoneSilenced,+ markNextSessionTerminalNotificationOwnedByScheduler,+ resetSilencedSessionDoneStoreForTests,+ scheduleClearSchedulerOwnedRun,+ scheduleClearSilencedRun,+} from '@/lib/silencedSessionDoneStore';describe('sessionStartingStore', () => {beforeEach(() => {resetSessionStartingStoreForTests();+ resetSilencedSessionDoneStoreForTests();clearRemoteSessionActivity();vi.useFakeTimers();});afterEach(() => {resetSessionStartingStoreForTests();+ resetSilencedSessionDoneStoreForTests();clearRemoteSessionActivity();vi.useRealTimers();});@@ -78,6 +89,22 @@ describe('sessionStartingStore', () => {expect([...getStartingSessionIds()]).toEqual([]);});+ it('clears only terminal-linger run markers on the first starting mark', () => {+ markNextSessionDoneSilenced('old-silent-run', 's1');+ markNextSessionTerminalNotificationOwnedByScheduler('old-owned-run', 's1');+ scheduleClearSilencedRun('old-silent-run', 2_000);+ scheduleClearSchedulerOwnedRun('old-owned-run', 2_000);++ markSessionStarting('s1');++ expect(isSessionDoneSilenced('s1')).toBe(false);+ expect(isSessionTerminalNotificationOwnedByScheduler('s1')).toBe(false);++ markNextSessionTerminalNotificationOwnedByScheduler('current-run', 's2');+ markSessionStarting('s2');+ expect(isSessionTerminalNotificationOwnedByScheduler('s2')).toBe(true);+ });+it('expires a starting mark that never becomes running', () => {markSessionStarting('stuck');vi.advanceTimersByTime(SESSION_STARTING_TTL_MS - 1);diff --git a/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts b/apps/desktop/src/renderer/hooks/useSessionRunningStatus.tsindex e30446f775..8562e73cda 100644--- a/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts+++ b/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts@@ -48,8 +48,7 @@ import {useSessionAttentionSnapshot,} from '@/lib/sessionAttentionStore';import {- clearCompletedSchedulerOwnedRunForNewActivity,- clearCompletedSilencedRunForNewActivity,+ clearCompletedRunMarkersForNewActivity,isSessionTerminalNotificationOwnedByScheduler,isSessionDoneSilenced,} from '@/lib/silencedSessionDoneStore';@@ -210,8 +209,7 @@ export function useSessionRunningStatus(// 只清「run 已终态」的标记(用户手动起的新对话或下一个 run);run 还在跑时// 是 subagent 续 turn / silent-stop 自动续跑,标记必须留着。兜底定时器不在// 这里动 —— 统一由本 effect 末尾的对账按当前 running 状态处理。- clearCompletedSilencedRunForNewActivity(sessionId);- clearCompletedSchedulerOwnedRunForNewActivity(sessionId);+ clearCompletedRunMarkersForNewActivity(sessionId);// error 红角标与真实错误态同步:新 turn 启动会清掉 store 的终止错误// (staleErrorClearedOnTurnStart),若此时角标还是 'error' 就成了 orphan——// 活跃会话的 done 分支不覆写它,角标会永久残留。错误已不存在,这里显式清除diff --git a/apps/desktop/src/renderer/lib/sessionStartingStore.ts b/apps/desktop/src/renderer/lib/sessionStartingStore.tsindex 1e3e1776ba..d8a58d48b5 100644--- a/apps/desktop/src/renderer/lib/sessionStartingStore.ts+++ b/apps/desktop/src/renderer/lib/sessionStartingStore.ts@@ -15,6 +15,7 @@import { useEffect, useSyncExternalStore } from 'react';import { dropStaleRemoteTerminalActivity } from '@/features/device-link/remoteSessionActivityStore';+import { clearCompletedRunMarkersForNewActivity } from '@/lib/silencedSessionDoneStore';/** 发送失败 / 状态一直不到时的兜底;正常路径应在 agent 开跑时就被吸收。 */export const SESSION_STARTING_TTL_MS = 120_000;@@ -53,8 +54,11 @@ export function markSessionStarting(sessionId: string): void {if (!sessionId) return;const already = startingIds.has(sessionId);if (!already) {- // 先丢掉上一轮远程终态,再置 starting。否则 absorb 会把旧 completed/error- // 当成新权威立刻清掉。重复 mark 只刷新 TTL,不能再删本轮新到达的终态。+ // starting 是早于真实 running 的新 activity 边界。先清上一轮已终态 marker,+ // 避免它在 linger 内把本轮准备失败误认成 scheduler-owned / silenced;仍在+ // 飞行的 marker 没有 linger timer,不会被清。重复 mark 只刷新 TTL,不能再+ // 删除本轮后续建立的新 run marker 或新到达的远程终态。+ clearCompletedRunMarkersForNewActivity(sessionId);dropStaleRemoteTerminalActivity(sessionId);startingIds.add(sessionId);}diff --git a/apps/desktop/src/renderer/lib/silencedSessionDoneStore.ts b/apps/desktop/src/renderer/lib/silencedSessionDoneStore.tsindex 8c14dacaf6..fe1763ed6d 100644--- a/apps/desktop/src/renderer/lib/silencedSessionDoneStore.ts+++ b/apps/desktop/src/renderer/lib/silencedSessionDoneStore.ts@@ -17,7 +17,7 @@* 次真 done 会当成普通完成,把 macOS toast / 飞书 / 手机推送全发一遍。** 清除只有三条路径:scheduler 的 completed / failed / notified 事件、run 已终态后该- * session 又起新 turn、以及对账权威 run 状态(`reconcileRunMarkers`,治事件丢失)。前两条+ * session 又起新 activity、以及对账权威 run 状态(`reconcileRunMarkers`,治事件丢失)。前两条* 与第三条统一走 `MARKER_TERMINAL_LINGER_MS` 的退场窗口。main 侧灵动岛* (`main/agent-island/service.ts` 的 `isCompletionEventSilenced`)是同一套语义,* 两边不要再分叉。@@ -231,7 +231,7 @@ export function clearSchedulerOwnedRun(runId: string): string | undefined {}/**- * run 已终态(completed/failed 排了 linger)后该 session 又起新 turn:那是用户手动+ * run 已终态(completed/failed 排了 linger)后该 session 又起新 activity:那是用户手动* 对话或下一个 run,立刻交回普通通知路径。run 还在跑时不清 —— 判据是* `schedulerOwnedClearTimers` 有没有 linger 定时器,而不是任何时间或 running 推断。*/@@ -258,6 +258,16 @@ export function clearCompletedSilencedRunForNewActivity(sessionId: string): voidclearSilencedRun(runId);}+/**+ * 新 activity 的统一边界。starting 在真实 running 之前调用,因此也覆盖附件准备+ * 失败等永远不会进入 running 的尝试;仍在飞行的 marker 没有 linger timer,+ * 两个 clear 函数都会保持它。+ */+export function clearCompletedRunMarkersForNewActivity(sessionId: string): void {+ clearCompletedSilencedRunForNewActivity(sessionId);+ clearCompletedSchedulerOwnedRunForNewActivity(sessionId);+}+export function clearSilencedRun(runId: string): string | undefined {clearPendingTimer(runId);const sessionId = silencedRunSessionIds.get(runId);@@ -314,4 +324,3 @@ function clearSchedulerOwnedTimer(runId: string | undefined): void {-