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): preserve coordination boundaries during steering

zqchrisd0d6f8a79322
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
index ccaf2e8a07..42801225e1 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
@@ -1783,13 +1783,89 @@ describe('AgentInputCoordinator send transaction', () => {
await flush();
expect(restarted.sendToAgent).toHaveBeenCalledOnce();
expect(restarted.coordinator.isActiveTaskCoordination(sid)).toBe(true);
- await restarted.coordinator.steer(sid, makeItem('human', 'Please explain the result'));
+ const accepted = deferred<void>();
+ restarted.steerToAgent.mockImplementationOnce(() => accepted.promise);
+ const steering = restarted.coordinator.steer(sid, makeItem('human', 'Please explain the result'));
+ await flush();
+ expect(restarted.coordinator.isActiveTaskCoordination(sid)).toBe(true);
+ accepted.resolve();
+ await steering;
expect(restarted.coordinator.isActiveTaskCoordination(sid)).toBe(false);
restarted.setRunning(false);
restarted.coordinator.onTurnEvent(sid, 'done');
expect(restarted.coordinator.isActiveTaskCoordination(sid)).toBe(false);
});
+ it.each(['policy', 'preparation', 'provider'] as const)(
+ 'keeps coordination quiet when human steering fails at %s', async (failure) => {
+ const h = createHarness(), sid = `coordination-steer-${failure}`;
+ h.sendToAgent.mockImplementationOnce(async () => { h.setRunning(true); return sendSuccess(); });
+ h.coordinator.enqueue(sid, makeItem('internal', '[UI_ACTION_TRIGGER]File agreement', {
+ botTaskCoordination: { delegationId: 'd', senderSessionId: 'child', runSequence: 1 },
+ }));
+ await flush();
+ const gate = deferred<void>();
+ if (failure === 'policy') h.setScreenUserMessage(async () => {
+ await gate.promise;
+ return { action: 'block', ghostId: 'guard', ghostName: 'guard', reason: 'blocked' };
+ });
+ if (failure === 'provider') h.steerToAgent.mockImplementationOnce(async () => {
+ await gate.promise;
+ throw new Error('attachment conversion or provider delivery failed');
+ });
+ const steering = h.coordinator.steer(sid, makeItem('human', 'Explain'),
+ failure === 'preparation' ? { beforeMutation: async () => {
+ await gate.promise;
+ throw new Error('preparation rejected');
+ } } : undefined);
+ // Install the rejection handler before releasing the asynchronous boundary.
+ const settled = steering.catch(() => false);
+ await flush();
+ expect(h.coordinator.isActiveTaskCoordination(sid)).toBe(true);
+ gate.resolve();
+ await settled;
+ expect(h.coordinator.isActiveTaskCoordination(sid)).toBe(true);
+ expect(h.coordinator.getAcceptedInputProvenance(sid)?.clientId).toBe('internal');
+ },
+ );
+
+ it.each(['projection', 'control', 'direct'] as const)(
+ 'keeps coordination queued instead of injecting it through %s steering', async (entry) => {
+ const h = createHarness(), sid = `coordination-queue-steer-${entry}`;
+ await h.coordinator.ensureQueueRestored(sid);
+ h.coordinator.enqueue(sid, makeItem('human', 'Requested answer'));
+ await flush();
+ const internal = makeItem('internal', '[UI_ACTION_TRIGGER]File agreement', {
+ botTaskCoordination: { delegationId: 'd', senderSessionId: 'child', runSequence: 1 },
+ });
+ h.coordinator.enqueue(sid, internal);
+ await flush();
+ if (entry === 'control') {
+ expect(await h.coordinator.steerControlInput(sid, { queuedClientId: 'internal' }, {
+ session: h.getTurnSessionIdentity(), turnGeneration: 0,
+ })).toBe('queued');
+ } else {
+ const candidate = entry === 'projection'
+ ? h.coordinator.getProjection(sid).pendingQueue[0]!
+ : { ...internal, clientId: 'direct-internal' };
+ expect(await h.coordinator.steer(sid, candidate, { removeFromQueue: entry === 'projection' }))
+ .toBe(false);
+ }
+ expect(h.steerToAgent).not.toHaveBeenCalled();
+ expect(h.coordinator.isActiveTaskCoordination(sid)).toBe(false);
+ expect(h.coordinator.getAcceptedInputProvenance(sid)?.clientId).toBe('human');
+ expect(h.coordinator.getQueueControlSnapshot(sid).pendingQueue[0]?.botTaskCoordination)
+ .toEqual(internal.botTaskCoordination);
+ h.setRunning(false);
+ h.coordinator.onTurnEvent(sid, 'done');
+ await flush();
+ expect(h.beforeDispatchUserTurn).toHaveBeenLastCalledWith(sid,
+ expect.objectContaining({ clientId: 'internal', botTaskCoordination: internal.botTaskCoordination }));
+ expect(h.sendToAgent).toHaveBeenCalledTimes(2);
+ expect(h.coordinator.isActiveTaskCoordination(sid)).toBe(true);
+ },
+ );
+
it('attributes synchronous provider output to its active input and clears after completion', async () => {
const h = createHarness();
const sid = 'private-reply-attribution';
diff --git a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts
index 860ee0313c..1d35af08f4 100644
--- a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts
+++ b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts
@@ -1216,7 +1216,9 @@ export class AgentInputCoordinator {
/** Only a main-owned accepted receipt can silence this turn. Human steering restores visibility. */
isActiveTaskCoordination(sessionId: string, vendorGeneration?: number): boolean {
const active = this.states.get(sessionId)?.activeTurn;
- return !!active?.item?.botTaskCoordination && !active.latestSteeringClientId
+ // Pending steering attribution precedes policy/attachment/provider acceptance.
+ // Only replacement of active.item after acceptance may release this silence.
+ return !!active?.item?.botTaskCoordination
&& (vendorGeneration === undefined || active.vendorTurnGeneration === null
|| vendorGeneration === active.vendorTurnGeneration);
}
@@ -2260,6 +2262,10 @@ export class AgentInputCoordinator {
typeof item.hostAcceptedAtMs === 'number' && Number.isFinite(item.hostAcceptedAtMs);
}
}
+ // Coordination must wait for its own turn and the normal dispatch-time
+ // relationship check. Read the host-owned row first: UI projections omit
+ // the receipt, and queue-to-steer must not silence an existing user turn.
+ if (item.botTaskCoordination) return false;
if (state.steeringQueueClientIds.includes(item.clientId)) {
log.info('steer ignored: duplicate in-flight clientId (control-side resend)', {
sessionId,