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(teammates): keep admitted queued task messages until real revocation

Dash2ddc447d5408
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 e950db058a..e1422598e2 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
@@ -89,6 +89,8 @@ const mocks = vi.hoisted(() => {
describe('task action dispatch authorization', () => {
// Unit regression through the production coordinator: revocation/restore cannot
// deliver an automatic message, while the following owner input still runs.
+ // teammate-authority.md「延迟投递只认真实撤权」: the revoked item settles before the
+ // send transaction, so the receiving task gets no user row or failed reply for it.
it.each(['revoked', 'restored'] as const)('discards %s automatic input without blocking owner input', async mode => {
const h = createHarness(), sid = 'task-action-target';
let current = true;
@@ -111,9 +113,11 @@ describe('task action dispatch authorization', () => {
h.coordinator.wakeSession(sid, 'idle');
await vi.waitFor(() => expect(dispatched).toHaveBeenCalledOnce());
await flush();
- expect(h.sendToAgent.mock.calls[1]![3].persistUserMessage?.clientId).toBe('owner');
+ expect(h.sendToAgent).toHaveBeenCalledOnce();
+ expect(h.sendToAgent.mock.calls[0]![3].persistUserMessage?.clientId).toBe('owner');
expect(h.onDiscardedQueuedMessage).toHaveBeenCalledWith(sid, expect.objectContaining({ clientId: 'automatic' }));
- expect(h.coordinator.getProjection(sid).pendingQueue).toEqual([]);
+ expect(h.onUndispatchedUserTurn).not.toHaveBeenCalled();
+ expect(h.coordinator.getProjection(sid)).toMatchObject({ error: null, pendingQueue: [] });
});
});
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/taskActionAuthorization.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/taskActionAuthorization.test.ts
index c4be07cd9a..7d32aa16d1 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/taskActionAuthorization.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/taskActionAuthorization.test.ts
@@ -434,7 +434,10 @@ describe('Owner-delegated scheduled task actions', () => {
expect(effect).not.toHaveBeenCalled();
});
- it.each(['permission', 'plan', 'instance', 'account', 'input'] as const)('invalidates admission and delayed delivery after %s changes', async changed => {
+ // teammate-authority.md「延迟投递只认真实撤权」(2026-10-30): live turn facts still
+ // expire the admission, but only real revocation stops a queued message. Before,
+ // any of these rollovers between turns dropped every supplement still queued.
+ it.each(['permission', 'plan', 'instance', 'account', 'input'] as const)('invalidates admission after %s changes; delayed delivery stops only on account change', async changed => {
const h = scheduledFixture();
const queued = input();
const guard = await withToolCallAuthority(h.authorize, scheduledSend(), async () => {
@@ -450,7 +453,9 @@ describe('Owner-delegated scheduled task actions', () => {
if (changed === 'account') hostFacts.boundaryPending.mockReturnValue(true);
if (changed === 'input') h.activeInput.boundary = 'replacement-runtime';
expect(() => guard()).toThrow('AUTHORIZATION_EXPIRED');
- await expect(taskActionInputGuard('target', queued)!()).rejects.toThrow('AUTHORIZATION_EXPIRED');
+ const delivery = expect(taskActionInputGuard('target', queued)!());
+ if (changed === 'account') await delivery.rejects.toThrow('AUTHORIZATION_EXPIRED');
+ else await delivery.resolves.toBeUndefined();
});
it.each(['permission', 'account', 'turn'] as const)('does not act or prompt if %s changes during review', async changed => {
@@ -513,7 +518,7 @@ describe('Desktop owner input task actions', () => {
);
it.each(['bypassPermissions', 'auto', 'ask'])(
- 'revokes the %s admission before execution and delayed delivery when live permissions change', async permissionMode => {
+ 'revokes the %s admission before execution but keeps its queued message when live permissions change', async permissionMode => {
const h = desktopFixture('private');
let current = true;
h.activeInput.permission = {
@@ -529,7 +534,7 @@ describe('Desktop owner input task actions', () => {
current = false;
const effect = vi.fn(async () => 'changed');
await expect(decision.run(effect)).rejects.toThrow('AUTHORIZATION_EXPIRED');
- await expect(taskActionInputGuard('target', queued)!()).rejects.toThrow('AUTHORIZATION_EXPIRED');
+ await expect(taskActionInputGuard('target', queued)!()).resolves.toBeUndefined();
expect(() => syncGuard()).toThrow('AUTHORIZATION_EXPIRED');
expect(effect).not.toHaveBeenCalled();
},
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 e54be56043..e4e7de4e3d 100644
--- a/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts
+++ b/apps/desktop/src/main/maker-ipc/agent-input-coordinator.ts
@@ -5067,7 +5067,22 @@ export class AgentInputCoordinator {
this.emit(sessionId);
let appMessageGuardRejected = false;
+ const taskActionGuard = taskActionInputGuard(sessionId, head);
try {
+ if (taskActionGuard) {
+ // A revoked task action settles before screening, persistence or a vendor
+ // turn, so the receiving task never shows a failed reply for it. The send
+ // transaction still rechecks the same guard at dispatch.
+ const revoked = await taskActionGuard().then(() => null, (error: unknown) => ({ error }));
+ if (!this.isActiveTurnCurrent(sessionId, active)) return;
+ if (revoked) {
+ log.info('discarding revoked task action input before dispatch', {
+ sessionId, clientId: head.clientId, reason: errorMessage(revoked.error),
+ });
+ this.discardRevokedAppInput(sessionId, active, head);
+ return;
+ }
+ }
// 意识拦截钩(订阅槽①):落库/派发之前问一遍——block 即丢弃本项
// (不入库不起 turn),通知宿主降级气泡,继续放行后续排队消息;
// rewrite 用新正文替换 head(送 agent / 落库 / 显示都用它),通知宿主
@@ -5134,7 +5149,7 @@ export class AgentInputCoordinator {
// may synchronously emit the new turn's started marker before it returns;
// post-dispatch acknowledgements must remain older than that marker.
const preVendorDispatchAt = Math.max(0, Date.now() - 1);
- const appMessageGuard = combineInputGuards(queuedAppMessageGuard(head), taskActionInputGuard(sessionId, head));
+ const appMessageGuard = combineInputGuards(queuedAppMessageGuard(head), taskActionGuard);
const result = await this.deps.sendToAgent(sessionId, makerUserMessage, head.createOpts, {
...(appMessageGuard ? { [MCP_APP_MESSAGE_GUARD]: async () => {
try {
diff --git a/apps/desktop/src/main/maker-ipc/taskActionAuthorization.ts b/apps/desktop/src/main/maker-ipc/taskActionAuthorization.ts
index 857180f5fd..20fa1c80c6 100644
--- a/apps/desktop/src/main/maker-ipc/taskActionAuthorization.ts
+++ b/apps/desktop/src/main/maker-ipc/taskActionAuthorization.ts
@@ -68,10 +68,11 @@ export interface TaskActionScope {
routine?: { botId: string; id: string; revision: number };
/** Existing, explicitly confirmed delegation; never inferred from creator/follower. */
delegated: boolean;
- /** Rechecked at mutation/delivery; includes account, target and delegation revocation. */
+ /** Rechecked at mutation; includes account, target and delegation revocation. */
assertCurrent(): Promise<void>;
/** Host generation check for existing synchronous commit/pre-send callbacks. */
assertCurrentSync?(): void;
+ /** Queued delivery outlives the admitting turn: real revocation only, no live turn facts. */
assertDeliveryCurrent?(): Promise<void>;
}
diff --git a/apps/desktop/src/main/maker-ipc/taskActionHost.ts b/apps/desktop/src/main/maker-ipc/taskActionHost.ts
index a764ee0031..5de0de28e7 100644
--- a/apps/desktop/src/main/maker-ipc/taskActionHost.ts
+++ b/apps/desktop/src/main/maker-ipc/taskActionHost.ts
@@ -305,14 +305,14 @@ export function createDesktopTaskActionAuthorizer(deps: {
return team ?? null;
};
const orcaTeam = useRuntimePermissions ? null : await readOrcaTeam();
+ // An admitted message outlives the turn that sent it. Delivery stops only on
+ // real revocation: account switch, sender cleared or deleted, companion paused
+ // or archived, delegation run or team changed, group grant. The sender's live
+ // Session incarnation, input generation and permission/Plan generation gate
+ // executing this call (assertCurrent), never an already queued message.
const assertDeliveryCurrent = async () => {
- runtime?.assertCurrent();
await group?.refresh();
- if (
- isAppSessionBoundaryPending() ||
- db !== tryGetDbClient() ||
- deps.input(sessionId).boundary !== input.boundary
- )
+ if (isAppSessionBoundaryPending() || db !== tryGetDbClient())
throw new Error('TASK_ACTION_AUTHORIZATION_EXPIRED');
const [fresh] = await db.drizzle
.select({
@@ -343,10 +343,8 @@ export function createDesktopTaskActionAuthorizer(deps: {
throw new Error('TASK_ACTION_AUTHORIZATION_EXPIRED');
}
group?.assertCurrent();
- assertPermissionCurrent();
if (db !== tryGetDbClient() || isAppSessionBoundaryPending())
throw new Error('OWNER_SCOPE_CHANGED');
- runtime?.assertCurrent();
};
const assertCurrentSync = () => {
runtime?.assertInputCurrent();
diff --git a/docs/product-rules/teammate-authority.md b/docs/product-rules/teammate-authority.md
index c47b7fc4fb..9768907f6b 100644
--- a/docs/product-rules/teammate-authority.md
+++ b/docs/product-rules/teammate-authority.md
@@ -45,7 +45,14 @@
- 代答许可在确认正文完整展示子任务当前请求的工具、参数(或计划)与请求 ID,不依赖截短的工具预览,绑定该实际请求;
原请求已处理或被新请求替换时,旧卡不能批准新请求。
- 拒绝、取消、停止或任务关闭不执行;晚到回答不恢复旧操作。断线重连读取既有待处理请求,不重新派发操作。
-- 同意到执行及延迟投递仍校验账号、实例、输入、权限与 Plan 代次;变更使旧放行失效。
+- 同意到执行仍校验账号、实例、输入、权限与 Plan 代次;变更使这次放行失效。
+- **延迟投递只认真实撤权**(2026-10-30 用户裁决:能力优先):已准入的消息因目标忙而排队后,
+ 发起轮结束、发起方 Session 重建、换新输入,或发起方的权限档、计划模式变化,都不撤销这条消息;
+ 它由接收任务按自己的权限执行,主人可以在接收任务的队列里编辑或撤回。只有切换账号、发起任务被
+ 清空或删除、伙伴被暂停或归档、委派执行代次或 Orca 团队变化、群授权失效时才不再投递;这类消息在
+ 落库前移出队列,不在接收任务里留下失败回复。实现见 `taskActionHost.ts` 的 `assertDeliveryCurrent`
+ 与 `agent-input-coordinator.ts` 的派发前复核;回归见 `taskActionAuthorization.test.ts` 与
+ `agent-input-coordinator.test.ts`。
- 来源判定与操作决定分别保留。获准自主操作不会给后续转达生成主人原话凭证。
## 转达主人原话(请求来源)
@@ -57,10 +64,9 @@
它不等同于主人刚刚亲手输入,应用更新等专门要求本人输入的操作保持原有边界。
- 空闲、繁忙和新建任务共用持久输入协调器,插话、重试及历史恢复都保留原话;审核上下文不采用 Agent 补充
里的授权说法。原话不明或缺少背景时,先按来源任务查上下文,只有仍缺少必要决定才向主人提问。
-- 已准入的后台任务补充消息排队后,实际接受时复核投递范围,不再要求发起轮仍是同一条输入;
- 发起轮正常结束或换新输入不撤销这条消息。账号、权限档、计划模式、群权限和委派执行代次等
- 真实撤权仍生效,新写操作仍复核当前输入。实现见 `botDelegationService.ts` 的
- `dispatchTrackedInput`;回归见 `botCanonicalSession.test.ts` 的排队补充与接受回调用例。
+- 已准入的后台任务补充消息排队后按上文「延迟投递只认真实撤权」送达,实际接受时复核委派执行代次;
+ 新写操作仍复核当前输入。实现见 `botDelegationService.ts` 的 `dispatchTrackedInput`;回归见
+ `botCanonicalSession.test.ts` 的排队补充与接受回调用例。
- IM 轮次不经过输入协调器:原话取自 IM 运行器写在逐轮租约上的本轮落库消息(`inputClientId`),
只在租约的发言人是主人时读取。
- 主人输入被自动续跑(包括生成的「继续」消息)仍算主人代办,但不算新的主人输入,