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(orca): 运行时不在了用独立基线比,别把冷启档位当撤销

Zhang Yunjin9a84e2118b33
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/orcaTeamService.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/orcaTeamService.test.ts
index 468ecab1f8..614cede8a0 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaTeamService.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaTeamService.test.ts
@@ -3878,6 +3878,17 @@ return captureOrcaDeliveryAuthority;`, {
await expect(assertDelivery()).resolves.toBeUndefined();
});
+ it('keeps a resumed runtime mode that the persisted row does not carry', async () => {
+ // A cold resume can run a stricter/looser mode than the row without rewriting it.
+ const h = compile(row({ permissionMode: 'ask' }));
+ h.setLive(permission('bypassPermissions', 1));
+ const assertDelivery = await h.authorize();
+
+ // Idle release: the row still says ask, and the user changed nothing.
+ h.setLive(null);
+ await expect(assertDelivery()).resolves.toBeUndefined();
+ });
+
it('rejects delivery while the owner is switching permissions or when the mode changed', async () => {
const h = compile(row());
h.setLive(permission('bypassPermissions', 3));
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index 35b140e7e5..76a95469af 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -15506,20 +15506,19 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
};
const sessionAtCapture = await readSessionRow();
const liveAtCapture = maker.getSession(leadSessionId);
- // Permission baselines are persisted semantics: instance generation counters restart on
- // rehydrate, so they can never be compared across a released runtime. Fall back to the row
- // when the runtime has no stable snapshot at admission.
- const permissionAtCapture = liveAtCapture?.stablePermissionModeState && liveAtCapture.stablePlanModeState
+ // Two baselines, each compared against its own source: a resumed runtime can run a
+ // permission mode the row does not carry (and the row is not rewritten for it), so mixing
+ // them would cancel a valid dispatch after the runtime is released. Instance generation
+ // counters restart on rehydrate, so only the semantics are ever compared.
+ const livePermissionAtCapture = liveAtCapture?.stablePermissionModeState && liveAtCapture.stablePlanModeState
? {
mode: liveAtCapture.stablePermissionModeState.mode,
planEnabled: liveAtCapture.stablePlanModeState.enabled,
}
- : sessionAtCapture
- ? {
- mode: sessionAtCapture.permissionMode,
- planEnabled: sessionAtCapture.planModeEnabled,
- }
- : null;
+ : null;
+ const persistedPermissionAtCapture = sessionAtCapture
+ ? { mode: sessionAtCapture.permissionMode, planEnabled: sessionAtCapture.planModeEnabled }
+ : null;
return async () => {
if (epoch !== getCurrentDbClientSnapshot()) throw new PluginTaskError('PERMISSION_DENIED', 'Account changed');
if (isAppSessionBoundaryPending()) throw new PluginTaskError('HOST_NOT_READY', 'Account is switching');
@@ -15537,12 +15536,13 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
// snapshot while the owner is changing it.
if (!permission || !plan)
throw new PluginTaskError('PERMISSION_DENIED', 'Task permissions are changing');
- if (permissionAtCapture && (permission.mode !== permissionAtCapture.mode
- || plan.enabled !== permissionAtCapture.planEnabled))
+ if (!livePermissionAtCapture
+ || permission.mode !== livePermissionAtCapture.mode
+ || plan.enabled !== livePermissionAtCapture.planEnabled)
throw new PluginTaskError('PERMISSION_DENIED', 'Task permissions changed before delivery');
- } else if (permissionAtCapture
- && (row.permissionMode !== permissionAtCapture.mode
- || row.planModeEnabled !== permissionAtCapture.planEnabled)) {
+ } else if (!persistedPermissionAtCapture
+ || row.permissionMode !== persistedPermissionAtCapture.mode
+ || row.planModeEnabled !== persistedPermissionAtCapture.planEnabled) {
// An absent runtime is released or not rehydrated yet, not a revocation by itself —
// but the persisted row is then the only authority left to compare against.
throw new PluginTaskError('PERMISSION_DENIED', 'Task permissions changed before delivery');
diff --git a/docs/dev-rules/orca-team-architecture.md b/docs/dev-rules/orca-team-architecture.md
index f4990f0055..9b95de5507 100644
--- a/docs/dev-rules/orca-team-architecture.md
+++ b/docs/dev-rules/orca-team-architecture.md
@@ -437,9 +437,10 @@ Worker turn 被 vendor 报终止型 error,但 interrupted-turn auto-resume 仍
排队消息的 accepted 回调要等目标排空队列才跑,此时发起它的那一轮早已结束;因此它只能复核
交付级不变量(账号 epoch、会话行仍 active 且 `cleared_at` 未变、任务归属未变、权限档未被撤销、
Worker 仍属于该 Lead 的活跃团队),不能复用轮次级凭证(本轮输入来源、`turnOrigin`)。
- 运行时被释放/重建本身不算撤销:权限按持久化的 permission mode / Plan 与准入快照比对
- (不能比 live 会话的 generation 计数——它随实例重建归零);权限档正在切换(stable 快照为空)
- 时拒绝投递。独立 UI 的 done 确认不带调用方凭证,不取交付凭证。
+ 运行时被释放/重建本身不算撤销:运行时在时比 live 档位、运行时不在时比持久化的
+ permission mode / Plan,两条基线各自取自对应来源(冷启恢复可能跑着与库不同的档位,混用会
+ 误取消);不能比 live 会话的 generation 计数——它随实例重建归零。权限档正在切换(stable
+ 快照为空)时拒绝投递。独立 UI 的 done 确认不带调用方凭证,不取交付凭证。
只有身份/归属/权限真的变了才取消,并按既有 rollback 恢复;accepted 里的状态写与广播
失败仍走既有失败路径(簿记失败是否该取消投递是另一个议题,另单处理)。同步控制面(归档、结束团队、
改名、切焦点、队列增删改)仍用轮次凭证。实现指针:`register.ts` 的 `captureOrcaPluginAuthority`(轮次)与