Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(companions): avoid runtime refresh after native compaction
Chris92dfec05db7c
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/sessionEventPipeline.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/sessionEventPipeline.test.tsindex 97a22f00f0..c7c4a24eef 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/sessionEventPipeline.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/sessionEventPipeline.test.ts@@ -3,6 +3,7 @@ import type { TurnUsageContext } from '../turnUsageContext.js';import { Session, type AgentEvent, type AgentSessionHandle } from '@cindy/maker-core';import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest';import { handleSessionEvent, type SessionEventDependencies } from '../sessionEventPipeline.js';+import { createBotCompactRuntimeRefreshCoordinator } from '../botCompactRuntimeRefresh.js';import { createContextOverflowRollover } from '../contextOverflowRollover.js';import { setMainLocale } from '../../i18n.js';import { installSessionTurnObserver } from '../sessionTurnObserver.js';@@ -2219,10 +2220,18 @@ describe('Bot adapters in the shared event pipeline', () => {await h.dispose();});- it('carries a pending follow-up into task settlement and remembers compact boundaries without rebuilding early', async () => {+ it('keeps native compaction in the current runtime while allowing explicit resource refresh', async () => {const h = harness();+ const close = vi.fn(async () => {});+ const bootstrap = vi.fn(async () => {});+ const coordinator = createBotCompactRuntimeRefreshCoordinator({+ hasPendingInteraction: () => false,+ refresh: async () => { await close(); await bootstrap(); return 'refreshed'; },+ });+ h.deps.botCompactRuntimeRefreshCoordinator.noteBoundary = vi.fn(coordinator.noteBoundary);+ h.deps.attemptBotCompactRuntimeRefresh.mockImplementation(() => { void coordinator.attempt(h.session); });h.emit(event('compact_boundary'));- expect(h.deps.botCompactRuntimeRefreshCoordinator.noteBoundary).toHaveBeenCalledWith(h.session);+ expect(h.deps.botCompactRuntimeRefreshCoordinator.noteBoundary).not.toHaveBeenCalled();// 原生摘要可能丢掉账本内容:下一次发送补一份工作记忆。expect(h.deps.workingMemoryRefresh.markCompacted).toHaveBeenCalledWith('task');// 原生摘要可能丢掉了环境说明:下一轮整体重发。@@ -2235,6 +2244,13 @@ describe('Bot adapters in the shared event pipeline', () => {childSessionId: 'task', resultText: 'first result', hadPendingInputAtTerminal: true,}));expect(h.deps.attemptBotCompactRuntimeRefresh).toHaveBeenCalledWith(h.session, 'event:done');+ expect(close).not.toHaveBeenCalled();+ expect(bootstrap).not.toHaveBeenCalled();+ coordinator.noteBoundary(h.session);+ await coordinator.attempt(h.session);+ expect(close).toHaveBeenCalledOnce();+ expect(bootstrap).toHaveBeenCalledOnce();+ await h.dispose();});});diff --git a/apps/desktop/src/main/maker-ipc/botCompactRuntimeRefresh.ts b/apps/desktop/src/main/maker-ipc/botCompactRuntimeRefresh.tsindex b2f308e23b..863f869fb2 100644--- a/apps/desktop/src/main/maker-ipc/botCompactRuntimeRefresh.ts+++ b/apps/desktop/src/main/maker-ipc/botCompactRuntimeRefresh.ts@@ -61,10 +61,10 @@ export async function replaceBotRuntimeAfterPreflight<T>(deps: {}/**- * A provider can emit compact_boundary in the middle of one product turn. The- * Bot Profile runtime must therefore be rebuilt only after the final product- * boundary, never directly from the compact event. This coordinator owns the- * small instance-scoped state machine; the host callback owns close/bootstrap.+ * Explicit Bot resource changes may arrive during a product turn. Defer their+ * runtime refresh until the turn settles. Native compact_boundary alone does+ * not register a refresh. This coordinator owns the instance-scoped pending+ * state; the host callback owns close/bootstrap.*/export function createBotCompactRuntimeRefreshCoordinator(deps: BotCompactRuntimeRefreshDeps,diff --git a/apps/desktop/src/main/maker-ipc/sessionEventPreparation.ts b/apps/desktop/src/main/maker-ipc/sessionEventPreparation.tsindex 2367778045..80bdc56f32 100644--- a/apps/desktop/src/main/maker-ipc/sessionEventPreparation.ts+++ b/apps/desktop/src/main/maker-ipc/sessionEventPreparation.ts@@ -151,7 +151,8 @@ export function prepareSessionEvent(// on-demand detail IPC; forwarding the raw diff through maker:event would duplicate a// potentially multi-megabyte payload to every renderer and device-link controller.if (event.type === 'turn_diff') return;- if (event.type === 'compact_boundary') deps.botCompactRuntimeRefreshCoordinator.noteBoundary(session);+ // Native compaction keeps its current runtime. Only explicit resource/configuration+ // changes register a companion refresh; compaction itself is not such a change.if (event.type === 'compact_boundary') deps.workingMemoryRefresh?.markCompacted(session.id);if (event.type === 'compact_boundary') deps.wireNoteMemory?.reset(session.id);if (diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.mdindex 092d0abd1e..6da51533dd 100644--- a/docs/product-rules/cindy-bots-runtime.md+++ b/docs/product-rules/cindy-bots-runtime.md@@ -196,6 +196,7 @@ Discord 传输层只放行主人,钉钉群里被 @ 时成员也能触发(成- 不按空闲时长(包括隔夜 12 小时)、打开次数或 70% / 90% 占用提前重建原生会话。- 不根据工作记忆新鲜度替代原生压缩,不主动扫描健康 Codex 历史来提前换窗。+- 正常原生压缩结束不登记或重启伙伴运行实例;只有明确资料 / 能力 / 模型配置变化等独立原因才刷新实例。- 不在后台唤醒、自动续跑或人工输入时执行伙伴专属整理,因此不产生日常整理提示卡。- 不在回复后调用辅助模型复盘学习、维护短期工作记忆账本,压缩后也不重新注入旧账本。- 用户明确建立的例行任务、后台任务与其结果回传、手动记忆 / Skill 工具、既有长期记忆及文件不受影响。