Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(goal): 修复运行中开启目标被旧轮结束误暂停 (#5595)
Dashd985aa9c0e02
diff --git a/apps/desktop/src/main/goal-host/__tests__/controller.test.ts b/apps/desktop/src/main/goal-host/__tests__/controller.test.tsindex a38ea672c7..d35fb01513 100644--- a/apps/desktop/src/main/goal-host/__tests__/controller.test.ts+++ b/apps/desktop/src/main/goal-host/__tests__/controller.test.ts@@ -1,4 +1,6 @@import { describe, expect, it, beforeEach, vi } from 'vitest';+import { readFileSync } from 'node:fs';+import { ScriptTarget, transpileModule } from 'typescript';import { TurnDispatchUnconfirmedError } from '@cindy/maker-core';import type { AgentEvent, SessionSendResult } from '@cindy/maker-core';@@ -15,6 +17,7 @@ import {} from '../controller';import { buildContinuationDirective, buildFirstTurnDirective } from '../directive';import { MAX_CONSECUTIVE_OVERLOAD_TURNS } from '../usageLimit';+import { publishUiSessionIntervention, resetUiContinuationListenersForTest } from '../../maker-ipc/uiContinuationSignal';import type {AccountLimitInfo,GoalCompletionSummary,@@ -26,6 +29,59 @@ import type {SessionLike,} from '../types';+// Execute the shared production steer closure with in-memory host dependencies.+// This covers INPUT_STEER and the legacy STEER path without booting Electron.+const registerSource = readFileSync(new URL('../../maker-ipc/register.ts', import.meta.url), 'utf8');+const steerSource = registerSource.slice(+ registerSource.indexOf(' const steerToAgentAccepted = async ('),+ registerSource.indexOf(' const trustedDesktopSteerText ='),+);+const compiledSteer = transpileModule(`${steerSource}\nreturn steerToAgentAccepted;`, {+ compilerOptions: { target: ScriptTarget.ES2022 },+}).outputText;++function productionSteer(session: FakeSession, deliver: () => Promise<void>, rejectBeforeDelivery = false) {+ const query = { from: () => query, leftJoin: () => query, where: () => query, limit: async () => [] };+ const deps = {+ maker: {+ getSession: () => ({+ ...session,+ capabilities: { sameTurnSteer: { supported: true } },+ isTurnRunning: () => session.running,+ getTurnGeneration: () => session.generation,+ steer: deliver,+ }),+ getSessionMeta: async () => null,+ },+ getDbClient: () => ({ drizzle: { select: () => query } }),+ sessions: {}, botSessionLinks: {}, botProfiles: {}, eq: () => undefined,+ assertReviewExternalInputAllowed: async () => {},+ botSessionInputBlockReason: () => null,+ prepareUserMessageForAgent: async (_id: string, message: unknown) => message,+ restoreAutoReviewSteerIntent: async () => undefined,+ shouldPrependMobileClientPromptNote: () => false,+ readWireSourceDevice: () => null,+ isDeviceLinkInvoke: () => false,+ assertRemoteInputClearNotInFlight: () => {},+ readRemoteInputClearBoundaryPrecondition: () => ({ present: false }),+ readExpectedInputGeneration: () => undefined,+ assertCurrentInputGeneration: () => {+ if (rejectBeforeDelivery) throw new Error('stale input generation');+ },+ MAIN_OWNED_SEND_CONTEXT: Symbol(), AUTO_REVIEW_SOURCE_CONTENT: Symbol(),+ AUTO_REVIEW_DELEGATED_CONTINUATION: Symbol(), AUTO_REVIEW_USER_INTENT: Symbol(),+ publishUiSessionIntervention,+ summarizeIpcUserMessage: () => ({}),+ log: { info: () => {}, warn: () => {}, debug: () => {} },+ throwIpcError: (code: string, message: string) => { throw new Error(`${code}: ${message}`); },+ };+ // Keep Session identity stable across the production preflight checks.+ const live = deps.maker.getSession();+ deps.maker.getSession = () => live;+ return new Function(...Object.keys(deps), compiledSteer)(...Object.values(deps)) as+ (sessionId: string, message: string) => Promise<void>;+}+// ── decideNextGoalState (pure) ───────────────────────────────────────────────const BASE: GoalCounters = {@@ -228,6 +284,11 @@ class FakeSession implements SessionLike {readonly sends: Array<{ content: string; originKind?: string }> = [];private listener: ((event: AgentEvent) => void) | null = null;running = false;+ generation = 0;++ getTurnGeneration(): number {+ return this.generation;+ }constructor(id: string, agentKind: SessionLike['agentKind'] = 'claude-code') {this.id = id;@@ -414,6 +475,7 @@ function startGoal(h: ReturnType<typeof makeController>, objective = 'make testsdescribe('GoalController', () => {let h: ReturnType<typeof makeController>;beforeEach(() => {+ resetUiContinuationListenersForTest();h = makeController();});@@ -1951,6 +2013,206 @@ describe('GoalController', () => {expect(h.userMessages.filter((m) => m.content === 'think about it').length).toBe(1);});+ it.each([false, true])('waits for the pre-existing user turn without counting its output (previous Stop: %s)', async (previousStop) => {+ if (previousStop) await h.controller.pauseGoal('s1');+ h.session.generation = 7;+ h.session.running = true;+ await startGoal(h);+ const oldEvent = (event: AgentEvent) => h.session.emit({ ...event, sessionTurnGeneration: 7 });+ oldEvent({ type: 'tool_use', data: { name: 'Bash' } });+ oldEvent({ type: 'text', data: { text: '```json\n{"goal_status":"complete"}\n```', isFinal: true } });+ oldEvent({ type: 'status', data: { isRunning: false, tokenUsage: 900 } });+ // An SDK continuation boundary is not the end of the old product turn.+ oldEvent({ type: 'done', data: {}, turnContinuationId: 1 });+ await tick();+ expect(h.session.sends).toHaveLength(0);++ h.session.running = false;+ oldEvent({ type: 'done', data: {} });+ await vi.waitFor(() => expect(h.session.sends).toHaveLength(1));+ expect(h.session.sends[0].content).toContain('[Goal] Work autonomously');+ expect(await h.storage.get('s1')).toMatchObject({+ status: 'active', turnsUsed: 0, tokensUsed: 0, noProgressStreak: 0, lastReason: null,+ });+ expect(h.userMessages).toHaveLength(1);+ expect(h.completions).toHaveLength(0);++ // A late duplicate cannot pause the newly dispatched Goal turn either.+ oldEvent({ type: 'done', data: {} });+ await tick();+ expect(h.session.sends).toHaveLength(1);+ h.session.emitGoalTurn({ tokens: 12, verdictJson: '{"goal_status":"continue"}' });+ await vi.waitFor(() => expect(h.session.sends).toHaveLength(2));+ expect(await h.storage.get('s1')).toMatchObject({ turnsUsed: 1, tokensUsed: 12, noProgressStreak: 1 });+ await h.controller.dispose();+ });++ it.each([false, true])('preserves pending clear before creating a Goal (Stop again: %s)', async (stopAgain) => {+ let releaseClear!: () => void;+ const blockedClear = new Promise<void>((resolve) => { releaseClear = resolve; });+ const clear = h.storage.clear.bind(h.storage);+ const clearSpy = vi.spyOn(h.storage, 'clear').mockImplementation(async (sessionId) => {+ await blockedClear;+ await clear(sessionId);+ });+ const clearing = h.controller.clearGoal('s1');+ await vi.waitFor(() => expect(clearSpy).toHaveBeenCalledOnce());+ h.session.generation = 7;+ h.session.running = true;+ const upsertSpy = vi.spyOn(h.storage, 'upsert');+ const creating = startGoal(h);+ await tick();+ expect(upsertSpy).not.toHaveBeenCalled();+ const stopping = stopAgain ? h.controller.pauseGoal('s1') : Promise.resolve();+ releaseClear();+ await Promise.all([clearing, creating, stopping]);+ h.session.running = false;+ h.session.emit({ type: 'done', data: {}, sessionTurnGeneration: 7 });+ if (stopAgain) {+ await tick();+ expect(upsertSpy).not.toHaveBeenCalled();+ expect(await h.storage.get('s1')).toBeNull();+ expect(h.session.sends).toHaveLength(0);+ } else {+ await vi.waitFor(() => expect(h.session.sends).toHaveLength(1));+ expect(await h.storage.get('s1')).toMatchObject({ status: 'active', turnsUsed: 0 });+ }+ await h.controller.dispose();+ });++ it.each(['pause', 'clear', 'dispose'] as const)(+ 'does not start a Goal after %s while the pre-existing turn is running', async (action) => {+ await h.controller.pauseGoal('s1');+ h.session.generation = 7;+ h.session.running = true;+ await startGoal(h);+ if (action === 'pause') await h.controller.pauseGoal('s1');+ else if (action === 'clear') await h.controller.clearGoal('s1');+ else await h.controller.dispose();+ h.session.running = false;+ h.session.emit({ type: 'done', data: {}, sessionTurnGeneration: 7 });+ await tick();+ expect(h.session.sends).toHaveLength(0);+ if (action === 'pause') expect((await h.storage.get('s1'))?.status).toBe('paused');+ if (action === 'clear') expect(await h.storage.get('s1')).toBeNull();+ await h.controller.dispose();+ },+ );++ it.each(['same-turn steer', 'new turn'] as const)(+ 'still pauses for a new user message after Goal creation (%s)', async (delivery) => {+ await h.controller.pauseGoal('s1');+ h.session.generation = 7;+ h.session.running = true;+ await startGoal(h);+ if (delivery === 'same-turn steer') publishUiSessionIntervention('s1');+ else h.session.generation = 8;+ h.session.running = false;+ h.session.emit({ type: 'done', data: {}, sessionTurnGeneration: h.session.generation });+ await vi.waitFor(async () => expect((await h.storage.get('s1'))?.status).toBe('paused'));+ expect((await h.storage.get('s1'))?.lastReason).toBe('paused: user sent a message during the goal');+ expect(h.session.sends).toHaveLength(0);+ await h.controller.dispose();+ },+ );++ it.each([false, true])('uses the production steer boundary before a pre-existing turn ends (rejected: %s)', async (rejected) => {+ h.session.generation = 7;+ h.session.running = true;+ await startGoal(h);+ const finishOldTurn = () => {+ h.session.running = false;+ h.session.emit({ type: 'done', data: {}, sessionTurnGeneration: 7 });+ };+ const deliver = vi.fn(async () => {+ // The vendor can emit done before acknowledging the steer RPC.+ finishOldTurn();+ await tick();+ });+ const steer = productionSteer(h.session, deliver, rejected);+ if (rejected) {+ await expect(steer('s1', 'new direction')).rejects.toThrow('stale input generation');+ expect(deliver).not.toHaveBeenCalled();+ finishOldTurn();+ await vi.waitFor(() => expect(h.session.sends).toHaveLength(1));+ expect((await h.storage.get('s1'))?.status).toBe('active');+ } else {+ await steer('s1', 'new direction');+ expect(deliver).toHaveBeenCalledOnce();+ await vi.waitFor(async () => expect((await h.storage.get('s1'))?.status).toBe('paused'));+ expect(h.session.sends).toHaveLength(0);+ }+ await h.controller.dispose();+ });++ it.each(['new turn', 'same-turn steer'] as const)(+ 'does not exempt input that arrives during Goal persistence (%s)', async (delivery) => {+ h.session.generation = 7;+ h.session.running = true;+ const upsert = h.storage.upsert.bind(h.storage);+ vi.spyOn(h.storage, 'upsert').mockImplementation(async (state) => {+ if (delivery === 'new turn') h.session.generation = 8;+ else publishUiSessionIntervention('s1');+ await upsert(state);+ });+ await startGoal(h);+ h.session.running = false;+ h.session.emit({ type: 'done', data: {}, sessionTurnGeneration: h.session.generation });+ await vi.waitFor(async () => expect((await h.storage.get('s1'))?.status).toBe('paused'));+ expect(h.session.sends).toHaveLength(0);+ await h.controller.dispose();+ },+ );++ it('does not confuse a replacement Session with the same generation for the pre-existing turn', async () => {+ const replacement = new FakeSession('s1');+ replacement.generation = 7;+ replacement.running = true;+ let live: FakeSession;+ const local = makeController({+ getSession: () => live,+ ensureSession: async () => (live = replacement),+ });+ live = local.session;+ live.generation = 7;+ live.running = true;+ await startGoal(local);+ replacement.running = false;+ replacement.emit({ type: 'done', data: {}, sessionTurnGeneration: 7 });+ await vi.waitFor(async () => expect((await local.storage.get('s1'))?.status).toBe('paused'));+ expect(replacement.sends).toHaveLength(0);+ await local.controller.dispose();+ });++ it('starts the first Goal turn if the pre-existing turn ends before the listener is attached', async () => {+ h.session.generation = 7;+ h.session.running = true;+ const upsert = h.storage.upsert.bind(h.storage);+ vi.spyOn(h.storage, 'upsert').mockImplementation(async (state) => {+ h.session.running = false;+ h.session.emit({ type: 'done', data: {}, sessionTurnGeneration: 7 });+ await upsert(state);+ });+ await startGoal(h);+ expect(h.session.sends).toHaveLength(1);+ expect((await h.storage.get('s1'))?.status).toBe('active');+ await h.controller.dispose();+ });++ it('keeps terminal errors of the pre-existing turn on the existing stop path', async () => {+ h.session.generation = 7;+ h.session.running = true;+ await startGoal(h);+ h.session.running = false;+ h.session.emit({+ type: 'error', data: { isTerminal: true, message: 'AbortError: aborted' },+ sessionTurnGeneration: 7,+ });+ await vi.waitFor(async () => expect((await h.storage.get('s1'))?.status).toBe('paused'));+ expect(h.session.sends).toHaveLength(0);+ await h.controller.dispose();+ });+it('continues to a second turn when the verdict is continue', async () => {await startGoal(h);h.session.emitGoalTurn({ toolUse: true, verdictJson: '```json\n{"goal_status":"continue","reason":"wip"}\n```', tokens: 100 });@@ -2615,7 +2877,14 @@ describe('GoalController', () => {expect(local.updates.at(-1)).toEqual({ sessionId: 's1', goal: null });});- it('waits for an old completion clear before creating a replacement Goal', async () => {+ it.each([+ { previousStop: false, intervention: 'none' },+ { previousStop: true, intervention: 'none' },+ { previousStop: false, intervention: 'same-turn steer' },+ { previousStop: false, intervention: 'new turn' },+ { previousStop: false, intervention: 'pause' },+ { previousStop: false, intervention: 'clear' },+ ] as const)('waits for an old completion clear before creating a replacement Goal ($previousStop, $intervention)', async ({ previousStop, intervention }) => {const local = makeController();const originalClear = local.storage.clear.bind(local.storage);let clearCalls = 0;@@ -2635,7 +2904,9 @@ describe('GoalController', () => {verdictJson: '```json\n{"goal_status":"complete","reason":"done"}\n```',});await vi.waitFor(() => expect(clearCalls).toBe(1));- await local.controller.pauseGoal('s1');+ if (previousStop) await local.controller.pauseGoal('s1');+ local.session.generation = 7;+ local.session.running = true;let replacementSettled = false;const replacement = local.controller.setGoal({@@ -2645,9 +2916,24 @@ describe('GoalController', () => {void replacement.then(() => { replacementSettled = true; });await tick();expect(replacementSettled).toBe(false);- expect((await local.storage.get('s1'))?.status).toBe('paused');+ expect((await local.storage.get('s1'))?.status).toBe(previousStop ? 'paused' : 'active');+ if (intervention === 'same-turn steer') publishUiSessionIntervention('s1');+ if (intervention === 'new turn') local.session.generation = 8;+ const stopping = intervention === 'pause' ? local.controller.pauseGoal('s1')+ : intervention === 'clear' ? local.controller.clearGoal('s1') : Promise.resolve();releaseClear();+ await stopping;+ if (intervention === 'pause' || intervention === 'clear') {+ await expect(replacement).resolves.toBeNull();+ local.session.running = false;+ local.session.emit({ type: 'done', data: {}, sessionTurnGeneration: 7 });+ await tick();+ expect(local.session.sends).toHaveLength(1);+ expect(await local.storage.get('s1')).toBeNull();+ await local.controller.dispose();+ return;+ }await expect(replacement).resolves.toMatchObject({status: 'active',objective: 'replacement objective',@@ -2660,6 +2946,18 @@ describe('GoalController', () => {status: 'active',objective: 'replacement objective',});+ expect(local.session.sends).toHaveLength(1);+ local.session.running = false;+ local.session.emit({ type: 'done', data: {}, sessionTurnGeneration: local.session.generation });+ if (intervention === 'none') {+ await vi.waitFor(() => expect(local.session.sends).toHaveLength(2));+ expect(await local.storage.get('s1')).toMatchObject({ status: 'active', turnsUsed: 0 });+ } else {+ await vi.waitFor(async () => expect((await local.storage.get('s1'))?.status).toBe('paused'));+ expect(local.session.sends).toHaveLength(1);+ expect((await local.storage.get('s1'))?.lastReason).toBe('paused: user sent a message during the goal');+ }+ await local.controller.dispose();});it('resumeGoal resumes a paused goal: preserves counters, fires a continuation', async () => {diff --git a/apps/desktop/src/main/goal-host/controller.ts b/apps/desktop/src/main/goal-host/controller.tsindex fb906d9b0d..9f1e81823e 100644--- a/apps/desktop/src/main/goal-host/controller.ts+++ b/apps/desktop/src/main/goal-host/controller.ts@@ -20,6 +20,7 @@ import { isTurnContinuationBoundaryEvent } from '@cindy/maker-shared/turn-continimport { buildContinuationDirective, buildFirstTurnDirective } from './directive';import { agentHandoffPending } from '../maker-ipc/agentHandoffPendingSingleton';+import { onUiSessionIntervention } from '../maker-ipc/uiContinuationSignal';import { prependHandoffToUserMessage } from '../maker-ipc/agentHandoff';import {MAX_CONSECUTIVE_OVERLOAD_TURNS,@@ -351,6 +352,8 @@ export function decideNextGoalState(prev: GoalCounters, outcome: TurnOutcome): G// ── 每轮事件累计状态 ─────────────────────────────────────────────────────────interface TurnAccumulator {+ /** 创建目标之前已在运行的轮次;只保存在本生命周期内,不计入目标裁决。 */+ precedingTurn: { session: SessionLike; generation: number } | null;text: string;sawToolUse: boolean;tokensThisTurn: number;@@ -374,6 +377,7 @@ function freshTurn(pendingCompletion: Promise<void> | null = null,): TurnAccumulator {return {+ precedingTurn: null,text: '',sawToolUse: false,tokensThisTurn: 0,@@ -466,6 +470,7 @@ export class GoalController {/** Disposal is two-phase: detach synchronously, then drain old-owner writes. */private disposing = false;private disposePromise: Promise<void> | null = null;+ private readonly unsubscribeIntervention: () => void;/** Throw if the controller has been disposed. */private assertActive(): void {@@ -475,6 +480,11 @@ export class GoalController {constructor(private readonly deps: GoalControllerDeps) {this.now = deps.now ?? (() => Date.now());this.debounceMs = deps.continuationDebounceMs ?? DEFAULT_DEBOUNCE_MS;+ this.unsubscribeIntervention = onUiSessionIntervention((sessionId) => {+ // 新消息(包括同一轮内的插话)撤销旧轮豁免,保留原有用户打断语义。+ const turn = this.turns.get(sessionId);+ if (turn) turn.precedingTurn = null;+ });}// ── 公开 API ───────────────────────────────────────────────────────────────@@ -487,6 +497,19 @@ export class GoalController {if (!objective) throw new GoalControllerInputError('objective must not be empty');this.cancelDeferredManualResume(sessionId);let entryBoundary = this.turns.get(sessionId);+ const entrySession = this.deps.getSession(sessionId);+ const entryGeneration = entrySession?.getTurnGeneration?.();+ if (+ (!entryBoundary || entryBoundary.cancelled || entryBoundary.pendingCompletion)+ && entrySession && entryGeneration != null && entryGeneration > 0+ && this.isBusy(sessionId)+ ) {+ // 必须在首次 await 前记住身份,不能把落库期间新开始的一轮也当作旧轮。+ // Stop 或目标完成清理都可能留下 owner,而普通轮次已启动;保留原取消状态和写入屏障。+ entryBoundary ??= freshTurn();+ entryBoundary.precedingTurn = { session: entrySession, generation: entryGeneration };+ this.turns.set(sessionId, entryBoundary);+ }let rejectionTakeover:| {retry: { attempts: number; firstRejectedAt: number; retryNotBefore: number };@@ -527,6 +550,7 @@ export class GoalController {entryBoundary.pendingPersistence,entryBoundary.pendingCompletion,);+ takeoverBoundary.precedingTurn = entryBoundary.precedingTurn;this.stopSession(sessionId);this.turns.set(sessionId, takeoverBoundary);await this.awaitPendingLifecycle(takeoverBoundary);@@ -684,6 +708,7 @@ export class GoalController {previousBoundary?.pendingPersistence ?? null,previousBoundary?.pendingCompletion ?? null,);+ createBoundary.precedingTurn = previousBoundary?.precedingTurn ?? null;this.turns.set(sessionId, createBoundary);let createdState: GoalState | null = null;try {@@ -1571,6 +1596,7 @@ export class GoalController {async dispose(): Promise<void> {if (this.disposePromise) return this.disposePromise;this.disposing = true;+ this.unsubscribeIntervention();// Snapshot all old-owner persistence barriers before stopSession removes// their owners. The DB may be closed as soon as account teardown returns;// dropping either a completion clear or a goal-state write leaves stale@@ -1772,6 +1798,19 @@ export class GoalController {this.turns.set(sessionId, turn);}if (turn.cancelled) return;+ const preceding = turn.precedingTurn;+ if (+ preceding && this.listenerSessions.get(sessionId) === preceding.session+ && event.sessionTurnGeneration === preceding.generation+ && !isTerminalAgentErrorEvent(event)+ ) {+ // 旧轮的正文、用量和正常结束都不属于目标首轮。真正错误仍走原有停止路径。+ // 保留身份以忽略重复/迟到的旧事件;Stop/Clear 换掉生命周期即撤销等待。+ if (event.type === 'done' && !isTurnContinuationBoundaryEvent(event)) {+ this.scheduleContinuation(sessionId);+ }+ return;+ }switch (event.type) {case 'text': {const d = event.data as { text?: string; isFinal?: boolean } | null;diff --git a/apps/desktop/src/main/goal-host/types.ts b/apps/desktop/src/main/goal-host/types.tsindex 492c0f64f6..d74b393e3d 100644--- a/apps/desktop/src/main/goal-host/types.ts+++ b/apps/desktop/src/main/goal-host/types.ts@@ -152,6 +152,7 @@ export interface SessionLike {): Promise<SessionSendResult>;onEvent(listener: (event: AgentEvent) => void): () => void;getStatus?(): SessionStatus;+ getTurnGeneration?(): number;isTurnRunning(): boolean;abort(): Promise<void>;}diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex 407684f971..4481bb8205 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -15128,6 +15128,9 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)}assertCurrentInputGeneration(sessionId, readExpectedInputGeneration(sendOpts));sess = readCurrentSteerSession();+ // 同轮插话也属于新输入。必须在 vendor await 前通知,旧轮可能先于 steer ack 结束。+ // 共用入口同时覆盖 INPUT_STEER、队列提升和旧 STEER IPC。+ publishUiSessionIntervention(sessionId);await sess.steer(steerPayload as never, {logTitle: meta?.title,messageUuid: so.messageUuid,diff --git a/apps/desktop/src/main/maker-ipc/uiContinuationSignal.ts b/apps/desktop/src/main/maker-ipc/uiContinuationSignal.tsindex 12c9e90426..71261a5163 100644--- a/apps/desktop/src/main/maker-ipc/uiContinuationSignal.ts+++ b/apps/desktop/src/main/maker-ipc/uiContinuationSignal.ts@@ -30,7 +30,8 @@* (取消 / 失败)。目标轮没起来, 记账该还回去, 而不是等超时。** 另有一条与归属无关、但同样必要的信号:- * - `sessionIntervention(sessionId)` —— 会话被一条**新**消息推进(enqueue 入口)。+ * - `sessionIntervention(sessionId)` —— 会话被一条**新**消息推进(enqueue 或同轮 steer)。+ * steer 在主机校验完成后、vendor await 前发布,确保早于可能先于 ack 到达的终态。* 记账只按 sessionId 记, 而"重试哪一轮"与"渠道消息对应哪一轮"是两件事: 用户跑过* 无关 turn 之后点重试, 重试的是那个无关 turn, 不该把它的输出写进渠道旧消息。* 判据是**入口**而不是文本: 零产出重试重发原文, 按文本判会让它撤掉自己。@@ -102,7 +103,7 @@ export function publishUiTurnUndispatched(sessionId: string, clientId: string):fanout(undispatchedListeners, (l) => l(sessionId, clientId));}-/** 订阅「某会话被一条新消息推进了」(enqueue 入口; 见模块注释)。 */+/** 订阅「某会话被一条新消息推进了」(enqueue / steer; 见模块注释)。 */export function onUiSessionIntervention(listener: UiSessionListener): () => void {interventionListeners.add(listener);return () => {