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(im): 将历史图片标识纳入容量统计与回收

Dashb124821fd538
diff --git a/apps/desktop/drizzle/0136_bizarre_pet_avengers.sql b/apps/desktop/drizzle/0136_bizarre_pet_avengers.sql
index bc3ceca2bf..cab603e7ce 100644
--- a/apps/desktop/drizzle/0136_bizarre_pet_avengers.sql
+++ b/apps/desktop/drizzle/0136_bizarre_pet_avengers.sql
@@ -1 +1,38 @@
-ALTER TABLE `hook_group_messages` ADD `image_refs` text;
\ No newline at end of file
+ALTER TABLE `hook_group_messages` ADD `image_refs` text;--> statement-breakpoint
+DROP TRIGGER `hook_group_message_stats_insert`;--> statement-breakpoint
+DROP TRIGGER `hook_group_message_stats_delete`;--> statement-breakpoint
+DROP TRIGGER `hook_group_message_stats_update`;--> statement-breakpoint
+CREATE TRIGGER `hook_group_message_stats_insert`
+AFTER INSERT ON `hook_group_messages`
+BEGIN
+ INSERT INTO `hook_group_message_stats` (`provider`, `row_count`, `text_bytes`)
+ VALUES (new.`provider`, 1, length(CAST(new.`text` AS BLOB)) + coalesce(length(CAST(new.`image_refs` AS BLOB)), 0))
+ ON CONFLICT(`provider`) DO UPDATE SET
+ `row_count` = `row_count` + 1,
+ `text_bytes` = `text_bytes` + excluded.`text_bytes`;
+END;--> statement-breakpoint
+CREATE TRIGGER `hook_group_message_stats_delete`
+AFTER DELETE ON `hook_group_messages`
+BEGIN
+ UPDATE `hook_group_message_stats`
+ SET `row_count` = `row_count` - 1,
+ `text_bytes` = max(0, `text_bytes` - length(CAST(old.`text` AS BLOB)) - coalesce(length(CAST(old.`image_refs` AS BLOB)), 0))
+ WHERE `provider` = old.`provider`;
+ DELETE FROM `hook_group_message_stats`
+ WHERE `provider` = old.`provider` AND `row_count` <= 0;
+END;--> statement-breakpoint
+CREATE TRIGGER `hook_group_message_stats_update`
+AFTER UPDATE ON `hook_group_messages`
+BEGIN
+ UPDATE `hook_group_message_stats`
+ SET `row_count` = `row_count` - 1,
+ `text_bytes` = max(0, `text_bytes` - length(CAST(old.`text` AS BLOB)) - coalesce(length(CAST(old.`image_refs` AS BLOB)), 0))
+ WHERE `provider` = old.`provider`;
+ DELETE FROM `hook_group_message_stats`
+ WHERE `provider` = old.`provider` AND `row_count` <= 0;
+ INSERT INTO `hook_group_message_stats` (`provider`, `row_count`, `text_bytes`)
+ VALUES (new.`provider`, 1, length(CAST(new.`text` AS BLOB)) + coalesce(length(CAST(new.`image_refs` AS BLOB)), 0))
+ ON CONFLICT(`provider`) DO UPDATE SET
+ `row_count` = `row_count` + 1,
+ `text_bytes` = `text_bytes` + excluded.`text_bytes`;
+END;
diff --git a/apps/desktop/src/main/im/shared/__tests__/groupHistorySearch.test.ts b/apps/desktop/src/main/im/shared/__tests__/groupHistorySearch.test.ts
index 210461fcce..84b1b7117e 100644
--- a/apps/desktop/src/main/im/shared/__tests__/groupHistorySearch.test.ts
+++ b/apps/desktop/src/main/im/shared/__tests__/groupHistorySearch.test.ts
@@ -50,6 +50,7 @@ function installClient(): void {
function installGroupHistoryMigrations(): void {
sqlite.exec(readMigration('0087_'));
sqlite.exec(readMigration('0088_'));
+ sqlite.exec(readMigration('0136_'));
}
function insertRaw(
@@ -96,7 +97,6 @@ beforeEach(() => {
sqlite = new Database(':memory:');
sqlite.exec(readMigration('0083_'));
sqlite.exec(readMigration('0086_'));
- sqlite.exec(readMigration('0136_'));
rawSequence = 0;
holder.queries = [];
installClient();
@@ -236,6 +236,31 @@ describe('group history FTS', () => {
});
describe('group window storage guardrails', () => {
+ // #7756 review: the existing aggregate tests contain text only. Unit: public
+ // writer/stats and real SQLite triggers must charge UTF-8 image metadata on
+ // insert, image/provider update, clearing refs and delete, without cross-lane totals.
+ it('accounts image metadata through insert, update, namespace move and delete', async () => {
+ installGroupHistoryMigrations();
+ const refs = [{ fileId: 'photo', name: '图.png', mimeType: 'image/png', downloadToken: '签'.repeat(100) }];
+ await recordGroupWindowEntry({
+ ...LANE, messageId: 'image-stats', text: '正文', author: { name: 'sender' }, imageRefs: refs, sentAt: 1,
+ });
+ expect(await getGroupWindowNamespaceStats(LANE.provider)).toEqual({
+ rows: 1, textBytes: Buffer.byteLength('正文') + Buffer.byteLength(JSON.stringify(refs)),
+ });
+ const otherProvider = 'telegram:other';
+ const updatedRefs = JSON.stringify([{ ...refs[0], downloadToken: '新'.repeat(150) }]);
+ sqlite.prepare('UPDATE hook_group_messages SET provider = ?, text = ?, image_refs = ? WHERE message_id = ?')
+ .run(otherProvider, '新正文', updatedRefs, 'image-stats');
+ expect(await getGroupWindowNamespaceStats(LANE.provider)).toEqual({ rows: 0, textBytes: 0 });
+ expect(await getGroupWindowNamespaceStats(otherProvider)).toEqual({
+ rows: 1, textBytes: Buffer.byteLength('新正文') + Buffer.byteLength(updatedRefs),
+ });
+ sqlite.prepare('UPDATE hook_group_messages SET image_refs = NULL WHERE message_id = ?').run('image-stats');
+ expect(await getGroupWindowNamespaceStats(otherProvider)).toEqual({ rows: 1, textBytes: Buffer.byteLength('新正文') });
+ sqlite.prepare('DELETE FROM hook_group_messages WHERE message_id = ?').run('image-stats');
+ expect(await getGroupWindowNamespaceStats(otherProvider)).toEqual({ rows: 0, textBytes: 0 });
+ });
it('正文按 UTF-8 约 16KB 硬上限安全截断,统计按命名空间给出行数与字节', async () => {
installGroupHistoryMigrations();
const text = '中'.repeat(6_000);
diff --git a/apps/desktop/src/main/im/shared/__tests__/groupWindowRetentionProxy.test.ts b/apps/desktop/src/main/im/shared/__tests__/groupWindowRetentionProxy.test.ts
index c6c8810376..776957c51d 100644
--- a/apps/desktop/src/main/im/shared/__tests__/groupWindowRetentionProxy.test.ts
+++ b/apps/desktop/src/main/im/shared/__tests__/groupWindowRetentionProxy.test.ts
@@ -69,8 +69,8 @@ function migrationSql(): string {
}
function stats(): { b: number; n: number } {
- const row = h.sqlite!
- .prepare(
+ const row = h
+ .sqlite!.prepare(
'SELECT text_bytes AS b, row_count AS n FROM hook_group_message_stats WHERE provider = ?',
)
.get(PROVIDER) as { b: number; n: number } | undefined;
@@ -92,11 +92,26 @@ afterEach(() => {
});
describe('群历史回收(worker RPC 代理下)', () => {
- it('回收真的执行了 —— 边界查询整条走 query builder, 不是 raw SQL', async () => {
+ // #7756 review: image locators were missing from both quota accounting and
+ // eviction boundaries. Unit: real writer over worker RPC + in-memory SQLite;
+ // the minimal new input is 21 rows with image refs and a 20-row byte budget.
+ it.each([false, true])('回收真的执行了 —— 含图片标识: %s', async (withImages) => {
// 上限 2000 字节, 低水位 1800。第 21 条 100 字节的消息把总量顶到 2100,
// 正好落在触发点上。raw SQL 那版会在这里抛 "should execute through worker RPC"。
- const retention = { maxTextBytesPerNamespace: 2_000, maxRowsPerNamespace: 5_000_000 };
- const body = 'x'.repeat(100);
+ const body = withImages ? '图' : 'x'.repeat(100);
+ const imageRefs = withImages
+ ? [
+ {
+ fileId: 'photo',
+ name: 'image.png',
+ mimeType: 'image/png',
+ downloadToken: '签'.repeat(100),
+ },
+ ]
+ : undefined;
+ const rowBytes =
+ Buffer.byteLength(body) + (imageRefs ? Buffer.byteLength(JSON.stringify(imageRefs)) : 0);
+ const retention = { maxTextBytesPerNamespace: rowBytes * 20, maxRowsPerNamespace: 5_000_000 };
for (let i = 0; i < 21; i += 1) {
await recordGroupWindowEntry(
{
@@ -106,6 +121,7 @@ describe('群历史回收(worker RPC 代理下)', () => {
messageId: `p${i}`,
author: { name: '@u' },
text: body,
+ imageRefs,
sentAt: 1,
},
retention,
@@ -113,16 +129,15 @@ describe('群历史回收(worker RPC 代理下)', () => {
}
const after = stats();
- expect(after.b).toBeLessThanOrEqual(1_800); // 收敛到低水位, 不是压线
- expect(after.b).toBeGreaterThan(1_700); // 也没删过头
+ expect(after).toEqual({ b: rowBytes * 18, n: 18 }); // 低水位,且不删过头
expect(
- h.sqlite!
- .prepare('SELECT 1 FROM hook_group_messages WHERE provider = ? AND message_id = ?')
+ h
+ .sqlite!.prepare('SELECT 1 FROM hook_group_messages WHERE provider = ? AND message_id = ?')
.get(PROVIDER, 'p0'),
).toBeUndefined(); // 删的是最旧的
expect(
- h.sqlite!
- .prepare('SELECT 1 FROM hook_group_messages WHERE provider = ? AND message_id = ?')
+ h
+ .sqlite!.prepare('SELECT 1 FROM hook_group_messages WHERE provider = ? AND message_id = ?')
.get(PROVIDER, 'p20'),
).toBeDefined(); // 最新的还在
});
diff --git a/apps/desktop/src/main/im/shared/groupWindowCore.ts b/apps/desktop/src/main/im/shared/groupWindowCore.ts
index 4882cf6e6e..46a4bbdf5a 100644
--- a/apps/desktop/src/main/im/shared/groupWindowCore.ts
+++ b/apps/desktop/src/main/im/shared/groupWindowCore.ts
@@ -41,14 +41,12 @@ const CURSOR_ROLLBACK_RETRY_DELAY_MS = 25;
* `maxRowsPerNamespace` 只是防止极端行数膨胀的安全阀(海量空消息把行开销撑爆),
* 设得足够高, 正常使用永远碰不到 —— 它不是日常清理手段。
*
- * **字节口径只统计 `text`**, 不含 `file_names` / `chat_name` / `author` / 各类 id
- * 与索引。这不是遗漏: `text_bytes` 由 migration 0088 的触发器维护, 改口径要动
- * schema。纯附件消息的 `text` 正是空串, 这类命名空间的增长由**行数阀**兜 ——
- * 每行的非正文开销约 200~250 字节(含索引), 500 万行即约 1.2 GiB, 与正文额度
- * 同一量级, 上限可估。要精确按整行受控字节计费得改触发器, 另立议题。
+ * 字节口径为 `text` + `image_refs` 的 UTF-8 大小;0136 更新既有统计触发器,
+ * 容量统计与下方回收边界使用同一口径。沿用 `text_bytes` / `textBytes` 名称兼容
+ * 既有调用方。其余 `file_names` / `chat_name` / `author` / id 与索引仍由行数阀兜底。
*/
export type GroupWindowRetentionPolicy = {
- /** 该 provider 命名空间保留的正文字节上限。 */
+ /** 该 provider 命名空间保留的正文与图片标识字节上限。 */
maxTextBytesPerNamespace: number;
/** 安全阀: 行数上限。 */
maxRowsPerNamespace: number;
@@ -278,7 +276,7 @@ async function runNamespaceRetention(
* 重复执行、并发执行、跨进程执行结果都一样, 不需要锁、事务或版本号 CAS,
* 也就不需要动 schema。
*
- * 边界取法: 从**最新往回**累计正文字节与行数, 累计量还在目标以内的那些留下,
+ * 边界取法: 从**最新往回**累计正文与图片标识字节及行数, 累计量还在目标以内的那些留下,
* 比其中最旧那条还旧的全删。`rn = 1` 那一项保证最新一行永远留着 —— 阈值被配得
* 极小(或单条消息就超过阈值)时不能把整个命名空间清空。
*
@@ -296,7 +294,7 @@ async function keepNewestWithinTargets(
.select({
id: hookGroupMessages.id,
cumBytes:
- sql<number>`sum(length(cast(${hookGroupMessages.text} as blob))) over (order by ${hookGroupMessages.id} desc)`.as(
+ sql<number>`sum(length(cast(${hookGroupMessages.text} as blob)) + coalesce(length(cast(${hookGroupMessages.imageRefs} as blob)), 0)) over (order by ${hookGroupMessages.id} desc)`.as(
'cum_bytes',
),
rn: sql<number>`row_number() over (order by ${hookGroupMessages.id} desc)`.as('rn'),
diff --git a/apps/desktop/src/main/localDb/__tests__/migrationReplay.test.ts b/apps/desktop/src/main/localDb/__tests__/migrationReplay.test.ts
index 626a81821b..ef70e2fd74 100644
--- a/apps/desktop/src/main/localDb/__tests__/migrationReplay.test.ts
+++ b/apps/desktop/src/main/localDb/__tests__/migrationReplay.test.ts
@@ -115,6 +115,7 @@ describeMigrationReplay('migration replay', () => {
db.exec("INSERT INTO sessions (id) VALUES ('legacy-session')");
// These reduced historical fixtures still need the group table present since schema 83.
db.exec(readFileSync(path.join(drizzleDir(), '0083_gray_katie_power.sql'), 'utf-8'));
+ db.exec(readFileSync(path.join(drizzleDir(), '0088_thankful_captain_midlands.sql'), 'utf-8'));
const result = runMigrationReplay(db, { drizzleDir: drizzleDir(), currentVersion: 124 });
expect(result.applied.map((migration) => migration.seq)).toEqual([
125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
@@ -150,6 +151,7 @@ describeMigrationReplay('migration replay', () => {
.run('legacy-tool', 'subject', 0, 100, 'run');
// These reduced historical fixtures still need the group table present since schema 83.
db.exec(readFileSync(path.join(drizzleDir(), '0083_gray_katie_power.sql'), 'utf-8'));
+ db.exec(readFileSync(path.join(drizzleDir(), '0088_thankful_captain_midlands.sql'), 'utf-8'));
runMigrationReplay(db, { drizzleDir: drizzleDir(), currentVersion: 131 });
expect(db.prepare('SELECT call_id,subject_id,occurred_at,entry_kind FROM plugin_usage_events').all()).toEqual([
{ call_id: 'legacy-tool', subject_id: 'subject', occurred_at: 100, entry_kind: 'tool' },
@@ -208,6 +210,7 @@ describeMigrationReplay('migration replay', () => {
db.exec("CREATE TABLE bot_delegations (id TEXT PRIMARY KEY)");
// These reduced historical fixtures still need the group table present since schema 83.
db.exec(readFileSync(path.join(drizzleDir(), '0083_gray_katie_power.sql'), 'utf-8'));
+ db.exec(readFileSync(path.join(drizzleDir(), '0088_thankful_captain_midlands.sql'), 'utf-8'));
const result = runMigrationReplay(db, { drizzleDir: drizzleDir(), currentVersion: 125 });
expect(result.applied.map((migration) => migration.seq)[0]).toBe(126);
expect(columnNames(db, 'sessions')).toContain('hidden_at');
@@ -227,6 +230,7 @@ describeMigrationReplay('migration replay', () => {
db.exec("CREATE TABLE plugin_usage_events (call_id TEXT PRIMARY KEY)");
// These reduced historical fixtures still need the group table present since schema 83.
db.exec(readFileSync(path.join(drizzleDir(), '0083_gray_katie_power.sql'), 'utf-8'));
+ db.exec(readFileSync(path.join(drizzleDir(), '0088_thankful_captain_midlands.sql'), 'utf-8'));
const result = runMigrationReplay(db, { drizzleDir: drizzleDir(), currentVersion: 129 });
expect(result.applied.map((migration) => migration.seq)).toEqual([
130, 131, 132, 133, 134, 135, 136,
diff --git a/apps/desktop/src/main/localDb/schema.ts b/apps/desktop/src/main/localDb/schema.ts
index ed5a52aade..d29c8f46e8 100644
--- a/apps/desktop/src/main/localDb/schema.ts
+++ b/apps/desktop/src/main/localDb/schema.ts
@@ -2367,6 +2367,7 @@ export const hookGroupMessages = sqliteTable(
export const hookGroupMessageStats = sqliteTable('hook_group_message_stats', {
provider: text('provider').primaryKey(),
rowCount: integer('row_count').notNull(),
+ /** UTF-8 bytes of text + image_refs; retain the existing column/API name. */
textBytes: integer('text_bytes').notNull(),
});
diff --git a/docs/product-rules/telegram-bot-parity.md b/docs/product-rules/telegram-bot-parity.md
index 8cadbb57a1..54f64af49f 100644
--- a/docs/product-rules/telegram-bot-parity.md
+++ b/docs/product-rules/telegram-bot-parity.md
@@ -120,7 +120,7 @@ App 完成未读与提醒统一由 `renderer/hooks/useSessionRunningStatus.ts`
| 交互卡的**语义层**(`ask_user_question` / `plan_review` / 权限确认) | `im/shared/interactionCardModel.ts` | 选项集与决策模型两侧真跑同一份:至多 6 个选项(`MAX_OPTIONS`)、multiSelect 降级单选、只渲染第一问、plan 正文截断 1500(`MAX_PLAN_LEN`)、按钮文案的**产品级**上限 30(`BTN_LABEL_MAX`)、无选项降级时唯一按钮「继续」,以及 buttonId → 决策对象的构造与 header/body 拆分。**2026-08-19 起该模块另有一份全量视图**(顶层 `questions` 数组 + `needsAskMultiCard` 判定),只被支持卡片原地更新(`updateInteractiveCard`)的个人 IM 渠道消费——目前**仅飞书个人 bot**(`ui.cards.ask.multi` 打勾卡,多题/真多选,见 `cardBuilders.buildAskMultiCard`);**本表对照的两个 Telegram bot 都不消费它**,上列 v1 规则对两侧与未提供 multi 文案的渠道仍逐字成立,看到飞书行为不同不要当漂移报官方那条链路由 `hook-control/interactions.ts` 直接 import 本模块(对 `@cindy/maker-core` 刻意只做 type-only 依赖,免得 hook 链路在运行期加载整个 barrel)。**渲染不在这里**——按钮文案来源、标题格式、省略号样式、尺寸上限都是各自渲染侧的事,见第三节 |
| **计划对账注入**(plan reconcile) | `maker-ipc/planReconcile.ts`(`summarizeOpenPlan` + `buildPlanReconcileNote`) | 两侧在真实用户轮次发送前查询未收口计划并前置对账说明。官方侧:`hook-control/session-runner.ts`(仅 `req.source?.im` 存在时注入,自动派发不注入);个人侧:`im/shared/turnRunner.ts`。两侧共用同一份查询与文案构造,差异仅在"什么算普通用户轮次"的判定各走各的来源分类 |
| Pi 管理命令的**共享 Host 服务与回执**(入口有意不同) | `packages/maker-core/src/agents/pi/index.ts` 的 `routeManagedPackageCommand` / `piManagedPackageVisibleReceipt`,授权落点为 `maker-host/pi-managed-package-mutation.ts` | 三种来源的授权语义必须分开:个人 bot 由 `im/shared/turnRunner.ts` 把 adapter 的 `item.text` 作为 authenticated IM 原文交给 `routeManagedPackageCommand`,共享渠道策略识别 `cindy_pi_command` / `cindy_pi_extension` 的原生 argv、旧 action/source 及包装调用:安装/更新/移除要求确认,明确只读的 list/version/help 不增加强确认(不作永久拒绝)。精确命令先检查本轮渠道 `forceConfirmToolCall`:要求强确认或检查异常时回到既有工具确认路径,不凭 IM 来源绕过主人批准;无强确认时使用 `authenticated-im-command` 直接执行,包括 `install/remove/uninstall`、单包 `update`、`update` / `--self` / `--all` / `--extensions`,以及 `list`、`--version`、`--help` 等已适配查询(完整语法见 `docs/dev-rules/pi-managed-commands.md`);官方 bot 由 `hook-control/session-runner.ts` 优先保留服务端 `source.userText`(旧服务端才回退已装饰 prompt),但其 Main-owned origin 明确是 `hook`,**不得**伪装成 `local-desktop-command`,上述管理命令及查询均不直执行,而是交给模型,调用 `cindy_pi_command`(兼容别名 `cindy_pi_extension`)时走既有统一工具授权路径(`confirmed-tool-call`)。Full Access 沿通用免询问规则,Ask/Auto 与渠道强制确认沿原策略;工具获准后不追加 Pi 专属审批。自然语言请求同样走工具路径,不等同精确用户命令授权。Main-owned Desktop direct 是独立于两个 Telegram bot 的可信本机入口,只有它使用 `local-desktop-command` 直接执行。三条路径最终复用同一 Host 服务;包操作共用相对路径解析与受管 store,内核/批量更新及查询执行类型化原生命令,均输出有界回执。内核及批量命令不走单包退休回调,内核更新保留活跃任务、新启动的根 Pi 任务采用更新后的路径;已有任务的子代理仍继承根任务启动时的二进制路径;下述单包收敛语义不延伸到内核/批量更新。Pi 原生命令结果是 mutation 真源;安装只有在最终包已启用时才报成功,更新保留此前明确启用/停用状态,设置页启停写入同一个 store,移除以原生命令成功为准;失败回执只携带稳定、脱敏、可恢复的分类,不暴露宿主路径或原始命令输出。安装/更新/启停/移除提交后,已发布及正在启动、且 metadata 满足 `!remoteHostId && !reviewMode` 的**本机普通 Pi runtime**都会收敛;这包含由 device-link/mobile 控制端在被控 Desktop 上启动的本机任务。带 `remoteHostId` 的 remote/SSH runtime、Review runtime 与非 Pi runtime 不受影响。Maker 中仅登记而尚未开始关闭的内部包退役,可由显式切换/关闭接管原因;实际关闭开始后原因固定。个人 bot 的 `turnRunner` 继续用准确实例及 `agent-switch` 原因保护待发队列,不放宽用户关闭的清理行为。兼容分析只作设置详情内的非阻断提示,不能改判 Pi 原生成功。延迟退役在成功终态后失败时,恢复回执按原实例及发起 generation 独立投递:个人 bot 用既有文本发送接口;官方 Telegram 在双方已协商 `msg-op-v1` 时向原 externalKey 发独立 `send`,只将 `msg.op.result` 成功视为送达,不重发原 turn.end、不派发新 prompt。换账号/目录撤权/实例替换后不向新归属投递;官方通知回执等待最多 10 秒,不自动重试未知结果。旧 hook、官方 Slack/X 尚无本路径支持的独立出站能力,及断线/拒收/超时的渠道通知仍未保证送达,Desktop 恢复回执继续保留;不把此限制写成全渠道已修。消息最终落在 Telegram 的载体形态继续遵守第二节既有生命周期差异 |
-| 群消息本地库的**保留策略** | `im/shared/groupWindowCore.ts` | 上限数值(每命名空间 1 GiB 正文 + 500 万行安全阀)、回收低水位(0.9)与回收实现都在这一处;两侧把同一份 `DEFAULT_GROUP_WINDOW_RETENTION` 传进同一个 `recordGroupWindowEntry`。**额度靠 provider 命名空间隔离**:官方 `telegram:<principalId>`、个人 `telegram-personal:<botId>`,统计与回收都按 provider 过滤,两个账号各算各的、消息不串。一个边界要记住:两侧各持有一份 `{ ...DEFAULT }` **可变副本**(为的是测试能用小阈值把回收逼出来),所以共享的是"模块初始化时的那组数字",运行期改一侧不会传导到另一侧 |
+| 群消息本地库的**保留策略** | `im/shared/groupWindowCore.ts` | 上限数值(每命名空间 1 GiB 正文与图片标识字节 + 500 万行安全阀)、回收低水位(0.9)与回收实现都在这一处;两侧把同一份 `DEFAULT_GROUP_WINDOW_RETENTION` 传进同一个 `recordGroupWindowEntry`。**额度靠 provider 命名空间隔离**:官方 `telegram:<principalId>`、个人 `telegram-personal:<botId>`,统计与回收都按 provider 过滤,两个账号各算各的、消息不串。一个边界要记住:两侧各持有一份 `{ ...DEFAULT }` **可变副本**(为的是测试能用小阈值把回收逼出来),所以共享的是"模块初始化时的那组数字",运行期改一侧不会传导到另一侧 |
| **上游过载 / 限流自动重试进度** | `im/shared/turnRetryNotice.ts`(`turnRetryNotice`) | 非终止 error 翻成渠道进度的**文案与判定**两侧真跑这一份:只认过载(`(auto-retry N/M)` + `upstream-overload` / 529)、终态 429 外层重投、以及 Auto 档审阅器不可用。Pi / Claude / Codex 过载重试都走「模型服务繁忙,正在自动重试(N/M)」;其它非终止 error(普通 5xx、未分类供应商抖动)保持静默。个人侧 `turnRunner`、官方侧 `turnPresenter` 都读这一份。**载体怎么发**不在这里——个人是过程消息原地编辑;官方私聊默认普通进度消息,开启 `TELEGRAM_DM_DRAFT_ENABLED` 时使用草稿,见第三节 |
| **工具循环与输出上限终态的渠道文案** | `im/shared/turnRetryNotice.ts`(`terminalErrorText`) | `reason=tool_use_loop_detected` 的终态事件统一按受限 `toolLoop` 生成渠道可读说明;`reason=output-limit` 共用「回复可能不完整,可发送下一条消息继续」提示;个人侧 `turnRunner` 与官方侧 `hook-control/turnObserver` 都复用这份映射,原始 `loopHint` / `missing_required_field` 等内部分类只留在本地错误上下文,不外发。 |
| **Auto 审阅的引用证据**(用户本条回复/引用的消息与附件数) | 投影与上限:`packages/maker-shared/src/autoReviewIntent.ts` 的 `projectAutoReviewUserReferences`;两侧映射:`im/shared/autoReviewReferences.ts` | 两侧都把宿主盖章的引用事实放进 `MAIN_OWNED_SEND_CONTEXT.autoReviewReferences`,由 maker-core 挂到当前消息的审阅意图上,审阅器以独立低信任块呈现,不算用户原话、不构成授权。**数据来源各不相同**:个人只取 adapter 的 `prepareAgentTurnText` 实际交给模型的回复投影(`replyContext`;飞书被注入扫描拦下时就是占位,模型没看到的回复审阅器也看不到),附件数取本条附件(`im/shared/turnRunner.ts`,纯图引用为「[图片]」占位);官方由 `hook-control/dispatcher.ts` 在展示截短(只留最早 20 条)之前从服务端原始 `source.threadContext` 取回复目标(触发消息带 `replyToMessageId` 时按它找父消息、找不到不猜,否则取排除当前请求后的最后一条),连同实际送达附件数交给 `hook-control/session-runner.ts`。配套服务端修复后,无可读正文也下发原消息 ID 与缺失占位;附件仍不区分自带与引用,数量只反映本条实际提供的附件(生产是否部署需单独核验) |
@@ -489,6 +489,7 @@ bot 身份按入站使用的稳定 ID 校验;Discord 取 gateway application i
`cindy-media` 可回收缓存;授权结束、账号切换、个人连接或官方绑定失效时丢弃在途结果。
受保护消息不留标识。仅支持 JPEG/PNG/GIF/WebP,每图至多 20 MB、每条至多 4 张。
旧记录没有标识时明确返回不可取回;本地群历史的既有保留策略仍生效。
+图片标识的 UTF-8 字节与正文一起计入既有命名空间容量,统计与最旧记录回收采用同一口径。
原图留在受管缓存,给模型的副本复用既有压缩器,整次结果共用 140 KB 内联预算;
无法压入预算的图片计入未返回数量,不回退内联超大原图。缓存读取期间文件被回收时按未命中
重新取件;混合消息的图片索引同时保留非图片附件名称,避免早期入窗覆盖其历史可检索性。