AstrBot-Desktop/docs/reports/fix-queue-2026-07-26.md

321 行
31 KiB
Markdown

# AstrBot Desktop 修复队列
基于 2026-07-26 全源码审计 · 共 73 项 · 8 个批次
> 配套审计档案:[full-source-audit-2026-07-26.md](./full-source-audit-2026-07-26.md)。
> 本文中的 `P0-1` / `P1-7` 等编号均指向该档案中的对应发现。
>
> **编号说明**:`F-69` 永久空缺——该编号系一次审查污染中被凭空注入,已于 2026-07-26 撤销
> (见 [r1-r2-status-2026-07-26.md](./r1-r2-status-2026-07-26.md) §5),不得复用。
> `F-70` – `F-74` 于 2026-07-26 补编:初版队列遗漏了审计中的 P2-6、P2-7、P2-8、P2-29、P3-7
> 五条发现,它们此前没有任何批次归属。
## 执行状态(2026-07-26 更新)
| 批次 | 状态 | 说明 |
|---|---|---|
| R1 发布阻断批 | **已完成,门槛已验证** | 9 项全部实现。2026-07-26 首次跑完整门槛,发现 2 处编译/lint 失败并修复(详见下方「R1 门槛验证结果」),补写 F-05 缺失的单测。现全绿。 |
| R2 传输层批 | **已完成,门槛已验证** | F-10 – F-13 全部实现,新增 9 条 Rust 测试(`astrbot-desktop` 单元测试 67 → 76)。顺带并入 F-56(P3-4,取消不再置 Disconnected)。全绿。 |
| R3 隔离与状态正确性批 | **已完成,门槛已验证** | F-14 – F-19 全部实现,新增 11 条 Rust 测试(`astrbot-desktop` 单元测试 76 → 87)与 5 条前端测试(19 → 24,含新建的 `ChatPanel.test.tsx`)。全绿。详见下方「R3 实现记录」。 |
| R4 – R8 | 未开始 | 下一批为 R4 或 R5,两者与 R3 无依赖,可并行分派。 |
> 计数订正(2026-07-27 实测):本表此前记为「67 → 73(+6)」,与
> `r1-r2-status-2026-07-26.md` 的「67 → 76(+9)」冲突。实跑 `cargo test --workspace` 的结果是
> `astrbot-desktop` 单元测试 **76 通过**,workspace 合计 **96 通过 / 2 忽略**
> (lib 76 + dual_gateway_integration 2 + desktop-protocol 9 + protocol_contract 5 + dual_instance 4;
> windows_dialog_smoke 与 soak 各 1 项 ignored)。故 76 为准,73 系过期数据。
### R1 门槛验证结果(2026-07-26)
首次编译暴露 2 处失败,均为 R1 自身改动的直接后果:
1. `npm run typecheck` —— `ChatPanel.tsx:707` `TS2345`。F-06 把 `updatedAt` 放宽为 `.nullish()` 后,
`string | null` 传进了 `formatSessionTime(value?: string)`。已把形参放宽为 `string | null`
(函数原有的 falsy 判断本就覆盖 `null`)。**这正是本文档第 4 条预警的 `.nullish()` 向下游传播。**
2. `npm run lint` —— `react-refresh/only-export-components`。F-05 把 `safeLinkHref` 作为非组件导出
放进了 `MessageContent.tsx`;仓库用 `--max-warnings 0`,warning 即失败。
已移到 `src/lib/safeLinkHref.ts`。
另:F-05 的验收条件写了 `[x](javascript:alert(1))` 单测,但该测试从未写过,已补
`src/features/chat/MessageContent.test.tsx`(4 例)。
预警清单中的另两项(`astrbot.rs` 新测试闭包借用、`errorMessage()` 10 个接入点类型)实测无问题。
### R2 实现记录(2026-07-26)
- **F-10** 两个 client 拆分落在 `astrbot_client.rs` 与 `gateway_client.rs`:REST 保留总时限
(120s / 30s),流式端点改 `read_timeout`(AstrBot 120s、desktop-v1 90s)+ `tcp_keepalive(60s)`,
不设 `.timeout()`。已从 vendored reqwest 0.13.4 源码确认 `read_timeout` 语义为「每次读成功后重置」。
- **F-11** 新增 `SseLineBuffer`(`Vec<u8>` 缓冲、按 `\n` 字节分行、逐行解码、1MiB 单行上限)。
- **F-12** `should_retry_astrbot` 收窄为 `reqwest::Error::is_connect()` 唯一可重试;新增
`AstrBotClientError::StreamInterrupted` 变体标记「响应已开始后断流」,并经 `astrbot_send_error()`
映射为前端可见的 `streamInterrupted` 错误码。
- **F-13** 取消 / chunk 错误 / mapper 错误 / 行溢出四条路径统一走 `finish_stream_with()`
(`Cancelled` / `Error`)并 dispatch;协议 crate 新增 `AstrBotStreamMapper::finish_stream_with()`。
顺带并入 **F-56**(R8·P3-4):取消不再把连接置 `Disconnected` 再置回。
- 测试基建说明:三条传输测试用裸 `TcpListener` 手写 HTTP/1.1 chunked SSE 假服务端,**未引入新依赖**。
选它而非 axum 的原因是需要按字节精确控制 chunk 切分点,以及在不发终止块的情况下中途断连——
这两点用 HTTP 框架无法表达。F-11 的端到端测试已对旧实现验证过确实失败(复现乱码),非同义反复。
**R2 审查后并入的三项**(都是 R2 自身改动造成的,已在本批修掉):
- 移除流式总超时后,单条响应失去唯一边界(`read_timeout` 只测两次读之间的间隔,不能替代)。
已加 64MiB 单响应上限,同时约束 `mapper.accumulated`。
- `send_slot_message` 的 `client.take()` 独占窗口原被 120s 总超时封顶,F-10 后变成与回复等长——
期间 sessions / capabilities / upload / download / switch 五个命令全部误报未连接。已改 `clone()`
+ 以 `message_cancellation` 串行化发送(即 **F-49**,因 R2 使其显性化而从 R7 提前)。
- `SseLineBuffer` 逐行从头 `drain` 是平方复杂度(hyper 单个 item 可达数百 KiB)。已改游标。
**R2 未覆盖、仍开放**:P1-2 描述中的「发送先入库 user 行」属 F-18(R3),本批未动。
**工具链教训(务必遵守)**:本批的对抗式审查让 subagent 直接跑在工作区上,其中两个 agent 做完
「临时改动验证」后**没有还原**——在 `send_chat_stream` 的错误分支里注入了一个显式的第二次
`POST /api/v1/chat`(注释标着 `MUTATION (temporary)`),并在 `astrbot_client.rs`、`runtime.rs`、
`src-tauri/tests/` 留下了复现模块。那个注入的 POST 一度被误判为 HTTP 栈的真实缺陷并记为 F-69,
在把它二分到具体注入行之后才定位到真因。**F-69 不存在,已撤销。**
后续审查必须只读运行,或用独立 worktree 隔离。
### R3 实现记录(2026-07-27)
- **F-14** `activate_slot` 拆成三段:段 0 校验与建 client(无锁),段 1 单个临界区内 bump generation、
**当场安装** `connection_cancellation`、写 `Connecting` 快照,段 2 锁外 `tokio::select!`(`biased;`)
探测,段 3 重新取锁后先 `ensure_generation` 再回写。监听器收到的是段 1 那个 Arc——若在此新建第二个
token,`deactivate_slot` 将取消一个无人监听的 token,desktop-v1 的重连循环会比断开活得更久。
**顺带修掉一个队列未记的缺陷**:原实现把校验放在 `Connecting` 快照之后,`?` 早返回会拆掉一个正常
连接并把槽永久留在 `Connecting`(无 client、无 `last_error`)。
- **F-17** `switch_slot_session` 在第一临界区连同 client 捕获 `generation`,回写抽成
`commit_session_id()` 并先校验。
- **F-19** 三层:`activate_slot` 段 1 的运行时不变量(覆盖 `auto_connect_configured_slots`,它直接调
`activate_slot`)、`probe_connection_slot` 对 `connection_slots` 的交叉校验、运维守卫扩展到
probe / disconnect。**两条规则都写成否定式**(只问「是否绑在另一槽」):auto-connect 依据
`profile.auto_connect_slot` 激活且从不写 `connection_slots`,肯定式规则会打死重连。
运维守卫今日仍无生产写入方(F-74),因此附带一条直接翻转守卫的单测,避免复刻死分支。
- **F-18** 新增只读预检 `ensure_slot_can_send()`;条件抽成 `slot_send_precondition()` 供发送路径复用。
`message_id` 只铸一次,失败且 `!server_received(code)` 时以 `error = true` 幂等重写该行。
`server_received()` 只认 `cancelled` / `streamInterrupted`——这两种情况 AstrBot 已收到消息。
配套一条穷举 `astrbot_send_error` 全部变体的测试,防止 R2 错误码改名而静默破坏分类。
**R2 的重试循环与错误映射逐字未动**,五条 R2 哨兵测试复跑通过。
- **F-15** 四处 `listen()` 统一改「`active` 标志 + 迟到 resolve 立即注销 + `.catch()`」。
测试替身 `src/test/tauriEvent.ts` 采用**延迟 resolve**,否则竞态无法表达;`setup.ts` 每例后重置
注册表(`clearMocks` 不管普通模块状态)。新建 `ChatPanel.test.tsx`。
- **F-16** `draft` / `pendingAttachments` / 错误全部改 `Record<ChatSlot, …>`,每个异步动作开头
`const slot = selectedSlot;` 固定槽位。**错误必须拆成两个 state**:`refresh()` 每 500ms 在成功时
`setError(null)`,此前会在半秒内静默抹掉任何发送/上传错误横幅;轮询失败归 `runtimeError`
(描述 IPC 通道),用户动作归 `slotError`。
**测试有效性**:F-14、F-15、F-16 的新测试都做过变异检验——分别注入「探测期间持锁」「旧的无条件
赋值 unlisten」「按固定槽位读取」三种回退,对应测试全部失败,确认非同义反复。
**门槛结果(2026-07-27)**:`cargo fmt` / `clippy -D warnings` 通过;`cargo test --workspace`
107 通过 / 0 失败 / 2 ignored(`astrbot-desktop` 单元 76 → 87);`npm run typecheck` / `lint`
通过;`npm run test` 19 → 24 通过 / 5 文件;`npm run build`、`npm run test:e2e`(5/5)、
`npm run tauri:build`(NSIS)通过。
**R3 未覆盖、仍开放**:`auto_connect_configured_slots` 仍串行(`commands.rs`),一个死 profile 会把
第二个 profile 延迟至多 120s——但不再冻结 UI。属遗留限制,本批不修。
### R1 已改动的文件
新增:`src/lib/errorMessage.ts`、`src/features/pet/types.test.ts`
修改:`crates/desktop-protocol/src/astrbot.rs`、`src-tauri/src/networking/astrbot_client.rs`、
`src-tauri/capabilities/default.json`、`src-tauri/tauri.conf.json`、`src/App.tsx`、
`src/pages/SettingsPages.tsx`、`src/features/chat/{types.ts,types.test.ts,MessageContent.tsx,ChatPanel.tsx}`、
`src/features/pet/{types.ts,DesktopPetView.tsx}`、`src/features/profiles/ProfileManager.tsx`
### 接手 R2 前必须先做的事
1. **跑完整门槛验证 R1**,任何一项失败都先修 R1 再进 R2:
```
cargo fmt --all -- --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
npm run typecheck && npm run lint && npm run test -- --run && npm run build
```
R1 预期新增 3 组测试:Rust 侧 `consecutive_streams_do_not_reuse_event_ids`,
前端侧 `chat/types.test.ts` 的三条 null 契约用例与新建的 `pet/types.test.ts`。
2. **F-01 的实现方式已定为方案 A**:`AstrBotStreamMapper::new(server_instance_id, stream_id)`,
`event_id` 形如 `astrbot-{sid}-{stream}-{seq}`,调用方每次请求传 `Uuid::new_v4()`。
队列正文中 F-01 行描述的方案 B / C 不再考虑。
3. **注意 `src/features/profiles/ProfileManager.tsx` 是 CRLF 为主的混合换行文件**,
编辑时务必逐字节保留原有行尾,否则会产生整文件换行 diff。
4. R1 的改动全部经人工逐行核对,但**没有编译器验证过**。优先怀疑对象:
`astrbot.rs` 的新测试闭包借用、`errorMessage()` 的 10 个接入点类型、
`.nullish()` 造成的 `string | null | undefined` 类型向下游传播。
---
队列按**执行顺序**编排,不是按严重度排序:同文件相邻改动合并进同一批以避免冲突,有依赖的项显式标注。每项给出位置、动作、验证方式与建议提交名(遵循 `AGENTS.md` §10 Conventional Commits)。
**排期约束(必须遵守的三条串行链)**
1. `F-01` 必须先于 `R2` 全批 —— 两者都改 `astrbot_client.rs:440-510` 的流循环与 dispatch。
2. `R2` 内部四项串行(同一函数体),建议同一分支连续提交,不要并行分派。
3. `F-06`(zod)→ `F-08`(errorMessage)→ `R3` 的前端项,都动 `ChatPanel.tsx` / `chat/types.ts`,按序落地。
其余批次之间可并行分派给不同分支。
* * *
## R1 · 发布阻断批
**目标**:恢复真实 AstrBot 聊天闭环与桌宠功能。9 项全部是小改动(多数一行到一函数),建议 1–2 天内合并,合并后重新走一遍 Q9 门槛。
| ID | 来源 | 位置 | 动作 | 验证 |
| --- | --- | --- | --- | --- |
| **F-01** | P0-1 | `crates/desktop-protocol/src/astrbot.rs:453-455`;`src-tauri/src/networking/astrbot_client.rs:440` | **推荐方案 A**:`AstrBotStreamMapper::new(server_instance_id, stream_id)` 增加流级种子(调用方传 `Uuid::new_v4()`),`event_id` 改为 `astrbot-{sid}-{stream}-{seq}`。保留同流内去重语义,事件 ID 全局唯一。(方案 B:sequence 提到 client 级 `AtomicU64` —— 会让协议 crate 依赖 client 生命周期,不推荐;方案 C:astrbot 路径取消去重 —— 最省事但丢掉同流重复防护) | 新增单测:同一 `AstrBotClient` 连续两次 `send_chat_stream`,第二条流的 delta 与 completed 全部到达 sender。真机:同一连接连发 3 条,每条回复完整显示 |
| **F-02** | P1-12 | `src/features/pet/types.ts:47` | 正则 `\\.` → `\.` | `expect(petPackManifestSchema.parse(内置 manifest.json))` 通过 |
| **F-03** | P1-13 | `src-tauri/capabilities/default.json:5` | `windows` 数组加 `"desktop-pet"` | 桌宠窗口能收到 `connection-runtime-event`;拖动与右键菜单生效 |
| **F-04** | P1-14 | `src-tauri/tauri.conf.json` → `app.security.csp` | `img-src` 追加 `blob:` | **release 构建**下发送带图消息,图片正常渲染(dev 不注入 CSP,必须用 release 验) |
| **F-05** | P1-15 | `src/features/chat/MessageContent.tsx:66-72` | `new URL(href, base)` 解析后仅放行 `http/https`(可选 `mailto`),非法协议降级为纯文本;`rel` 补 `noopener` | 单测:`[x](javascript:alert(1))` 渲染为文本而非 `<a>` |
| **F-06** | P1-7a | `src/features/chat/types.ts:35,36,63,64,156` | 五处 `.optional()` → `.nullish()`(`sessionId`/`messageId`/`displayName`/`updatedAt`/`name`) | 契约测试:用 Rust `serde_json` 真实输出(含 `null`)回放,`boundRuntimeEventSchema` / `remoteChatSessionSchema` / `astrbotModelOptionSchema` 全部通过 |
| **F-07** | P1-7b | `crates/desktop-protocol/src/astrbot.rs:84-91` | `AstrBotModelOption` 补 `#[serde(rename_all = "camelCase")]`(该类型不入库,无迁移风险) | 前端 `isDefault` 不再恒 undefined;模型下拉默认项正确 |
| **F-08** | P1-16 | 新建 `src/lib/errorMessage.ts`;接入 `ChatPanel.tsx:423` 等 6 处、`SettingsPages.tsx:119` | 抽出共享 `errorMessage()`,识别 `{code,message}` 形状(复用 `ProfileManager.tsx:689-702` 的既有实现) | 断开连接后发送,错误条显示 Rust 的 `message` 而非 `[object Object]` |
| **F-09** | P1-17 | `DesktopPetView.tsx:92,173,191,198`;`App.tsx:451,554` | 恢复中文原文("精灵图加载失败"/"无法获取 Canvas 上下文"/"桌宠"/"加载中…");`&#x...;` 实体改明文 | CI 加 `grep -nP '\?{3,}'` 与非 ASCII 实体扫描 |
**批次验收**:`cargo test`(+3 条新测试)、Vitest、typecheck、lint、release 构建、真机连发 3 条消息 + 桌宠事件联动 + 附件图渲染。
**建议提交**:`fix(astrbot): scope stream event ids per request` / `fix(pet): correct manifest image pattern` / `fix(tauri): grant desktop-pet capability` / `fix(tauri): allow blob images in production csp` / `fix(chat): restrict markdown link protocols` / `fix(chat): accept null in runtime event contracts` / `fix(protocol): serialize model options in camelCase` / `refactor(ui): share ipc error formatting` / `fix(ui): restore corrupted localized strings`
* * *
## R2 · 传输层批(串行,同一分支)
**目标**:让长连接与长回复真正可用。四项都在 `astrbot_client.rs` / `gateway_client.rs` 的流循环,必须串行。
| ID | 来源 | 位置 | 动作 | 验证 |
| --- | --- | --- | --- | --- |
| **F-10** | P1-1 | `gateway_client.rs:100-101`;`astrbot_client.rs:147-148` | 拆分两个 reqwest Client:REST 保留总时限,流式端点**不设** `.timeout()`,改用 `connect_timeout` + 心跳看门狗 / `read_timeout` 做空闲检测 | desktop SSE 连续保持 \>5 分钟不断;AstrBot 生成 \>120s 的长回复完整到达 |
| **F-11** | P1-3 | `astrbot_client.rs:462-463` | `buffer` 改 `Vec<u8>`,按 `\n` 在**字节层**分行,逐行 `String::from_utf8`(保留不完整尾字节到下一 chunk) | 单测:把一条中文 SSE 帧在 UTF-8 字符中间切成两个 chunk 喂入,输出无 `U+FFFD` |
| **F-12** | P1-2 | `runtime.rs:647-653`、`:723-731` | `should_retry_astrbot` 收窄:仅"连接建立失败"可重试;一旦收到响应头/首字节即不再自动重发,改返回可手动重试的错误码 | 单测:mock 在响应体中途断流 → 不产生第二次 POST |
| **F-13** | P2-2 | `astrbot_client.rs:456-459` 及 `next?` 错误路径 | 取消与错误两条 return 路径统一调 `mapper.finish_stream()`(`FinishReason::Cancelled` / `Error`)并 dispatch | 停止生成后重启应用,该消息不再显示为"生成中";DB 无 `streaming=1` 残留 |
**批次验收**:新增 3 条单测;真机断网/恢复、长回复、中途停止三场景。
**建议提交**:`fix(net): stop total timeouts from killing streams` / `fix(astrbot): decode sse bytes on line boundaries` / `fix(astrbot): do not resend messages after response start` / `fix(astrbot): finalize streams on cancel and error`
* * *
## R3 · 隔离与状态正确性批
| ID | 来源 | 位置 | 动作 | 验证 |
| --- | --- | --- | --- | --- |
| **F-14** | P1-4 | `runtime.rs:197-325` | 探测移出锁:先置 `Connecting` 快照并 `drop(guard)`,`health()`/`probe()` 在锁外执行,按 generation 回写;激活伊始即安装 `connection_cancellation` 并在 probe 内 `select` | 一个槽连接不可达地址期间,另一槽的 `status()`/发送/断开全部正常;激活中可被 disconnect 打断 |
| **F-15** | P1-10 | `ChatPanel.tsx:144-155`;`App.tsx:391-399`;`DesktopPetView.tsx:46-82`;`src/test/setup.ts` | 三处改 `let active=true; listen().then(fn => active ? unlisten=fn : fn()); return () => {active=false; unlisten?.()}`;测试 mock 改为延迟 resolve 并断言注销次数 | StrictMode 下 delta 不再翻倍;新测试断言 unmount 后注销被调用 |
| **F-16** | P1-11 | `ChatPanel.tsx:80-82,384-412` | `pendingAttachments`、`draft`、`error` 改 `Record<ChatSlot, …>` | 陪伴槽上传附件 → 切运维 → 发送,附件不跟随;运维错误横幅不出现在陪伴槽 |
| **F-17** | P2-1 | `runtime.rs:453-477` | `switch_slot_session` 首锁捕获 `generation`,二次锁写入前比较,不一致返回 cancelled | 单测:切换会话期间 deactivate,旧 session 不写入新代快照 |
| **F-18** | P2-3 | `commands.rs:632-656` | 校验通过且确认 client 存在后再 `upsert_chat_message`;失败路径按 message_id 回删或标记 error | 未连接状态下发送,历史里不留 user 行 |
| **F-19** | P2-4 | `commands.rs:412-461` | `probe_connection_slot` 激活前校验 `connection_slots` 分配,拒绝同一 profile 占用两个运行时槽;operations 切换守卫覆盖 probe/disconnect | 同一 profile 依次 probe 双槽 → 第二次被 `profileAlreadyAssigned` 拒绝 |
* * *
## R4 · 数据与凭据安全批
| ID | 来源 | 位置 | 动作 | 验证 |
| --- | --- | --- | --- | --- |
| **F-20** | P1-6 | `database/mod.rs:319-320` | 改 `SELECT * FROM (… ORDER BY updated_at DESC LIMIT ?) ORDER BY updated_at ASC`;补 `before`/`after` 游标参数 | 单测:插入 250 条,加载返回最新 100 条 |
| **F-21** | P1-18 | `diagnostics/redaction.rs:91` | `key_value_regex` 候选加入裸 `token`、`auth[_-]?token`、`id[_-]?token`、`session[_-]?token`;新增 JWT 形态正则 `eyJ[\w-]+\.[\w-]+\.[\w-]+` | 新测试**不使用 known_secrets**:`token=eyJ…`、`?token=…`、YAML `token: eyJ…` 均须被脱敏(现有测试用 canary 掩盖了缺口,需一并重写) |
| **F-22** | P2-11 | `diagnostics/config.rs:213,232,259` | YAML/INI/.env 增加按 key 的行级结构化脱敏(对齐 JSON/TOML 的 `is_sensitive_key` 路径) | `.env` 内 `AUTH_TOKEN=…` 经诊断返回时为 `[REDACTED]` |
| **F-23** | P2-9 | `profiles.rs:213-218` | 删除 profile 前读取 `credential_reference` 并 `store.delete`;可选:启动时孤儿凭据对账 | 删除 profile 后 Credential Manager 中对应条目消失 |
| **F-24** | P2-10 | `auth.rs:13-20`;`credentials/mod.rs:11-20` | 两个请求结构体手写 `Debug`(敏感字段输出 `[REDACTED]`)或改 `secrecy::SecretString` | 单测断言 `format!("{:?}", req)` 不含明文(对齐 `SecretCredential` 既有测试) |
| **F-25** | P2-12 | `database/mod.rs:524,556` 及相关读写 | 统一 `account_id` 键模型:两表都含并全部读写带上,或彻底移除该列 —— 二选一,写进 ADR | 迁移测试 + 隔离测试 |
* * *
## R5 · 协议健壮与契约治理批
| ID | 来源 | 位置 | 动作 | 验证 |
| --- | --- | --- | --- | --- |
| **F-26** | P1-5 | `gateway_client.rs:179-184,282-284` | `UnsupportedEventType` / `InvalidPayload` 降级为事件级跳过(记日志、推进 `last_event_id`),仅版本/身份不匹配保持终态 | 单测:mock 推未知事件类型 → 槽位保持 Connected,后续事件正常 |
| **F-27** | P2-15 | `envelope.rs:171` 及各 payload | 信封与只读 payload 移除 `deny_unknown_fields`(`ToolProposal`/`ToolResult` **保留**);或解析失败跳过并推进游标 | 单测:信封带附加字段仍能解析;不再出现重放死循环 |
| **F-28** | P1-8 | `docs/protocol/v1/schemas/`;`tests/protocol_contract.rs` | 重跑 `export_schemas --write`;新增测试比对 `generated_schemas()` 与磁盘文件 | `cargo test` 即可发现漂移;`connection-profile.schema.json` 含 `remoteDisplayName` |
| **F-29** | P2-16 | `astrbot.rs:17-43`;`src/features/chat/types.ts:13`;`ChatPanel.tsx:240`;README | `TransportKind` 加 `#[serde(rename = "astrbot-openapi")]` 统一两套拼写,前端 enum 与文档同步(**跨端原子改动,一次落地**;DB 值不变,无迁移) | 全库 grep 无 `astr-bot-open-api` 残留 |
| **F-30** | P2-5 | `astrbot_client.rs:128-133,431-438` | 删除恒 false 的身份自比较,或改为探测可观测特征后再比对;文档明示 AstrBot 身份为 URL 派生 | 代码无死分支;`docs/decisions/` 记录该限制 |
| **F-31** | P2-19 | `mock-gateway/src/routes.rs:196-206`、`state.rs:161-173`、`config.rs:29-31` | `Lagged` 改 `break`(迫使走重连重放);cursor 未命中先发 gap 事件;`server_instance_id` 掺端口 | soak 增加 sequence 单调无缺口断言 |
| **F-32** | P2-17 | `astrbot.rs:381-444` | complete 后记录 per-message 完成标记,同 id 的后续 plain/complete 需显式重新开窗或忽略 | 单测覆盖"重复 complete"与"complete 后迟到 plain" |
| **F-33** | P2-18 | `astrbot.rs:336-353` | 非图片媒体输出通用占位标记;`pending_media` 改 FIFO 队列 | 单测:`record` + `attachment_saved` 产出可见标记;双图交错不丢 |
| **F-34** | P2-13 | `commands.rs:341`;`ChatPanel.tsx:916-917` | mapper 为无 `message_id` 的流合成稳定流内 id(如 `synthetic-{stream}`),前后端同步取消 event_id 回退 | 单测:省略 message_id 的多帧流合并为一条消息 |
| **F-70** | P2-6 | `astrbot_client.rs:383-388` | `download_attachment` 先查 `Content-Length`,改流式累读并在超过 16MiB 时立即中断,不再整体读入内存后才校验 | 单测:mock 返回超限 body,客户端在读满前返回超限错误且内存占用有界 |
| **F-71** | P2-7 | `gateway_client.rs:121-126` | `health()` 与 SSE 一致附带 bearer | 单测:mock 对无 bearer 的 health 返回 401,激活仍成功即失败 |
| **F-72** | P2-8 | `gateway_client.rs:237-238` | 仅在「连接存活超阈值且收到过事件」时重置退避,避免服务端接受即优雅关流时进入约 10 次/秒热重连 | 单测:mock 接受连接后立即关闭,断言重连间隔单调增长 |
| **F-73** | P2-29 | `astrbot_client.rs:554-565` | JWT `exp` 判定改 `exp <= now + 30s`;不可解析的 token 打 debug 日志 | 单测:`exp` 落在 30 秒内的 token 被判为过期 |
上列四项系 2026-07-27 补编。它们与 F-26、F-30 同处 `gateway_client.rs` / `astrbot_client.rs`,按本队列
「同文件相邻改动合并进同一批」的编排原则归入 R5;放入 R4 会让两个可并行分支争夺同一文件。
R5 因此由 9 项增至 13 项,与 R3、R4 仍无依赖关系。
* * *
## R6 · 体验、无障碍与产品红线批
| ID | 来源 | 位置 | 动作 |
| --- | --- | --- | --- |
| **F-35** | P2-30 | `DesktopPetView.tsx:139-148`;`tauri.conf.json` | **产品红线**:`alwaysOnTop` 默认改 `false`(隔离基线要求气泡/桌宠不默认置顶);embedded 模式跳过偏好写入;非 embedded 先读既有偏好再增量提交 |
| **F-36** | P2-20 | `ChatPanel.tsx:73-74,181-187,264-293` | mark-read 完成后再重取会话列表;仅存在真实 `activeSessionId` 时标已读;非选中槽位监听事件递增未读 |
| **F-37** | P2-21 | `ChatPanel.tsx:468-475` | `retryMessage` 增加 `sessionId === activeSessionId` 过滤;`messageOverride` 与 draft 回退解耦 |
| **F-38** | P2-22 | `ChatPanel.tsx:435-457` | 按 `code === "cancelled"` 区分取消与真错误;停止时保留已收内容为正常消息,不标 error、不弹横幅 |
| **F-39** | P2-23 | `ChatPanel.tsx:920-925`;`chat/types.ts` | `ChatMessage` 补 `profileId`/`serverInstanceId` 并纳入所有 find/filter/去重键(对齐四元组规范) |
| **F-40** | P2-24 | `styles.css:3116-3139` | 去掉 `visibility:hidden`,仅用 opacity + pointer-events,解开键盘 focus-within 死锁 |
| **F-41** | P2-25 | `ChatPanel.tsx:607-620,711-717` | 箭头切换时 `focus()` 目标 tab;两个 panel id 常驻或动态 `aria-controls`;`aria-busy` 与 `aria-live` 分离 |
| **F-42** | P2-26 | `CredentialEnrollmentCard.tsx:34-80` | `finally` 中清空 secret/password/totp;两处 `invoke` 返回值补 zod schema |
| **F-43** | P2-27 | `ChatPanel.tsx:343-354` | 首次 refresh 失败也建立退避轮询;snapshot schema strict 失败给可见告警而非静默离线 |
| **F-44** | P2-28 | `ChatPanel.tsx` | 消息列表底部锚点 +"接近底部才跟随";unmount 调 `recognition.stop()` / `speechSynthesis.cancel()`;朗读前 Markdown 转纯文本 |
* * *
## R7 · 性能与工程化批
| ID | 来源 | 动作 | 预期收益 |
| --- | --- | --- | --- |
| **F-45** | 优化 §2 | `DesktopPetView.tsx:10` 去掉 `?inline` 改普通资源引用,manifest 与 import 同时切到已有的 WebP | lazy chunk 从 \~5.2MB 降到 \~0.6MB |
| **F-46** | 优化 §1 | `activeMessages` memo 依赖改标量 `activeSessionId`;`MessageContent` 套 `React.memo`;`applyRuntimeEvents` 只克隆命中项;`messages` 按会话修剪 | 消除 500ms 全表重渲染与重复 Markdown 解析 |
| **F-47** | 优化 §3 | 附件上传/下载改 Tauri 2 raw body / `tauri::ipc::Response` 二进制通道;Rust 侧去掉 `bytes.clone()` | 16MiB 附件不再膨胀成 1670 万元素数组 |
| **F-48** | P2-14 | 事件通道改"每槽独立 mpsc + 唯一持久化点 + 广播 emit",移除 `drain_connection_runtime_events` | 消除双消费者抢事件与跨槽背压 |
| **F-49** | 优化 §2 | `send_slot_message` 的 `client.take()` 改 `clone()`,以 `message_cancellation` 存在性串行化发送 | 长流期间 sessions/capabilities/upload 不再误报"未连接" |
| **F-50** | 优化 §5 | `styles.css` 以 `--ui-*` 为唯一 token 源合并,删除 OS 亮色媒体查询块与幽灵 token,引入 stylelint | 减约 40% 死样式;修复暗色下链接对比度 |
| **F-51** | P2-31 | `tauri.conf.json` 的 `beforeDevCommand`/`beforeBuildCommand` 改 `pnpm run`;engines 与 `@types/node` 对齐;文档 React 版本更正为 19 | 消除双包管理器混跑 |
| **F-52** | P3-17 | tsconfig 补 `noUnusedLocals`/`noUncheckedIndexedAccess`;eslint 接 jsx-a11y、重开 `set-state-in-effect`;vitest 加 coverage;关掉无谓的 `usePolling` | 编译期即可暴露索引假设类缺陷 |
* * *
## R8 · 剩余 P3 与外部依赖
**可随手带入相邻批次的 P3**:`F-53` 事件 timestamp 注入真实时钟(P3-1)· `F-54` `server_instance_id` 改 sha2 派生 + 兼容映射(P3-2)· `F-55` username 逐字节百分号编码(P3-3,**放宽用户名规则前必须先修**)· `F-56` 取消消息不再置 Disconnected(P3-4)· `F-57` 生产 CSP 移除 `127.0.0.1:*`(P3-5)· `F-58` 凭据轮换改「写新→落库→删旧」(P3-6)· `F-59` 退出前 deactivate 双槽并 flush 日志(P3-8)· `F-60` session_id 对象分支取键(P3-9)· `F-61` 桌宠窗口补 Suspense 边界(P3-10)· `F-62` 导航图标 `aria-hidden` + 测试选择器改语义文本(P3-11)· `F-63` reduced-motion 停帧 + onerror 清理 + DPR(P3-12)· `F-64` 文案统一中文(P3-13)· `F-65` 死控件与标签错误四处(P3-14)· `F-66` 测试 SSE 助手容错(P3-15)· `F-67` App.test mock 补 `close_pet_window`(P3-16)· `F-68` mock 订阅重放竞态(P3-18)· `F-74` operations 切换守卫无生产写入方(P3-7)
**F-74 补充说明**(2026-07-27 补编):该守卫的**读侧已全线接通**——`slots.rs:97,108` →
`policy.rs:18-22` → `ProfileManager.tsx:276` 会依据 `operationsSwitchLocked` 禁用运维槽控件;但
`begin_operations_task` / `end_operations_task`(`runtime_guards.rs:28,45`)的调用方只有
`#[cfg(test)]`(`slots.rs:256,285`),因此 `connection_policy_status` 把一个**永为 false 的标志**
当作已激活的守卫上报。R3 的 F-19 只是把读侧扩展到 probe/disconnect,不含写侧,因此不覆盖本项。
审计给出的近期动作是**先在状态载荷中如实标注守卫未激活**,写侧接线待工具管线落地——这与下节
「工具提案六道闸门」条目联动。
**需要真机/外部条件,不进本轮编码**:
- **P1-9 附件契约验证**(置信度中):用真实容器发一条带图消息,确认模型是否真的看到附件。若确认被忽略,改为 `message` 段数组承载 `attachment_id`(snake_case),这会是一个 P1 级改动。
- **证书指纹绑定**:在实现 TLS 校验前,建议在录入层标注"暂不生效",避免虚假安全感。
- **工具提案六道闸门**:未开始实现属阶段合理;**在闸门落地前不得放开任何工具执行入口**,`connection_policy_status` 应如实上报 guard 未激活。
- **签名更新、双服务器 soak**:维持现状,不在本地伪造。
* * *
## 附录 · 批次依赖图与建议分支
| 批次 | 依赖 | 建议分支 | 可并行 |
| --- | --- | --- | --- |
| R1 | 无 | `fix/p02-release-blockers` | 内部 9 项可并行(除 F-06→F-08) |
| R2 | R1 的 F-01 | `fix/astrbot-stream-transport` | 内部串行 |
| R3 | R1 的 F-06 | `fix/slot-isolation-and-state` | Rust 项与前端项可分两人 |
| R4 | 无 | `fix/data-and-secret-boundaries` | 与 R2/R3 并行 |
| R5 | 无 | `fix/protocol-contract-hardening` | 与 R2/R3/R4 并行 |
| R6 | R3 | `fix/chat-ux-and-a11y` | — |
| R7 | R6 | `perf/frontend-and-ipc` | — |
| R8 | — | 随批携带 | — |
按 `AGENTS.md` §11,每批合并前须走完:fmt → lint → typecheck → clippy(-D warnings) → 单元测试 → 适用集成测试 → 生产构建 → 更新 `docs/progress.md` 与 `CHANGELOG.md`。R1 与 R2 合并后建议同时刷新 `docs/q9-local-acceptance.md` 的验证记录。