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): reconcile legacy lane permissions from canonical chat

xuzini-xznc61594120d97
diff --git a/apps/desktop/src/main/localDb/client/tx/types.ts b/apps/desktop/src/main/localDb/client/tx/types.ts
index 2b0a89de56..fcdc3ba587 100644
--- a/apps/desktop/src/main/localDb/client/tx/types.ts
+++ b/apps/desktop/src/main/localDb/client/tx/types.ts
@@ -837,6 +837,8 @@ export interface BotGroupsCreateLaneArgs {
export interface BotGroupsCreateLaneResult {
sessionId: string;
created: boolean;
+ /** Existing runtimes must follow a canonical permission repaired during creation. */
+ permissionRepairCanonicalSessionId?: string;
}
/** 伙伴接管的个人 IM 群 / 话题专线(`role = 'channel'`)。 */
@@ -1535,7 +1537,7 @@ export type DbTxResultByName = {
'bots.archiveLifecycle': { sessions: number };
'bots.deleteProfile': { sessionIds: string[]; status: 'archived' | 'deleted' };
'bots.prepareProfileDeletion': undefined;
- 'bots.reconcileLanePermission': { mode: string | null; changed: boolean };
+ 'bots.reconcileLanePermission': { mode: string | null; changed: boolean; canonicalSessionId?: string };
'bots.persistSessionPermission': { updated: boolean };
'bots.createGroupLane': BotGroupsCreateLaneResult;
'bots.createChannelLane': BotGroupsCreateLaneResult;
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
index fe39a4512a..7c668b210e 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
@@ -970,6 +970,28 @@ describe('Bot canonical Session lifecycle', () => {
},
);
+ // #6782, unit: creation repairs in the worker before Main can see the old
+ // Profile. The returned repair receipt must still update an existing runtime.
+ it('repairs legacy permissions during new channel creation and hot-switches an existing lane', async () => {
+ const initial = await invoke('local-db:bots:update', { id: 'bot-1', capabilities: { permissions: 'ask' } });
+ const created = await invoke('local-db:bots:create-canonical-session', {
+ botId: 'bot-1', expectedCanonicalSessionId: null, expectedProfileVersion: initial.currentVersion,
+ });
+ const existing = await ensureBotChannelLaneSession({ botId: 'bot-1', routeKey: 'im:feishu:fixture:g:1', title: 'Old' });
+ if (!existing.ok) throw new Error(existing.message);
+ h.sqlite!.prepare("UPDATE sessions SET permission_mode = 'bypassPermissions' WHERE id = ?").run(created.session.id);
+ const live = { compactSession: vi.fn(), stablePermissionModeState: { mode: 'ask' },
+ setPermissionMode: vi.fn(async (mode: string) => { live.stablePermissionModeState = { mode }; }) };
+ h.getSession.mockImplementation(id => id === existing.sessionId ? live : null);
+ const next = await ensureBotChannelLaneSession({ botId: 'bot-1', routeKey: 'im:feishu:fixture:g:2', title: 'New' });
+ if (!next.ok) throw new Error(next.message);
+ expect(live.stablePermissionModeState.mode).toBe('bypassPermissions');
+ expect(live.setPermissionMode).toHaveBeenCalledTimes(1);
+ expect(h.sqlite!.prepare('SELECT permission_mode FROM sessions WHERE id IN (?, ?, ?)').pluck()
+ .all(created.session.id, existing.sessionId, next.sessionId)).toEqual(Array(3).fill('bypassPermissions'));
+ expect((await invoke('local-db:bots:get', 'bot-1')).capabilities.permissions).toBe('trusted');
+ });
+
// #6782, unit: an explicit idempotent edit is still a new permission intent.
// The previous diff only protected changed=true profile saves.
it('commits an explicit same-value permission after a concurrent composer choice', async () => {
diff --git a/apps/desktop/src/main/localDb/ipc/bots.ts b/apps/desktop/src/main/localDb/ipc/bots.ts
index 849ebf0b28..56fd6b1533 100644
--- a/apps/desktop/src/main/localDb/ipc/bots.ts
+++ b/apps/desktop/src/main/localDb/ipc/bots.ts
@@ -425,6 +425,10 @@ export async function ensureBotGroupLaneSession(input: {
},
});
owner.assertCurrent();
+ if (result.permissionRepairCanonicalSessionId) {
+ await syncBotLinkedLanePermissions(result.permissionRepairCanonicalSessionId);
+ owner.assertCurrent();
+ }
return { ok: true, sessionId: result.sessionId, created: result.created };
}
@@ -548,6 +552,10 @@ export async function ensureBotChannelLaneSession(input: {
throw cause;
}
owner.assertCurrent();
+ if (result.permissionRepairCanonicalSessionId) {
+ await syncBotLinkedLanePermissions(result.permissionRepairCanonicalSessionId);
+ owner.assertCurrent();
+ }
return { ok: true, sessionId: result.sessionId, created: result.created };
}
@@ -679,6 +687,10 @@ export async function ensureBotDmThreadSession(input: {
throw cause;
}
owner.assertCurrent();
+ if (result.permissionRepairCanonicalSessionId) {
+ await syncBotLinkedLanePermissions(result.permissionRepairCanonicalSessionId);
+ owner.assertCurrent();
+ }
return { ok: true, sessionId: result.sessionId, created: result.created };
}
diff --git a/apps/desktop/src/main/localDb/worker/opHandlers/__tests__/botTx.test.ts b/apps/desktop/src/main/localDb/worker/opHandlers/__tests__/botTx.test.ts
index a0bc118dae..f14333b3e3 100644
--- a/apps/desktop/src/main/localDb/worker/opHandlers/__tests__/botTx.test.ts
+++ b/apps/desktop/src/main/localDb/worker/opHandlers/__tests__/botTx.test.ts
@@ -222,8 +222,18 @@ describe('Bot named worker transactions', () => {
tx(db, { name: 'bots.createChannelLane', args: { botId: 'bot-1', routeKey: 'im:feishu:g:2', session: session('new') } });
expect(mode('new')).toBe('bypassPermissions');
db.prepare("UPDATE bot_profile_versions SET capabilities_json = ? WHERE bot_id = 'bot-1'").run(JSON.stringify({ permissions: 'ask' }));
- expect(tx(db, { name: 'bots.reconcileLanePermission', args: { sessionId: 'feishu' } })).toMatchObject({ mode: 'ask' });
- expect(mode('feishu')).toBe('ask');
+ expect(tx(db, { name: 'bots.reconcileLanePermission', args: { sessionId: 'feishu' } }))
+ .toMatchObject({ mode: 'bypassPermissions', canonicalSessionId: 'main' });
+ expect(['main', 'feishu', 'group', 'thread', 'new'].map(mode))
+ .toEqual(Array(5).fill('bypassPermissions'));
+ expect(JSON.parse(db.prepare('SELECT capabilities_json FROM bot_profile_versions WHERE bot_id = ?').pluck().get('bot-1') as string).permissions)
+ .toBe('trusted');
+ // Main is authoritative in both directions; never choose the widest snapshot.
+ db.prepare("UPDATE sessions SET permission_mode = 'ask' WHERE id = 'main'").run();
+ expect(tx(db, { name: 'bots.reconcileLanePermission', args: { sessionId: 'main' } }))
+ .toMatchObject({ mode: 'ask', canonicalSessionId: 'main' });
+ expect(['main', 'feishu', 'group', 'thread', 'new'].map(mode)).toEqual(Array(5).fill('ask'));
+ expect(['delegation', 'history'].map(mode)).toEqual(['ask', 'ask']);
expect(tx(db, { name: 'bots.reconcileLanePermission', args: { sessionId: 'history' } })).toMatchObject({ mode: null });
expect(db.prepare('SELECT COUNT(*) FROM sessions').pluck().get()).toBe(7);
});
diff --git a/apps/desktop/src/main/localDb/worker/opHandlers/tx.ts b/apps/desktop/src/main/localDb/worker/opHandlers/tx.ts
index b95f0aae2e..156df7182f 100644
--- a/apps/desktop/src/main/localDb/worker/opHandlers/tx.ts
+++ b/apps/desktop/src/main/localDb/worker/opHandlers/tx.ts
@@ -834,8 +834,9 @@ function botsCreateGroupLane(db: Database.Database, args: BotGroupsCreateLaneArg
(id, bot_id, session_id, profile_version, role, route_key, created_at, archived_at)
VALUES (?, ?, ?, ?, 'group', ?, ?, NULL)`)
.run(`${botId}:${sessionId}`, botId, sessionId, profile.version, routeKey, createdAt);
- botsReconcileLanePermission(db, { sessionId });
- return { sessionId, created: true };
+ const permission = botsReconcileLanePermission(db, { sessionId });
+ return { sessionId, created: true,
+ ...(permission.canonicalSessionId ? { permissionRepairCanonicalSessionId: permission.canonicalSessionId } : {}) };
})();
}
@@ -870,8 +871,9 @@ function botsCreateChannelLane(db: Database.Database, args: BotsCreateChannelLan
(id, bot_id, session_id, profile_version, role, route_key, created_at, archived_at)
VALUES (?, ?, ?, ?, 'channel', ?, ?, NULL)`)
.run(`${botId}:${sessionId}`, botId, sessionId, profile.version, routeKey, createdAt);
- botsReconcileLanePermission(db, { sessionId });
- return { sessionId, created: true };
+ const permission = botsReconcileLanePermission(db, { sessionId });
+ return { sessionId, created: true,
+ ...(permission.canonicalSessionId ? { permissionRepairCanonicalSessionId: permission.canonicalSessionId } : {}) };
})();
}
@@ -915,8 +917,9 @@ function botsCreateThreadLane(db: Database.Database, args: BotsCreateThreadLaneA
(id, bot_id, session_id, profile_version, role, route_key, created_at, archived_at)
VALUES (?, ?, ?, ?, 'thread', ?, ?, NULL)`)
.run(`${botId}:${sessionId}`, botId, sessionId, profile.version, routeKey, createdAt);
- botsReconcileLanePermission(db, { sessionId });
- return { sessionId, created: true };
+ const permission = botsReconcileLanePermission(db, { sessionId });
+ return { sessionId, created: true,
+ ...(permission.canonicalSessionId ? { permissionRepairCanonicalSessionId: permission.canonicalSessionId } : {}) };
})();
}
@@ -1302,16 +1305,18 @@ function botsPersistSessionPermission(
})();
}
-/** Repair old lane snapshots from the active Profile, never from the widest stored value. */
-function botsReconcileLanePermission(db: Database.Database, args: unknown): { mode: string | null; changed: boolean } {
+/** Repair conflicting Bot snapshots from the active canonical Chat, not the widest lane. */
+function botsReconcileLanePermission(db: Database.Database, args: unknown): { mode: string | null; changed: boolean; canonicalSessionId?: string } {
const sessionId = expectString(asRecord(args, 'args').sessionId, 'sessionId');
return db.transaction(() => {
- const row = db.prepare(`SELECT v.capabilities_json AS json FROM bot_session_links l
+ const row = db.prepare(`SELECT v.capabilities_json AS json, l.bot_id AS botId, l.role,
+ s.permission_mode AS previousMode FROM bot_session_links l
JOIN sessions s ON s.id = l.session_id
JOIN bot_profiles p ON p.id = l.bot_id
LEFT JOIN bot_profile_versions v ON v.bot_id = p.id AND v.version = p.current_version
- WHERE l.session_id = ? AND l.role IN ('channel', 'group', 'thread') AND l.archived_at IS NULL
- AND s.source = 'bot' AND s.status = 'active' AND p.status = 'active'`).get(sessionId) as { json: string | null } | undefined;
+ WHERE l.session_id = ? AND l.role IN ('canonical', 'channel', 'group', 'thread') AND l.archived_at IS NULL
+ AND s.source = 'bot' AND s.status = 'active' AND p.status = 'active'`).get(sessionId) as
+ { json: string | null; botId: string; role: string; previousMode: string } | undefined;
if (!row) return { mode: null, changed: false };
let parsed: unknown;
try { parsed = typeof row.json === 'string' ? JSON.parse(row.json) : null; }
@@ -1320,6 +1325,27 @@ function botsReconcileLanePermission(db: Database.Database, args: unknown): { mo
throw Object.assign(new Error('Bot profile capabilities are unreadable'), { code: 'PRECONDITION_FAILED' });
}
const config = parsed as Record<string, unknown>;
+ const canonical = db.prepare(`SELECT s.id, s.permission_mode AS mode FROM bot_session_links l
+ JOIN sessions s ON s.id = l.session_id
+ WHERE l.bot_id = ? AND l.role = 'canonical' AND l.archived_at IS NULL
+ AND s.source = 'bot' AND s.status = 'active'`).get(row.botId) as { id: string; mode: string } | undefined;
+ if (canonical && ['ask', 'auto', 'bypassPermissions'].includes(canonical.mode)) {
+ const permission = canonical.mode === 'bypassPermissions' ? 'trusted' : canonical.mode;
+ const staleLane = db.prepare(`SELECT 1 FROM bot_session_links l JOIN sessions s ON s.id = l.session_id
+ WHERE l.bot_id = ? AND l.role IN ('channel', 'group', 'thread') AND l.archived_at IS NULL
+ AND s.source = 'bot' AND s.status = 'active' AND s.permission_mode != ? LIMIT 1`)
+ .get(row.botId, canonical.mode);
+ if (config.permissions !== permission || staleLane) {
+ // The read and cascade share this transaction: a later explicit tightening
+ // cannot be undone by an earlier snapshot. Preserve all other capabilities.
+ botsPersistSessionPermission(db, { sessionId: canonical.id, mode: canonical.mode });
+ return { mode: canonical.mode, changed: row.previousMode !== canonical.mode, canonicalSessionId: canonical.id };
+ }
+ return { mode: canonical.mode, changed: false };
+ }
+ // Legacy session-only modes have no Profile equivalent. Do not convert them
+ // implicitly; lanes retain the configured Profile when no three-way mode exists.
+ if (row.role === 'canonical') return { mode: null, changed: false };
const mode = config.permissions === 'trusted' ? 'bypassPermissions' : config.permissions === 'auto' ? 'auto' : 'ask';
const changed = db.prepare('UPDATE sessions SET permission_mode = ?, updated_at = ? WHERE id = ? AND permission_mode != ?')
.run(mode, Date.now(), sessionId, mode).changes > 0;
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/sessionPermissionPersistence.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/sessionPermissionPersistence.test.ts
index b669520937..85b6c97251 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/sessionPermissionPersistence.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/sessionPermissionPersistence.test.ts
@@ -131,6 +131,37 @@ describe('permission persistence without a live runtime', () => {
expect(good.stablePermissionModeState.mode).toBe('ask');
});
+ // #6782, unit: a legacy main/Profile disagreement survived the original fix.
+ // Minimal input: main bypass + Profile ask + existing ask lane. Calling the real
+ // send/reuse reconciliation must repair both stored siblings and live runtimes.
+ it.each([
+ ['bypassPermissions', 'ask', 'trusted'],
+ ['ask', 'bypassPermissions', 'ask'],
+ ])('uses main %s to repair stale %s lanes and Profile together', async (mainMode, staleMode, permission) => {
+ sqlite.prepare("UPDATE sessions SET permission_mode = ? WHERE id = 'chat'").run(mainMode);
+ sqlite.prepare('UPDATE bot_profile_versions SET capabilities_json = ?')
+ .run(JSON.stringify({ permissions: staleMode === 'ask' ? 'ask' : 'trusted', memory: true }));
+ sqlite.exec(`INSERT INTO sessions (id, permission_mode, updated_at) VALUES ('lane','ask',1), ('sibling','ask',1);
+ INSERT INTO bot_session_links VALUES ('bot-1','lane','channel',NULL), ('bot-1','sibling','group',NULL);`);
+ sqlite.prepare("UPDATE sessions SET permission_mode = ? WHERE id != 'chat'").run(staleMode);
+ for (const id of ['lane', 'sibling']) {
+ const live = { stablePermissionModeState: { mode: staleMode }, setPermissionMode: vi.fn(async (mode: string) => { live.stablePermissionModeState = { mode }; }) };
+ h.live.set(id, live);
+ }
+ await syncBotLanePermission('lane');
+ expect(sqlite.prepare('SELECT DISTINCT permission_mode FROM sessions').pluck().all()).toEqual([mainMode]);
+ expect(JSON.parse(sqlite.prepare('SELECT capabilities_json FROM bot_profile_versions').pluck().get() as string))
+ .toEqual({ permissions: permission, memory: true });
+ for (const id of ['lane', 'sibling']) {
+ expect(h.live.get(id)?.stablePermissionModeState.mode).toBe(mainMode);
+ expect(h.patched).toHaveBeenCalledWith(id, { permissionMode: mainMode });
+ expect(h.live.get(id)?.setPermissionMode).toHaveBeenCalledTimes(1);
+ }
+ // Reload/next send keeps the repaired authority without another hot switch.
+ await syncBotLanePermission('lane');
+ expect(h.live.get('lane')?.setPermissionMode).toHaveBeenCalledTimes(1);
+ });
+
it('serializes successive lane updates and discards an outgoing account continuation', async () => {
sqlite.exec(`INSERT INTO sessions (id, permission_mode, updated_at) VALUES ('lane','bypassPermissions',1);
INSERT INTO bot_session_links VALUES ('bot-1','lane','channel',NULL);`);
@@ -152,6 +183,35 @@ describe('permission persistence without a live runtime', () => {
expect(h.patched).not.toHaveBeenCalled();
});
+ // Distinct failure branch: repair has already cascaded saved permissions, but
+ // the initiating runtime rejects. Siblings must still consume the repair.
+ it('finishes a legacy repair on sibling runtimes after the initiating hot switch fails', async () => {
+ sqlite.exec(`UPDATE bot_profile_versions SET capabilities_json = '{"permissions":"trusted"}';
+ INSERT INTO sessions (id, permission_mode, updated_at) VALUES ('bad','bypassPermissions',1), ('good','bypassPermissions',1);
+ INSERT INTO bot_session_links VALUES ('bot-1','bad','channel',NULL), ('bot-1','good','channel',NULL);`);
+ const good = { stablePermissionModeState: { mode: 'bypassPermissions' }, setPermissionMode: vi.fn(async (mode: string) => { good.stablePermissionModeState = { mode }; }) };
+ h.live.set('bad', { stablePermissionModeState: { mode: 'bypassPermissions' }, setPermissionMode: vi.fn(async () => { throw new Error('switch failed'); }) });
+ h.live.set('good', good);
+ await expect(syncBotLanePermission('bad')).rejects.toThrow('switch failed');
+ expect(h.live.has('bad')).toBe(false);
+ expect(good.stablePermissionModeState.mode).toBe('ask');
+ expect(sqlite.prepare('SELECT DISTINCT permission_mode FROM sessions').pluck().all()).toEqual(['ask']);
+ });
+
+ it.each(['missing', 'plan'])('keeps Profile authority for lanes when main is %s', async kind => {
+ if (kind === 'missing') sqlite.exec("DELETE FROM sessions WHERE id = 'chat'");
+ else sqlite.exec("UPDATE sessions SET permission_mode = 'plan' WHERE id = 'chat'");
+ sqlite.exec(`UPDATE bot_profile_versions SET capabilities_json = '{"permissions":"trusted"}';
+ INSERT INTO sessions (id, permission_mode, updated_at) VALUES ('lane','ask',1);
+ INSERT INTO bot_session_links VALUES ('bot-1','lane','channel',NULL);`);
+ await syncBotLanePermission('lane');
+ expect(sqlite.prepare("SELECT permission_mode FROM sessions WHERE id = 'lane'").pluck().get()).toBe('bypassPermissions');
+ if (kind === 'plan') {
+ await syncBotLanePermission('chat');
+ expect(sqlite.prepare("SELECT permission_mode FROM sessions WHERE id = 'chat'").pluck().get()).toBe('plan');
+ }
+ });
+
it.each(['missing', 'malformed'])('does not keep old authority when the active Profile is %s', async failure => {
sqlite.exec(`INSERT INTO sessions (id, permission_mode, updated_at) VALUES ('lane','bypassPermissions',1);
INSERT INTO bot_session_links VALUES ('bot-1','lane','channel',NULL);`);
diff --git a/apps/desktop/src/main/maker-ipc/botPermissionSync.ts b/apps/desktop/src/main/maker-ipc/botPermissionSync.ts
index 26a537a313..392201a163 100644
--- a/apps/desktop/src/main/maker-ipc/botPermissionSync.ts
+++ b/apps/desktop/src/main/maker-ipc/botPermissionSync.ts
@@ -9,39 +9,50 @@ import { withSessionPermissionChange } from './sessionPermissionChange.js';
export async function syncBotLanePermission(sessionId: string): Promise<void> {
const owner = getCurrentDbClientSnapshot();
if (!owner) return;
- await withSessionPermissionChange(sessionId, async () => {
- const assertCurrent = () => {
- if (getCurrentDbClientSnapshot() !== owner) throw new Error('Account changed during lane permission update');
- };
- assertCurrent();
- let saved: { mode: string | null; changed: boolean };
- try {
- saved = await owner.client.tx('bots.reconcileLanePermission', { sessionId });
- } catch (error) {
+ let repairedCanonicalSessionId: string | undefined;
+ try {
+ await withSessionPermissionChange(sessionId, async () => {
+ const assertCurrent = () => {
+ if (getCurrentDbClientSnapshot() !== owner) throw new Error('Account changed during lane permission update');
+ };
assertCurrent();
- const maker = getMakerIfReady();
- if (maker?.getSession(sessionId)) await maker.closeSession(sessionId);
- throw error;
- }
- const { mode, changed } = saved;
- assertCurrent();
- if (!mode) return;
- const maker = getMakerIfReady();
- const live = maker?.getSession(sessionId);
- if (changed || (live && live.stablePermissionModeState?.mode !== mode)) forgetCredentialGrants(sessionId);
- if (live && live.stablePermissionModeState?.mode !== mode) {
+ let saved: { mode: string | null; changed: boolean; canonicalSessionId?: string };
try {
- await live.setPermissionMode(mode as PermissionMode);
+ saved = await owner.client.tx('bots.reconcileLanePermission', { sessionId });
} catch (error) {
assertCurrent();
- // Never leave a failed tightening running with its previous authority.
- if (maker?.getSession(sessionId) === live) await maker.closeSession(sessionId);
+ const maker = getMakerIfReady();
+ if (maker?.getSession(sessionId)) await maker.closeSession(sessionId);
throw error;
}
+ const { mode, changed } = saved;
assertCurrent();
+ repairedCanonicalSessionId = saved.canonicalSessionId;
+ if (!mode) return;
+ const maker = getMakerIfReady();
+ const live = maker?.getSession(sessionId);
+ if (changed || (live && live.stablePermissionModeState?.mode !== mode)) forgetCredentialGrants(sessionId);
+ if (live && live.stablePermissionModeState?.mode !== mode) {
+ try {
+ await live.setPermissionMode(mode as PermissionMode);
+ } catch (error) {
+ assertCurrent();
+ // Never leave a failed tightening running with its previous authority.
+ if (maker?.getSession(sessionId) === live) await maker.closeSession(sessionId);
+ throw error;
+ }
+ assertCurrent();
+ }
+ broadcastSessionPatched(sessionId, { permissionMode: mode });
+ });
+ } finally {
+ // Release the current lane's fence before visiting siblings (including this
+ // lane). The transaction has already repaired their saved values atomically.
+ // Even a failed hot switch must not strand other running lanes on old authority.
+ if (repairedCanonicalSessionId && getCurrentDbClientSnapshot() === owner) {
+ await syncBotLinkedLanePermissions(repairedCanonicalSessionId);
}
- broadcastSessionPatched(sessionId, { permissionMode: mode });
- });
+ }
}
/** Called after a canonical save; delegated work and archived history keep their own authority. */
diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.md
index a5a3353fc7..9ffbb4faa5 100644
--- a/docs/product-rules/cindy-bots-runtime.md
+++ b/docs/product-rules/cindy-bots-runtime.md
@@ -135,9 +135,13 @@ Telegram 设为全响应的群;设置页的人格与行为配置不带。移
较早读取的 Profile 快照不能在稍后保存时撤销主人刚完成的权限提升或收紧。
设置页与主任务显式切档共用包含数据库与运行态的完整提交顺序;即使保存界面当前显示的
同一档位,也按提交时的最新 Profile 对齐,不能因早读快照看似未变而漏写权限。
-存量专线在复用与发送前从当前 Profile 恢复,历史与委派任务不批量改档,也不删消息。
-若历史主任务与 Profile 已分歧,不能推断哪次选择更新:专线以 Profile 为准,不取最宽值;
-用户在主任务重新选择所需权限后,主任务、Profile 与专线重新对齐。实现与回归见
+存量权限冲突以当前有效主任务的 Ask / Auto / 完全访问档为准:创建、复用专线或发送前,
+在同一事务将主任务当前档写回 Profile 与所有有效群、渠道、私聊话题专线,并同步已有运行实例。
+例如主任务完全访问、Profile 与飞书专线为 Ask 时,自动统一为完全访问,不要求主人重新选档。
+反向冲突同样跟随主任务收紧,不从各专线中取最宽值;历史与委派任务不批量改档,也不删消息。
+没有有效主任务或主任务仍为不映射到 Profile 的旧权限模式时,专线继续读取当前 Profile,
+不擅自转换主任务旧模式。此规则只修复已有矛盾;之后主任务与设置页的显式切档仍按上述同一事务保存。
+实现与回归见
`maker-ipc/botPermissionSync.ts`、`sessionPermissionPersistence.test.ts` 与 `botTx.test.ts`。
渠道行为:表情、回复引用档位用默认值,不读 设置 → IM 机器人 的人格与行为配置(伙伴的身份与分寸来自 SOUL);
群参与模式(仅 @ / 全响应)按连接各一份,存在连接记录里,由「消息平台」页每条 Telegram 连接下的「群聊」小节