Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(bots): distinguish workbench read failures from empty state

ylliuuu661b4648a844bd
diff --git a/apps/desktop/src/main/bot-autonomy/__tests__/hub.test.ts b/apps/desktop/src/main/bot-autonomy/__tests__/hub.test.ts
index 882c7b96c1..1e1895ca80 100644
--- a/apps/desktop/src/main/bot-autonomy/__tests__/hub.test.ts
+++ b/apps/desktop/src/main/bot-autonomy/__tests__/hub.test.ts
@@ -9,9 +9,11 @@ import { afterEach, beforeEach, expect, it, vi } from 'vitest';
import type { BotAutonomyRuntime } from '../runtime.js';
import type { RoutineEngine } from '@cindy/maker-scheduler';
import type { LocalSessionMeta } from '../taskWatch.js';
+import type { BotGlance } from '../../../shared/botAutonomy.js';
const h = vi.hoisted(() => ({
- scope: 'a', scheduler: 'sched' as string | null,
+ scope: 'a', scheduler: 'sched' as string | null, ready: true,
+ glance: vi.fn(),
readMetas: vi.fn(), readOwnership: vi.fn(),
}));
vi.mock('../../appSessionState.js', () => ({
@@ -26,7 +28,7 @@ vi.mock('../../maker-host/bot-autonomy-settings-store.js', () => ({
vi.mock('../hostData.js', () => ({
readLocalSessionMetas: h.readMetas, readTaskOwnership: h.readOwnership, readBotDirectory: vi.fn(),
}));
-import { currentFollowUpEvents, setActiveBotAutonomy } from '../hub.js';
+import { currentFollowUpEvents, getBotAutonomyGlance, setActiveBotAutonomy } from '../hub.js';
const meta = (id: string, source = 'desktop'): LocalSessionMeta => ({
id, source, title: 'Completed task', workingDir: null, status: 'active', hiddenAt: null,
@@ -37,12 +39,15 @@ const events = ['mine', 'delegated', 'shared', 'deleted'].map(subject => ({
sourceId: 'host:sessions', event: { id: subject, type: 'finished', subject, occurredAt: 2, data: {} },
}));
beforeEach(() => {
- h.scope = 'a'; h.scheduler = 'sched';
+ h.scope = 'a'; h.scheduler = 'sched'; h.ready = true;
+ h.glance.mockReset().mockReturnValue({
+ botId: 'sched', scope: 'all', waiting: [], working: [], lastSweepAt: 0, doneToday: 0, offlineDevices: [],
+ } satisfies BotGlance);
const bots = new Map([['sched', { status: 'active', allowSchedulerFollow: false }]]);
h.readMetas.mockReset().mockResolvedValue([meta('mine'), meta('delegated'), meta('shared', 'shared')]);
h.readOwnership.mockReset().mockResolvedValue({ bots, creatorBySession: new Map([['delegated', 'sched']]), responsibleByBot: new Map() });
setActiveBotAutonomy({ scope: 'a', engine: {} as RoutineEngine,
- runtime: { watch: { isReady: () => true, list: () => [], getBots: () => bots } } as unknown as BotAutonomyRuntime });
+ runtime: { glance: h.glance, watch: { isReady: () => h.ready, list: () => [], getBots: () => bots } } as unknown as BotAutonomyRuntime });
});
afterEach(() => setActiveBotAutonomy(null));
@@ -61,3 +66,20 @@ it('defers rather than authorizing a durable read that crossed the account bound
h.readMetas.mockImplementationOnce(async () => { h.scope = 'b'; return [meta('mine')]; });
expect(await currentFollowUpEvents('sched', events)).toBeNull();
});
+
+// #6508: the public glance reader must not report a successful empty workbench
+// before its host/ownership is ready. Existing coverage only exercised follow-up
+// authorization. Minimal unit inputs: missing, stale, or unready runtime.
+it.each(['missing', 'stale', 'unready'] as const)('rejects a %s runtime instead of reporting no work', (state) => {
+ if (state === 'missing') setActiveBotAutonomy(null);
+ if (state === 'stale') h.scope = 'other';
+ if (state === 'unready') h.ready = false;
+ expect(() => getBotAutonomyGlance('sched')).toThrow(/\[PRECONDITION_FAILED\]/u);
+ expect(h.glance).not.toHaveBeenCalled();
+});
+
+it('returns the actual empty projection once ready, preserving scope and visibility options', () => {
+ const options = { excludeBotIds: new Set(['hidden']) };
+ expect(getBotAutonomyGlance('sched', options)).toMatchObject({ botId: 'sched', scope: 'all', waiting: [], working: [] });
+ expect(h.glance).toHaveBeenCalledWith('sched', options);
+});
diff --git a/apps/desktop/src/main/bot-autonomy/hub.ts b/apps/desktop/src/main/bot-autonomy/hub.ts
index df90990362..fb2324209c 100644
--- a/apps/desktop/src/main/bot-autonomy/hub.ts
+++ b/apps/desktop/src/main/bot-autonomy/hub.ts
@@ -63,14 +63,13 @@ export function noteBotAutonomyInputProjection(projection: unknown): void {
runtime.watch.applyInputProjection(projection as BotAutonomyInputProjection);
}
-function emptyGlance(botId: string): BotGlance {
- return { botId, scope: 'own', waiting: [], working: [], lastSweepAt: 0, doneToday: 0, offlineDevices: [] };
-}
-
export function getBotAutonomyGlance(botId: string, options?: GlanceOptions): BotGlance {
if (isAppSessionBoundaryPending()) throwIpcError('PRECONDITION_FAILED', 'App session is switching; retry later.');
const active = current && scopeIsCurrent(current.scope) ? current.runtime : null;
- return active ? active.glance(botId, options) : emptyGlance(botId);
+ // 与伙伴工具读取保持一致:运行体或归属未就绪不是「没有任务」。
+ // 沿用已有错误协议,旧查看端也能进入读取失败分支;就绪后的变化推送会触发重读。
+ if (!active?.watch.isReady()) throwIpcError('PRECONDITION_FAILED', 'Bot autonomy is not ready; retry later.');
+ return active.glance(botId, options);
}
export async function getBotAutonomySettingsView(): Promise<BotAutonomySettingsView> {
diff --git a/apps/desktop/src/renderer/features/bots/BotWorkbench.tsx b/apps/desktop/src/renderer/features/bots/BotWorkbench.tsx
index 4bc9412595..e3bf83d7e3 100644
--- a/apps/desktop/src/renderer/features/bots/BotWorkbench.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotWorkbench.tsx
@@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { Button } from '@/components/ui/button';
+import { ErrorNotice } from '@/components/ui/error-notice';
import { Spinner } from '@/components/ui/spinner';
import { getDataOwnerGeneration, isDataOwnerGenerationCurrent } from '@/contexts/dataOwnerGeneration';
import { useDeviceLinkDeviceList } from '@/features/device-link/useDeviceLinkDeviceList';
@@ -123,9 +124,7 @@ export function BotWorkbench({
return (
<div className="flex h-full items-center justify-center bg-[var(--surface)] px-5">
{failed ? (
- <p role="status" className="text-center text-13 leading-[1.54] text-[var(--text-secondary)]">
- {t('bots.workbench.glance.loadFailed')}
- </p>
+ <ErrorNotice role="status" message={t('bots.workbench.glance.loadFailed')} />
) : (
<Spinner size={16} className="text-[var(--text-tertiary)]" role="status" aria-label={t('ccAgent.common.loading')} />
)}
@@ -161,7 +160,7 @@ export function BotWorkbench({
{t('bots.autonomy.title')}
</p>
) : null}
- {quiet ? (
+ {quiet && !failed ? (
<p className="px-2 pt-8 text-center text-14 leading-[1.57] text-[var(--text-secondary)]">
{t('bots.workbench.glance.quiet')}
</p>
@@ -169,15 +168,21 @@ export function BotWorkbench({
{glance.waiting.length > 0 ? <WaitingBlock rows={glance.waiting} ctx={ctx} /> : null}
{glance.working.length > 0 ? <WorkingBlock rows={glance.working} ctx={ctx} /> : null}
</div>
- <footer
- className={cn(
- 'flex shrink-0 items-center gap-2 border-t border-[var(--border-default)] py-2.5 text-12 leading-[1.5] text-[var(--text-tertiary)]',
- quiet ? 'justify-center px-5' : 'pl-10 pr-5',
- )}
- >
- <span aria-hidden className="size-1 shrink-0 rounded-full bg-[var(--text-tertiary)]" />
- <span className="min-w-0 truncate tabular-nums">{join(...footer)}</span>
- </footer>
+ {failed ? (
+ <div className="shrink-0 px-5 pb-4">
+ <ErrorNotice role="status" message={t('bots.workbench.glance.loadFailed')} />
+ </div>
+ ) : (
+ <footer
+ className={cn(
+ 'flex shrink-0 items-center gap-2 border-t border-[var(--border-default)] py-2.5 text-12 leading-[1.5] text-[var(--text-tertiary)]',
+ quiet ? 'justify-center px-5' : 'pl-10 pr-5',
+ )}
+ >
+ <span aria-hidden className="size-1 shrink-0 rounded-full bg-[var(--text-tertiary)]" />
+ <span className="min-w-0 truncate tabular-nums">{join(...footer)}</span>
+ </footer>
+ )}
</section>
);
}
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotWorkbenchView.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/BotWorkbenchView.test.tsx
index 4ac130f868..1dee13bb29 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/BotWorkbenchView.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotWorkbenchView.test.tsx
@@ -256,3 +256,57 @@ it('never approves a confirmation that carries no request id; it opens the task
expect(localMaker.getPendingInteractions).not.toHaveBeenCalled();
expect(localMaker.resolveInteraction).not.toHaveBeenCalled();
});
+
+// #6508: exercise the real view + reader, including retained empty snapshots.
+// Existing tests covered successful empty reads and remote offline approval only.
+// Unit regression: a successful empty read followed by a rejected refresh must
+// show read failure, never the quiet sentence or a fresh-looking footer.
+it.each([false, true])('shows refresh failure without claiming an empty workbench (had rows: %s)', async (hasRows) => {
+ glanceApi.mockResolvedValueOnce(glance({ working: hasRows ? [row({ title: 'Still working', kind: 'working' })] : [] }));
+ render(<BotWorkbench botId="bot-1" />);
+ await screen.findByText(hasRows ? 'Still working' : 'bots.workbench.glance.quiet');
+
+ glanceApi.mockRejectedValueOnce(new Error('read unavailable'));
+ act(() => listeners.forEach((cb) => cb({ botIds: ['bot-1'] })));
+ expect(await screen.findByText('bots.workbench.glance.loadFailed')).toBeTruthy();
+ expect(screen.queryByText('bots.workbench.glance.quiet')).toBeNull();
+ expect(screen.queryByText('bots.workbench.glance.seenJust')).toBeNull();
+ if (hasRows) expect(screen.getByText('Still working')).toBeTruthy();
+
+ glanceApi.mockResolvedValueOnce(glance({ working: [row({ title: 'Recovered work', kind: 'working' })] }));
+ act(() => listeners.forEach((cb) => cb({ botIds: ['bot-1'] })));
+ expect(await screen.findByText('Recovered work')).toBeTruthy();
+ expect(screen.queryByText('bots.workbench.glance.loadFailed')).toBeNull();
+});
+
+it('keeps initial loading distinct from failure and restores content on readiness and reopen', async () => {
+ let reject!: (error: Error) => void;
+ glanceApi.mockImplementationOnce(() => new Promise<BotGlance>((_resolve, fail) => { reject = fail; }));
+ const view = render(<BotWorkbench botId="bot-1" />);
+ expect(screen.getByRole('status', { name: 'ccAgent.common.loading' })).toBeTruthy();
+ expect(screen.queryByText('bots.workbench.glance.quiet')).toBeNull();
+ await act(async () => reject(new Error('[PRECONDITION_FAILED] Host not ready')));
+ expect(screen.getByText('bots.workbench.glance.loadFailed')).toBeTruthy();
+ expect(screen.queryByText('bots.workbench.glance.quiet')).toBeNull();
+
+ glanceApi.mockResolvedValue(glance({ working: [row({ title: 'Visible before close', kind: 'working' })] }));
+ act(() => listeners.forEach((cb) => cb({ botIds: ['bot-1'] })));
+ expect(await screen.findByText('Visible before close')).toBeTruthy();
+ view.unmount();
+ expect(listeners).toHaveLength(0);
+ render(<BotWorkbench botId="bot-1" />);
+ expect(await screen.findByText('Visible before close')).toBeTruthy();
+ expect(screen.queryByText('bots.workbench.glance.quiet')).toBeNull();
+});
+
+it('ignores an older empty response arriving after a newer nonempty refresh', async () => {
+ let resolve!: (value: BotGlance) => void;
+ glanceApi.mockImplementationOnce(() => new Promise<BotGlance>((done) => { resolve = done; }));
+ glanceApi.mockResolvedValueOnce(glance({ working: [row({ title: 'Current work', kind: 'working' })] }));
+ render(<BotWorkbench botId="bot-1" />);
+ act(() => listeners.forEach((cb) => cb({ botIds: ['bot-1'] })));
+ expect(await screen.findByText('Current work')).toBeTruthy();
+ await act(async () => resolve(glance()));
+ expect(screen.getByText('Current work')).toBeTruthy();
+ expect(screen.queryByText('bots.workbench.glance.quiet')).toBeNull();
+});
diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.md
index 877774ea4d..13dfb43e2b 100644
--- a/docs/product-rules/cindy-bots-runtime.md
+++ b/docs/product-rules/cindy-bots-runtime.md
@@ -743,6 +743,10 @@ Session 任务遵守同一套机制与呈现契约:
- **页脚**:上次程序级扫描时间、今天(本地日)做完几件(内存计数,重启清零)、离线电脑。
- 范围:总调度伙伴看全设备全任务(含远程电脑;远程行只看与允许,不会叫醒任何伙伴);其它伙伴只看自己开的或明确接手的任务。
- 已授权的远程控制端可读远程可见伙伴的「一眼」;设置读写不开放给远程。
+- 只有成功读取、且「等你/在做」都为空时才显示空态。运行体或归属未就绪返回既有
+ `PRECONDITION_FAILED`,不能伪造成功的空投影;首次读取期间沿用加载提示,失败明确显示读取失败。
+ 刷新失败保留已读到的条目,但隐藏空态和扫描成功页脚,显示错误;随后成功重读再恢复正常展示。
+ 实现与回归见 `bot-autonomy/hub.ts`、`hub.test.ts` 和 `BotWorkbenchView.test.tsx`。
#### 6.3.5 伙伴工具与逐任务责任
diff --git a/docs/verification/issue-6508/README.md b/docs/verification/issue-6508/README.md
new file mode 100644
index 0000000000..b4622a2fbf
--- /dev/null
+++ b/docs/verification/issue-6508/README.md
@@ -0,0 +1,95 @@
+# #6508:工作台空态修正与 macOS 验证
+
+验证日期:2026-10-21。分支:`fix/6508-workbench-empty`。
+基线:`f25a95f3b289d74b6aa4f18c78f8e2693b1ba4c6`,检查时包含本次未提交的修复。
+
+## 结论与范围
+
+本次修正两个已由回归测试证明的问题:
+
+1. 宿主运行体不存在、归属已过期或尚未就绪时,返回既有 `PRECONDITION_FAILED`,不再返回成功的空投影。
+2. 已读到缓存结果后刷新失败时,保留任务行并显示读取失败,隐藏安静空态和扫描成功页脚;后续读取成功时恢复。
+
+**尚未复现 #6508 所述的「正常打开为空、关闭时闪现内容、重开仍为空」。**
+本次改动不能被视为已确认解决该闪现现象,也不构成关闭 issue 的依据。
+[原报告及评论](https://github.com/makecindy/cindy/issues/6508)未确认关闭对象,未提供录屏;
+Windows/CN 仅是提交时快照。Windows 验证本次明确跳过,未用平台标志模拟代替实机结果。
+
+## macOS 实机
+
+环境:macOS ARM64、Electron 42.11.12、Global、隔离 userData。通过仓库安全入口启动:
+
+```sh
+pnpm restart:desktop:remote --region=global --isolated=@worktree
+```
+
+启动返回 `DESKTOP_DEV_VERDICT=ready`,界面分支核对为 `fix/6508-workbench-empty@f25a95f`。
+经真实 IPC 读取远程伙伴已有工作台,不发送消息、不响应权限、不修改任务。
+从伙伴头部的「打开工作台」进入,分别关闭标签和收起侧栏,再从同一入口重开。
+Light/Dark 打开及重开截图均已目检,均显示 2 条「在做」,文字及布局正常。
+
+改前对照仅把 `BotWorkbench.tsx` 临时换成基线版本,其余本地代码及远端宿主不变;
+不是完整旧版本重跑。对照结束后已还原修复文件并核对字节一致。
+
+| 代码 | 主题 | 关闭操作 | 关闭前 → 重开后行数 | 采样帧数 | 空态帧数 |
+| --- | --- | --- | --- | --- | --- |
+| 改前渲染代码 | light | 关闭标签 | 2 → 2 | 59 | 0 |
+| 改前渲染代码 | light | 收起 | 2 → 2 | 62 | 0 |
+| 改前渲染代码 | dark | 关闭标签 | 2 → 2 | 58 | 0 |
+| 改前渲染代码 | dark | 收起 | 2 → 2 | 62 | 0 |
+| 本次修复 | light | 关闭标签 | 2 → 2 | 58 | 0 |
+| 本次修复 | light | 收起 | 2 → 2 | 62 | 0 |
+| 本次修复 | dark | 关闭标签 | 2 → 2 | 61 | 0 |
+| 本次修复 | dark | 收起 | 2 → 2 | 61 | 0 |
+
+每次关闭采集约 1 秒 `requestAnimationFrame` 数据,只记录相对时间、挂载状态、行数、
+空态布尔值(修复后另含宽度)。共 483 帧未观察到空态;这不是屏幕录屏,不能据此断言
+所有合成器帧均无闪烁。两种主题下,改前与改后都没有复现原报告。
+
+其他入口与限制:
+
+- 独立工作台窗口记录到 `useNavigate() may be used only in the context of a <Router> component.`,
+ 与 [#6487](https://github.com/makecindy/cindy/pull/6487) 描述一致;后续截图为加载遮罩。
+ 此错误未混同为 #6508 的空态闪现,也未纳入本次修复。
+- 调用 macOS 原生关闭自身入口并尝试激活后,未捕获显隐事件,不能计为有效的主窗口关闭/重开验证。
+- 未验证 Windows、CN 或原报告者环境;未建立宿主未就绪与关闭闪现的因果关系。
+
+## 双主题组件检查
+
+在隔离 Electron 中加载真实 `BotWorkbench`、读取 hook、样式和主题,模拟宿主 API 数据。
+加载、真空态、初次失败、缓存空结果后失败、缓存非空结果后失败、正常内容,
+Light/Dark 共 12 个组合通过通用 UI 检查。
+
+首次缓存空结果失败场景截得过早,不能作为失败终态证据。修正临时场景的事件时序后,
+两个缓存失败场景的 4 个组合重跑通过并重新目检:失败提示可见、旧任务行保留、
+安静空态与成功页脚隐藏。此检查未替换产品模块,但使用了模拟宿主数据,不能替代实机复现。
+
+原始截图、帧记录与临时场景保存在验证 worktree 的 Git 忽略目录
+`artifacts/issue-6508-real/`、`artifacts/ui-check/`、`tmp/6508-workbench.tsx`,
+未随本次提交发布。此文保存可独立阅读的结果及限制,自动回归随源码提交。
+
+## 回归与静态检查
+
+先补回归、再修复:初始两个测试文件 **5 失败 / 13 通过**;生产代码修正后 **18 通过**。
+新增测试覆盖运行体缺失/过期/未就绪、真实空结果、缓存刷新失败与恢复、
+加载/失败区分、卸载重开,以及较早空响应不得覆盖较新非空响应。
+
+扩展验证 **7 个文件、80 项测试通过**:
+
+```sh
+pnpm --filter desktop exec vitest run \
+ src/main/bot-autonomy/__tests__/hub.test.ts \
+ src/main/bot-autonomy/__tests__/runtime.test.ts \
+ src/main/bot-autonomy/__tests__/taskWatch.test.ts \
+ src/main/bot-autonomy/__tests__/autonomyRules.test.ts \
+ src/renderer/features/bots/__tests__/BotWorkbenchView.test.tsx \
+ src/renderer/features/bots/__tests__/botWorkbenchLifecycle.test.tsx \
+ src/renderer/features/right-sidebar/lib/__tests__/openBotWorkbenchTab.test.ts \
+ --maxWorkers=2
+pnpm --filter desktop run --if-present typecheck
+pnpm check:dev-docs
+git diff --check
+```
+
+Desktop 类型检查、文档检查及 diff 空白检查通过。首次类型检查因 Mobile 工作区依赖未安装失败,
+补齐依赖后重跑通过;没有通过修改源码或弱化检查消除该环境错误。没有执行完整仓库测试或远端 CI。