diff --git a/CHANGELOG.md b/CHANGELOG.md index 9822373..45f53a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,27 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and ### Fixed +- One unreachable connection no longer freezes the whole application. The reachability probe now + runs outside the runtime lock, so a slot that is connecting cannot block status, sending, + cancelling or disconnecting on the other slot, and the attempt itself can be interrupted. +- An activation rejected during validation no longer tears down a working connection or leaves the + slot stuck in "connecting" with nothing to explain it. +- Switching a session while the slot is being reconnected no longer writes the old session id onto + the new connection, and no longer copies it into that profile's sticky session. +- One connection profile can no longer be activated into both slots at once, which previously let + the two slots overwrite each other's sticky session. +- Disconnecting or re-pointing the operations slot is now refused while an operations task is + active, matching the existing rule for slot assignment. +- A rejected chat send no longer leaves the question in local history without a failure marker, and + retrying no longer appends a second copy of it. A send that fails after AstrBot accepted it keeps + its question, since the remote conversation already has it. +- Streaming replies are no longer doubled in development. Event listeners that resolved after their + component had unmounted were never unregistered, so a leaked listener applied every delta twice. +- The composer draft, pending attachments, and the error banner are now per slot. An attachment + uploaded on the companion slot no longer follows the user to the operations slot, and an error + from one slot no longer appears on the other. +- An error from sending or uploading is no longer erased half a second later by the connection + status poll. - Scoped AstrBot stream event ids per chat request so the second and later messages on a connection are no longer discarded by the client-side event deduplicator. - Accepted Rust `null` values in the runtime-event, remote-session, and model-option diff --git a/docs/progress.md b/docs/progress.md index cb04e27..d4f0c44 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -553,3 +553,56 @@ pending in `docs/q9-local-acceptance.md`. Certificate pinning, signed updates, a remain externally blocked. Next: batch R3 (isolation and state correctness), F-14 through F-19. + +## 2026-07-27: batch R3, isolation and state correctness + +Current stage: P02 dual connections, branch `feat/p02-dual-connections`. Six commits, one per fix. + +### Completed + +- **F-14** `activate_slot` no longer holds the runtime lock across the reachability probe. It is now + three phases: validate and build the client with no lock, claim the slot in one critical section + that installs the cancellation token up front, probe outside the lock under a biased `select!`, + then write back only if the slot's generation still matches. One unreachable address used to + freeze every command on both slots for up to 120 seconds, and the activation could not be + interrupted. This also fixed an unrecorded defect: validation ran after the `Connecting` snapshot + was written, so a rejected request tore down a working connection and parked the slot in + `Connecting` with no client and no error. +- **F-17** `switch_slot_session` captures the generation with the client and checks it before + writing `active_session_id`, so a slot reset mid-switch cannot receive the old session id. +- **F-19** One profile can no longer occupy both runtime slots. Enforced inside `activate_slot` + (which also covers startup auto-connect), cross-checked against `connection_slots` in the + command, and the operations switch guard now covers probe and disconnect. Both rules are + negative — they ask only whether the profile is bound to the *other* slot — because auto-connect + activates from `auto_connect_slot` and never writes `connection_slots`. +- **F-18** Sends are validated before anything is written to history, via a new read-only + `ensure_slot_can_send`. A failure that the server never received marks the row rather than + leaving it clean; `cancelled` and `streamInterrupted` keep the question because AstrBot already + has it. +- **F-15** All four `listen()` call sites now unregister correctly when the promise resolves after + the effect was cleaned up. Under StrictMode the first listener leaked on every mount, which + doubled every character of a streamed reply. +- **F-16** `draft`, `pendingAttachments`, and the error banner are per slot, and every async action + pins its slot at the start. The error state was split in two: the 500ms status poll used to clear + the shared error on success, silently erasing action errors. + +### Test status + +Rust 107 passed / 2 ignored (`astrbot-desktop` unit tests 76 → 87). Frontend 24 passed / 5 files +(19 → 24, including a new `ChatPanel.test.tsx`, which the component previously had none of). +Playwright 5 passed. `npm run build` and `npm run tauri:build` pass. + +The new tests for F-14, F-15, and F-16 were each checked against a mutation restoring the old +behaviour, and each fails under it, so they are not tautological. + +### Not covered + +`auto_connect_configured_slots` is still serial, so a dead profile delays the second profile by up +to 120 seconds — it no longer freezes the UI, but the delay remains. The operations switch guard +still has no production writer (F-74, audit P3-7); F-19 extends only its read side. + +Real-hardware acceptance for R3 has not been performed; the steps are listed in +`docs/q9-local-acceptance.md`. + +Next: batch R4 (data and credential boundaries) or R5 (protocol hardening). Neither depends on R3, +so they can be dispatched in parallel. diff --git a/docs/q9-local-acceptance.md b/docs/q9-local-acceptance.md index 1ae8414..0a13808 100644 --- a/docs/q9-local-acceptance.md +++ b/docs/q9-local-acceptance.md @@ -106,6 +106,31 @@ Not executed, not claimed. Each item names the fix it is the acceptance evidence Items 1 and 2 need only the installer, not a container. +## 2026-07-27 verification update (R3 isolation and state correctness) + +### Gate results + +`cargo fmt`, `cargo clippy --workspace --all-targets -D warnings`, and `cargo check` pass. +`cargo test --workspace`: 107 passed, 0 failed, 2 ignored (`astrbot-desktop` unit tests 76 to 87). +`npm run typecheck`, `npm run lint`, `npm run build` pass. `npm run test -- --run`: 24 passed across +5 files, up from 19 across 4 — `ChatPanel.test.tsx` is new, the component had no tests before. +`npm run test:e2e`: 5 passed. `npm run tauri:build`: passed; +`target/release/bundle/nsis/AstrBot Desktop_0.1.0-alpha.2_x64-setup.exe`, 8,874,747 bytes, built +2026-07-27 00:30:22 +0800. + +The new tests for F-14, F-15 and F-16 were each run against a mutation restoring the old behaviour +and each fails under it, so they exercise the invariant rather than restating the implementation. + +### Pending, requires a live AstrBot container + +1. With one slot pointed at an unreachable address, confirm the other slot's status, sending and + disconnect stay responsive, and that the connecting slot can be interrupted with 断开 — F-14. +2. Upload an attachment on the companion slot, switch to operations, send; the attachment must not + follow. Type a draft on one slot and confirm it does not appear on the other — F-16. +3. Send while disconnected and confirm no user row appears in history — F-18. +4. Probe the same profile into both slots in turn; the second must be refused — F-19. +5. Confirm a streamed reply renders each character once in a production build — F-15. + ## Explicitly pending external acceptance - HTTPS certificate pinning requires a real HTTPS endpoint and first-trust confirmation. diff --git a/docs/reports/fix-queue-2026-07-26.md b/docs/reports/fix-queue-2026-07-26.md index bf3c588..9027525 100644 --- a/docs/reports/fix-queue-2026-07-26.md +++ b/docs/reports/fix-queue-2026-07-26.md @@ -16,7 +16,8 @@ |---|---|---| | 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 – R8 | 未开始 | 下一批为 R3。依赖关系见文末批次依赖图。 | +| 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` 的结果是 @@ -74,6 +75,45 @@ 在把它二分到具体注入行之后才定位到真因。**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`,每个异步动作开头 + `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` diff --git a/docs/reports/r1-r2-status-2026-07-26.md b/docs/reports/r1-r2-status-2026-07-26.md index 368bf40..b60395f 100644 --- a/docs/reports/r1-r2-status-2026-07-26.md +++ b/docs/reports/r1-r2-status-2026-07-26.md @@ -14,14 +14,18 @@ | --- | --- | --- | --- | --- | | R1 发布阻断批 | 9 | 已完成 | 已通过 | **未做** | | R2 传输层批 | 4 | 已完成 | 已通过 | **未做** | -| R3 隔离与状态正确性 | 6 | 未开始 | — | — | +| R3 隔离与状态正确性 | 6 | 已完成 | 已通过 | **未做** | | R4 数据与凭据安全 | 6 | 未开始 | — | — | | R5 协议健壮与契约治理 | 13 | 未开始 | — | — | | R6 体验、无障碍与产品红线 | 10 | 未开始 | — | — | | R7 性能与工程化 | 8(1 项已提前完成) | 未开始 | — | — | | R8 剩余 P3 | 17(1 项已提前完成) | 未开始 | — | — | -**已完成 15 项,剩余 58 项。** 共 10 个提交,工作区干净。 +**已完成 21 项,剩余 52 项。** 工作区干净。 + +> 2026-07-27 更新:R3(F-14 – F-19)已实现并通过门槛,实现记录见 +> [fix-queue-2026-07-26.md](./fix-queue-2026-07-26.md) 的「R3 实现记录」。R3 的真机验收项 +> 已并入 `docs/q9-local-acceptance.md` 的待真机清单。 > 2026-07-27 订正:R5 由 9 项增至 13 项、R8 由 16 项增至 17 项。初版队列遗漏了审计中的 > P2-6、P2-7、P2-8、P2-29、P3-7 五条发现,现补编为 F-70 – F-74(`F-69` 保持永久空缺)。