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(plugins): reject late plans and failed delegated history reads

Dash9cad729af9cd
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/autoReviewUserIntent.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/autoReviewUserIntent.test.ts
index 35dc26b6c0..69a125af76 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/autoReviewUserIntent.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/autoReviewUserIntent.test.ts
@@ -25,14 +25,15 @@ const current = { clientId: 'latest', content: { text: '修吧,改完跑相关
describe('steer authorization restoration', () => {
it.each([false, true])('restores delegated history without treating it as human input (unavailable=%s)', async unavailable => {
- const intent = await restoreAutoReviewSteerIntent('Deploy now', {
+ const pending = restoreAutoReviewSteerIntent('Deploy now', {
[AUTO_REVIEW_SOURCE_CONTENT]: '', [AUTO_REVIEW_DELEGATED_CONTINUATION]: true,
}, async () => {
if (unavailable) throw new Error('unavailable');
return [user('Edit src.'), user('Do not deploy.')];
});
- if (unavailable) expect(intent).toBe('');
+ if (unavailable) await expect(pending).rejects.toThrow('unavailable');
else {
+ const intent = await pending;
expect(intentText(intent)).toContain('Edit src.');
expect(intentText(intent)).toContain('Do not deploy.');
expect(intentText(intent)).not.toContain('Deploy now');
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts
index 3bed63ab30..a4e3e574c2 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts
@@ -2520,11 +2520,16 @@ describe('session-agent-switch handoff injection', () => {
if(unavailable) throw new Error('unavailable');
return [{clientId:'human',role:'user',content:{text:'Do not deploy'},agentMeta:{delivery:'turn',autoReviewUserText:'Do not deploy'}}];
}});
- await createMakerSendTransaction(deps).sendToAgentAccepted('session-1','Deploy now',undefined,{
+ const pending = createMakerSendTransaction(deps).sendToAgentAccepted('session-1','Deploy now',undefined,{
[AUTO_REVIEW_SOURCE_CONTENT]:'',[AUTO_REVIEW_DELEGATED_CONTINUATION]:true,
});
- const opts=vi.mocked(session.send).mock.calls[0]![1]!;
- expect(opts[AUTO_REVIEW_USER_INTENT]).toBe(unavailable?'':'Do not deploy');
+ if (unavailable) {
+ await expect(pending).rejects.toThrow('unavailable');
+ expect(session.send).not.toHaveBeenCalled();
+ } else {
+ await pending;
+ expect(vi.mocked(session.send).mock.calls[0]![1]![AUTO_REVIEW_USER_INTENT]).toBe('Do not deploy');
+ }
});
it.each([false, true])('restores scheduled intent from owner history, not the prompt (unavailable=%s)', async (unavailable) => {
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/orcaInterAgentDispatcher.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/orcaInterAgentDispatcher.test.ts
index fdd40a3caa..289aa1591d 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaInterAgentDispatcher.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaInterAgentDispatcher.test.ts
@@ -122,8 +122,11 @@ describe('Orca lead/worker dispatcher', () => {
if(unavailable) throw new Error('unavailable');
return [{clientId:'human',role:'user',content:{text:'Do not deploy'},agentMeta:{delivery:'turn',autoReviewUserText:'Do not deploy'}}];
}});
- await h.dispatcher.dispatchOrEnqueueOrcaInterAgentMessage({targetSessionId:'target-session',rawContent:'Deploy now',source:'lead',senderLabel:'Lead',workerId:'worker-1',meta:{source:'orca',context:'test'}});
- expect(h.liveSession.send.mock.calls[0]?.[1]?.[AUTO_REVIEW_USER_INTENT]).toBe(unavailable ? '' : 'Do not deploy');
+ const result = await h.dispatcher.dispatchOrEnqueueOrcaInterAgentMessage({targetSessionId:'target-session',rawContent:'Deploy now',source:'lead',senderLabel:'Lead',workerId:'worker-1',meta:{source:'orca',context:'test'}});
+ if (unavailable) {
+ expect(result).toMatchObject({ok:false});
+ expect(h.liveSession.send).not.toHaveBeenCalled();
+ } else expect(h.liveSession.send.mock.calls[0]?.[1]?.[AUTO_REVIEW_USER_INTENT]).toBe('Do not deploy');
});
it('runs direct accepted side effects after DB persistence and before vendor turn release', async () => {
const h = createHarness();
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskAuthorshipWiring.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskAuthorshipWiring.test.ts
index 3202100ecd..f54b534c5c 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskAuthorshipWiring.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskAuthorshipWiring.test.ts
@@ -15,7 +15,7 @@ it('restores human authorization for both live and cold internal delegated sends
const options=source.slice(start,source.indexOf('onAccepted: persistUserMessage',start));
expect(options).toContain('params.autoReviewUserText');
expect(options).toContain('[AUTO_REVIEW_SOURCE_CONTENT]:');
- expect(options).toContain('restoreAutoReviewUserIntent(await readAutoReviewHistory(targetSessionId).catch(() => []))');
+ expect(options).toContain('restoreAutoReviewUserIntent(await readAutoReviewHistory(targetSessionId))');
}
});
@@ -55,3 +55,45 @@ it('builds a durable queued plugin input without promoting plugin text to user i
expect(queued).toMatchObject({ text: base.message, persistedContent: base.persistedContent, autoReviewUserText: { kind: 'delegated-continuation' }, permissionMode: 'auto' });
expect(await build(base)).not.toHaveProperty('autoReviewUserText');
});
+
+it.each(['empty', 'user', 'worker', 'reserved', 'unavailable'])('seals initial plans against persisted activity: %s', async state => {
+ const start = source.indexOf('assertTeamPlanUnstarted: async taskId => {');
+ const end = source.indexOf('\n createSession:', start);
+ const property = source.slice(start, end).trim().replace(/,$/, '');
+ const tables = ['messages', 'orcaWorkers', 'orcaTeams', 'orcaWorkerCreationReservations'];
+ const records = Object.fromEntries(tables.map(name => [name, { name }]));
+ let drained = false;
+ const snapshot = { client: { drizzle: { select: () => {
+ let table: {name: string};
+ const query = {
+ from(value: {name: string}) { table = value; return query; },
+ innerJoin() { return query; }, where() { return query; },
+ async limit() {
+ expect(drained).toBe(true);
+ if (state === 'unavailable') throw new Error('unavailable');
+ const populated = { user: 'messages', worker: 'orcaWorkers', reserved: 'orcaWorkerCreationReservations' }[state];
+ return table.name === populated ? [{ id: 'existing' }] : [];
+ },
+ };
+ return query;
+ } } } };
+ class PlanError extends Error { constructor(code: string) { super(code); } }
+ const check = new Function('snapshot', 'assertCurrent', 'drainPersistQueue', 'PluginTaskError', 'eq', 'and', 'gte', ...tables,
+ compile(`return ({${property}}).assertTeamPlanUnstarted;`))(
+ snapshot, vi.fn(), async () => { drained = true; }, PlanError, vi.fn(), vi.fn(), vi.fn(), ...tables.map(t => records[t]),
+ );
+ if (state === 'empty') await expect(check('task')).resolves.toBeUndefined();
+ else await expect(check('task')).rejects.toThrow(state === 'unavailable' ? 'unavailable' : 'TASK_BUSY');
+});
+
+it('aborts both internal delegated entry points when authorization history cannot be read', async () => {
+ for (const target of ['live', 'session']) {
+ const start = source.lastIndexOf(`sendUserMessageWithAwaitedGitBaseline(${target}, message, clientId, {`);
+ const options = source.slice(start, source.indexOf('onAccepted: persistUserMessage', start));
+ const expression = options.slice(options.indexOf('restoreAutoReviewUserIntent('), options.indexOf('),', options.indexOf('restoreAutoReviewUserIntent(')) + 1);
+ const evaluate = new Function('readAutoReviewHistory', 'restoreAutoReviewUserIntent', 'targetSessionId', `return (async () => ${expression})();`);
+ const restore = vi.fn();
+ await expect(evaluate(async () => { throw new Error('unavailable'); }, restore, 'task')).rejects.toThrow('unavailable');
+ expect(restore).not.toHaveBeenCalled();
+ }
+});
diff --git a/apps/desktop/src/main/maker-ipc/autoReviewUserIntent.ts b/apps/desktop/src/main/maker-ipc/autoReviewUserIntent.ts
index 6d028f2e29..3c834832a2 100644
--- a/apps/desktop/src/main/maker-ipc/autoReviewUserIntent.ts
+++ b/apps/desktop/src/main/maker-ipc/autoReviewUserIntent.ts
@@ -37,7 +37,7 @@ export async function restoreAutoReviewSteerIntent(
const context = options[MAIN_OWNED_SEND_CONTEXT];
if (context && context.origin.kind !== 'desktop') return undefined;
if (options[AUTO_REVIEW_DELEGATED_CONTINUATION]) {
- const history = await readHistory().catch(() => []);
+ const history = await readHistory();
options.signal?.throwIfAborted();
return restoreAutoReviewUserIntent(history);
}
diff --git a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts b/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
index c76ae151b2..0cc7cca4d1 100644
--- a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
+++ b/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
@@ -1328,7 +1328,7 @@ export function createMakerSendTransaction(deps: MakerSendTransactionDeps): Make
if (resolveScheduledIntent) restoredAutoReviewIntent = undefined;
if (!resolveScheduledIntent && restoredAutoReviewIntent === undefined && so[AUTO_REVIEW_DELEGATED_CONTINUATION]
&& (!mainOwnedSendContext || mainOwnedSendContext.origin.kind === 'desktop')) {
- const history = await deps.readAutoReviewHistory?.(sessionId).catch(() => []) ?? [];
+ const history = await deps.readAutoReviewHistory?.(sessionId) ?? [];
restoredAutoReviewIntent = restoreAutoReviewUserIntent(history);
}
if (!resolveScheduledIntent && restoredAutoReviewIntent === undefined && isOrdinaryUserTurn && trustedUserText !== undefined
diff --git a/apps/desktop/src/main/maker-ipc/orcaInterAgentDispatcher.ts b/apps/desktop/src/main/maker-ipc/orcaInterAgentDispatcher.ts
index 6d06a18137..a2bba35187 100644
--- a/apps/desktop/src/main/maker-ipc/orcaInterAgentDispatcher.ts
+++ b/apps/desktop/src/main/maker-ipc/orcaInterAgentDispatcher.ts
@@ -671,7 +671,7 @@ async function sendPersistedUserMessageToSession<TSessionMeta>(
): Promise<CollabDirectDispatchResult> {
const { session, dbContent, agentMessage, clientId = deps.createId(), source, context, origin, onAccepted } = params;
let turnChangeSetStarted = false;
- const humanIntent = restoreAutoReviewUserIntent(await deps.readAutoReviewHistory?.(session.id).catch(() => []) ?? []);
+ const humanIntent = restoreAutoReviewUserIntent(await deps.readAutoReviewHistory?.(session.id) ?? []);
const result = await resolveCollabDispatchResult(
() => session.send(agentMessage, {
planMode: false,
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index fd9d1c2e63..f18250d2a8 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -9422,7 +9422,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
const sendResult = await sendUserMessageWithAwaitedGitBaseline(live, message, clientId, {
...(params.autoReviewUserText ? {
[AUTO_REVIEW_SOURCE_CONTENT]: '',
- [AUTO_REVIEW_USER_INTENT]: restoreAutoReviewUserIntent(await readAutoReviewHistory(targetSessionId).catch(() => [])),
+ [AUTO_REVIEW_USER_INTENT]: restoreAutoReviewUserIntent(await readAutoReviewHistory(targetSessionId)),
} : {}),
planMode: false,
onAccepted: persistUserMessage,
@@ -9536,7 +9536,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
const sendResult = await sendUserMessageWithAwaitedGitBaseline(session, message, clientId, {
...(params.autoReviewUserText ? {
[AUTO_REVIEW_SOURCE_CONTENT]: '',
- [AUTO_REVIEW_USER_INTENT]: restoreAutoReviewUserIntent(await readAutoReviewHistory(targetSessionId).catch(() => [])),
+ [AUTO_REVIEW_USER_INTENT]: restoreAutoReviewUserIntent(await readAutoReviewHistory(targetSessionId)),
} : {}),
planMode: false,
onAccepted: persistUserMessage,