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(helper): preserve uncertain remote status write outcomes

zqchris8964db9d3116
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
index 1fcbf9a7af..ad345268e6 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
@@ -183,6 +183,7 @@ import { retireDeletedPiSubagentState } from '../piSubagentDeletion';
import { setSessionRouteLockImplementation } from '../../sessionRouteLock';
import { assertTrustedAppRendererEvent } from '../../../security/trustedAppRenderer.js';
import { createRemoteSessionsStatusSetter } from '../../../mcp-integrations/sessionStatusRemote.js';
+import * as sessionQueries from '../../sessionQueries';
function createDb(): void {
const sqlite = new Database(':memory:');
@@ -918,6 +919,39 @@ describe('local-db:sessions:update handler wiring', () => {
expect(h.closeSharedTask).not.toHaveBeenCalled();
});
+ it('reports an unknown remote result when the receipt query overloads after the status write', async () => {
+ h.sqlite!.prepare("UPDATE sessions SET status = 'archived' WHERE id = ?").run('codex-local');
+ const receiptQuery = vi.spyOn(sessionQueries, 'selectSessionWithCount')
+ .mockRejectedValueOnce(new Error('db worker RPC queue overloaded'));
+ try {
+ let handlerError: unknown;
+ const invoke = vi.fn(async (_device: string, _channel: string, args: unknown[]) => {
+ try {
+ return { ok: true as const, result: await invokePatchMeta(args[0] as string, args[1] as Record<string, unknown>) };
+ } catch (error) {
+ handlerError = error;
+ // Preserve the handler error as dispatch does: newer hosts may wrap it first.
+ const message = error instanceof Error ? error.message : String(error);
+ const code = message.includes('db worker RPC queue overloaded') ? 'BACKPRESSURE' : 'IPC_ERROR';
+ return { ok: false as const, error: { code, message } };
+ }
+ });
+ const restore = createRemoteSessionsStatusSetter({ captureAccess: () => () => {}, invoke });
+ expect(await restore({ deviceId: 'studio', sessionIds: ['codex-local', 'unattempted'], status: 'active' })).toMatchObject({
+ ok: false, errorCode: 'REMOTE_RESULT_UNKNOWN', changed: [],
+ message: expect.stringContaining('请先查询目标任务状态'),
+ failedSessionId: 'codex-local', remainingSessionIds: ['unattempted'],
+ });
+ expect(h.sqlite!.prepare('SELECT status FROM sessions WHERE id = ?').get('codex-local')).toEqual({ status: 'active' });
+ expect(handlerError).toBeInstanceOf(Error);
+ expect((handlerError as Error).message).toBe('[PRECONDITION_FAILED] Worktree is busy or its recovery record could not be saved');
+ expect(receiptQuery).toHaveBeenCalledOnce();
+ expect(invoke).toHaveBeenCalledOnce();
+ } finally {
+ receiptQuery.mockRestore();
+ }
+ });
+
it.each(['active', 'archived'] as const)('remote patch-meta cannot change a deleted task to %s', async (status) => {
h.sqlite!.prepare("UPDATE sessions SET status = 'deleted' WHERE id = ?").run('codex-local');
await expect(invokePatchMeta('codex-local', { status })).rejects.toThrow('已删除的任务不能恢复或归档');
diff --git a/apps/desktop/src/main/mcp-integrations/__tests__/sessionStatusRemote.test.ts b/apps/desktop/src/main/mcp-integrations/__tests__/sessionStatusRemote.test.ts
index c02c808996..4665232b05 100644
--- a/apps/desktop/src/main/mcp-integrations/__tests__/sessionStatusRemote.test.ts
+++ b/apps/desktop/src/main/mcp-integrations/__tests__/sessionStatusRemote.test.ts
@@ -29,8 +29,12 @@ describe('remote session archive status', () => {
['VERSION_MISMATCH', '', 'REMOTE_UNSUPPORTED'],
['NOT_CONNECTED', '', 'REMOTE_UNAVAILABLE'],
['DEVICE_UNRESPONSIVE', '', 'REMOTE_UNAVAILABLE'],
+ ['BACKPRESSURE', 'db worker RPC queue overloaded', 'REMOTE_RESULT_UNKNOWN'],
+ ['IPC_ERROR', '[BACKPRESSURE] db worker RPC queue overloaded', 'REMOTE_RESULT_UNKNOWN'],
['IPC_ERROR', '[DEVICE_LINK_CONTROL_DISABLED] off', 'REMOTE_DISABLED'],
['IPC_ERROR', '[PRECONDITION_FAILED] 已删除的任务不能恢复或归档', 'PRECONDITION_FAILED'],
+ ['IPC_ERROR', '[PRECONDITION_FAILED] Bot task lifecycle is managed by teammate recovery and history controls', 'PRECONDITION_FAILED'],
+ ['IPC_ERROR', '[PRECONDITION_FAILED] Worktree is busy or its recovery record could not be saved', 'REMOTE_RESULT_UNKNOWN'],
['IPC_ERROR', '[NOT_FOUND] Session 不存在', 'NOT_FOUND'],
['IPC_ERROR', '[NOT_FOUND] Session does not exist', 'REMOTE_RESULT_UNKNOWN'],
['IPC_ERROR', '[INTERNAL] failure after write', 'REMOTE_RESULT_UNKNOWN'],
@@ -41,6 +45,15 @@ describe('remote session archive status', () => {
expect(s.invoke).toHaveBeenCalledOnce();
});
+ it.each([false, true])('distinguishes local backpressure with inFlight=%s', async (inFlight) => {
+ const s = setup(Object.assign(new DeviceLinkError('BACKPRESSURE', 'queue full'), { inFlight }));
+ expect(await s.setStatus(request)).toMatchObject({
+ ok: false, errorCode: inFlight ? 'REMOTE_RESULT_UNKNOWN' : 'REMOTE_UNAVAILABLE',
+ changed: [], failedSessionId: 's1', remainingSessionIds: ['s2', 's3'],
+ });
+ expect(s.invoke).toHaveBeenCalledOnce();
+ });
+
it('keeps a timeout/disconnect after sending uncertain even when its code looks like a rejection', async () => {
const s = setup(Object.assign(new DeviceLinkError('NOT_CONNECTED', ''), { inFlight: true }));
expect(await s.setStatus(request)).toMatchObject({ errorCode: 'REMOTE_RESULT_UNKNOWN' });
diff --git a/apps/desktop/src/main/mcp-integrations/sessionStatusRemote.ts b/apps/desktop/src/main/mcp-integrations/sessionStatusRemote.ts
index b1e7911cd7..adc91917a2 100644
--- a/apps/desktop/src/main/mcp-integrations/sessionStatusRemote.ts
+++ b/apps/desktop/src/main/mcp-integrations/sessionStatusRemote.ts
@@ -8,7 +8,7 @@ const unknownOutcome = (): Failure => ({
});
/** Only classify proven pre-write rejections as definite failures. */
-function failure(code: string, message: string): Failure {
+function failure(code: string, message: string, beforeSend = false): Failure {
const actual = code === 'IPC_ERROR'
? /(?:^|:\s*(?:Error:\s*)?)\[([A-Z0-9_]+)]/.exec(message)?.[1] ?? code
: code;
@@ -24,9 +24,12 @@ function failure(code: string, message: string): Failure {
case 'REMOTE_DISABLED':
case 'DEVICE_LINK_CONTROL_DISABLED':
return { errorCode: 'REMOTE_DISABLED', message: '未允许远程控制目标电脑。' };
+ case 'BACKPRESSURE':
+ // The target can overload while querying its receipt after committing the write.
+ if (!beforeSend) return unknownOutcome();
+ return { errorCode: 'REMOTE_UNAVAILABLE', message: '发送队列拥塞,尚未发送到目标电脑。' };
case 'LINK_NOT_OPEN':
case 'NOT_CONNECTED':
- case 'BACKPRESSURE':
case 'DEVICE_LINK_NOT_CONNECTED':
case 'DEVICE_LINK_STANDBY':
case 'DEVICE_UNRESPONSIVE':
@@ -34,7 +37,12 @@ function failure(code: string, message: string): Failure {
case 'INVALID_PARAMS':
return { errorCode: 'INVALID_ARGS', message: '目标电脑拒绝了归档状态参数。' };
case 'PRECONDITION_FAILED':
- return { errorCode: 'PRECONDITION_FAILED', message: '目标任务已删除或由专属生命周期管理,不能通过此工具恢复或归档。' };
+ if (message.includes('[PRECONDITION_FAILED] 已删除的任务不能恢复或归档') ||
+ message.includes('[PRECONDITION_FAILED] Bot task lifecycle is managed by teammate recovery and history controls')) {
+ return { errorCode: 'PRECONDITION_FAILED', message: '目标任务已删除或由专属生命周期管理,不能通过此工具恢复或归档。' };
+ }
+ // The worktree mutation wrapper can also replace a post-write query error with this code.
+ return unknownOutcome();
case 'NOT_FOUND':
// dispatch also emits NOT_FOUND *after* the handler on owner/visibility changes.
if (message.includes('[NOT_FOUND] Session 不存在')) {
@@ -89,7 +97,7 @@ export function createRemoteSessionsStatusSetter(deps: {
changed.forEach((item) => { item.title = null; item.workingDir = null; });
}
const reason = error instanceof DeviceLinkError
- ? (error.inFlight ? unknownOutcome() : failure(error.code, error.message))
+ ? (error.inFlight ? unknownOutcome() : failure(error.code, error.message, true))
: failure('IPC_ERROR', error instanceof Error ? error.message : '');
return fail(index, reason);
}
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index f7a5f227a3..acc687edd9 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -432,6 +432,9 @@ allowlist、数据库 migration 或第三台电脑转发。复合 ID 不交给
目标服务的不存在与已删除/专属生命周期限制返回 `NOT_FOUND` / `PRECONDITION_FAILED`;
隧道在处理后复核账号/可见性的 NOT_FOUND、超时、在途断连、错误回执与内部错误均按
`REMOTE_RESULT_UNKNOWN`,说明该项可能已生效,调用方先查状态再决定是否重试。
+本机发送前的 `BACKPRESSURE` 返回 `REMOTE_UNAVAILABLE`;目标返回的 `BACKPRESSURE` 或
+无法确认为写入前拒绝的 `PRECONDITION_FAILED` 也返回 `REMOTE_RESULT_UNKNOWN`,因为写入后的
+回执查询可能失败(后者可能由 worktree mutation 包装查询错误)。即使 `changed` 为空也标记 `partial: true`。
同一账号快照覆盖整个远程批次,切账号后停止并不返回旧账号的标题/目录。
取消归档不发送旧消息、不启动任务执行、不恢复暂停自动化。成功后另调既有 `send_to_session`
diff --git a/packages/lizi-mcps/src/__tests__/archiveSessionsTool.test.ts b/packages/lizi-mcps/src/__tests__/archiveSessionsTool.test.ts
index b218ba26bf..3ee7159c7d 100644
--- a/packages/lizi-mcps/src/__tests__/archiveSessionsTool.test.ts
+++ b/packages/lizi-mcps/src/__tests__/archiveSessionsTool.test.ts
@@ -226,4 +226,18 @@ describe('unarchive_sessions tool', () => {
} });
expect(setSessionsStatus).not.toHaveBeenCalled();
});
+
+ it('marks an unknown first write as partial even without a confirmed receipt', async () => {
+ const remote = vi.fn(async () => ({
+ ok: false as const, errorCode: 'REMOTE_RESULT_UNKNOWN', message: 'check status first',
+ changed: [], failedSessionId: 's1', remainingSessionIds: ['s2'],
+ }));
+ const { registry, setSessionsStatus } = setup({ remote });
+ const res = await registry.call('unarchive_sessions', { session_ids: ['studio::s1', 'studio::s2'] });
+ expect(res.isError).toBe(true);
+ expect(parse(res)).toMatchObject({ ok: false, errorCode: 'REMOTE_RESULT_UNKNOWN', data: {
+ partial: true, changed: [], failed_session_id: 'studio::s1', remaining_session_ids: ['studio::s2'],
+ } });
+ expect(setSessionsStatus).not.toHaveBeenCalled();
+ });
});