Skip to content

fix(agent): 重启后接管等待中的问题,并正确处理过期回答 - #1707

Merged
chen-ran merged 1 commit into
felinics:mainfrom
ChrAlpha:fix/ask-user-restart-independent
Nov 1, 2026
Merged

chen-ran merged 1 commit into
felinics:mainfrom
ChrAlpha:fix/ask-user-restart-independent

Conversation

@ChrAlpha

@ChrAlpha ChrAlpha commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Author

  • Human
  • Agent

Type

  • bug
  • feat
  • test

Summary

使用 Memory live backend 时,Server 重启会让等待 ask_user 回答的 run 丢失接管路径;历史问题还可能保持可回答,但用户提交后无法续跑。重启接管后,丢失的内存视图也会使问题卡片消失。另一个标签页提交迟到答案时,Web 会保留未生效的乐观答案。

本 PR 让 native parked decision 在 Memory 和 Redis 下都能交接、恢复 fence 并接续同一个 run;从持久化历史重建丢失的步骤和问题卡片,后续输出接在已有内容之后。异常结束的 run 同时关闭遗留的 ask_user 请求和工具审批;WebSocket 通过稳定的 expired code 回报未应用的回答,Web 撤回该乐观答案并显示过期提示。

已于 2026-11-02 rebase 到 main (e82c2ca5f),当前 head 1b9001f3b。本 PR 尚未合入的清理迁移已从 0170 顺延为 0172_close_decisions_of_ended_runs,避开 main 已合入的 0170_history_checkpoints 和 0171_session_attention;不修改已发布迁移。迁移仍仅关闭已结束 run 遗留的 pending 请求,不变更 schema;down 保留清理后的数据。冲突处理中保留 main 的分叉历史决策只读处理及其测试,同时保留本 PR 的重启恢复能力。

Related Issues

无自动关闭关联 issue。

Validation

2026-11-02 rebase verification (1b9001f3b)

  • Rebase 到 main e82c2ca5f;清理迁移顺延为 0172。数据库查询接口保留两侧新增方法;HTTP 历史装饰保留 main 的分叉决策只读逻辑与测试。
  • mise run sqlc-generate:通过,无额外生成差异;git diff --check:通过。
  • Session Runtime / ledger、application、decision / approval / input、view、handlers、db/store 包测试:通过。
  • golangci-lint 2.10.1(仓库 mise 固定版本):通过。诊断过程中曾直接调用系统 2.11.4,出现不同规则的报错;最终以仓库固定版本重跑通过。
  • 前端 decisions.test.ts:12/12 通过;本 PR 的三个前端文件 ESLint 通过;UI contract guard 通过,保留仓库已有的 3 条 warning。
  • 独立 PostgreSQL 18 从开发迁移入口升至 version 172,dirty=false;0172 down/up SQL 事务执行通过;三张相关表的 RLS 与 FORCE RLS 均为 true。清理迁移逻辑未改动。
  • 开发环境 memoh-pr1707-rebase,Web http://localhost:45082/bot/pr1707-rebase,Server http://localhost:45080。使用仓库 scripts/dev-compose.sh + 仓库外隔离 override。Docker 一度出现容器 inspect 超时与 pgvector 恢复;经用户允许重启 Docker 后恢复。后端使用从当前干净 head 交叉编译的 Linux arm64 二进制挂载运行,容器内外 SHA-256 相同;Web 挂载当前源码,Server / Channel / PostgreSQL / pgvector / Connect-It 健康。验收结束后已停止该独立栈,保留数据卷。
  • 真实浏览器流程:在聊天页发送确定性 fixture 任务 → 显示 ask_user → SIGKILL 并启动 Server → 刷新原页面 → 原问题仍可回答 → 选择 Continue 并提交 → 显示后续输出。数据库独立确认同一 run b78667c1-ad67-498c-8808-3a709d2fe8ab、turn 283a5fc9-aa8f-4dc3-9ab5-6c0e22c379f4 完成,fence 10 → 11,问题为 submitted。
  • 当前 head 黑盒 TestSRBASE001BaselineCompletesAndPersists、TestSRDEC001DecisionPersistsRunAndTurnAcrossRestart(graceful + SIGKILL):全部通过,单 Server + Memory + 真实 PostgreSQL。GitHub 当前 head 的检查为 21 项通过、1 项 publish 按条件跳过,无失败或待完成项;通过项包括 PostgreSQL migrations、Go / Web lint 与测试、Session Runtime Redis / Valkey / PostgreSQL fencing 和构建。
  • 本轮使用确定性 provider,不是新的真实模型验收。旧 head 的 MiMo、双标签页与 Redis 记录保留在下面;本轮 Agent 验证不等于 Human QA。

Historical validation (aec751c21)

以下为旧 head aec751c21 的历史验证记录;不代表 rebase 后已重跑所有项目:

  • mise run sqlc-generate:通过,生成结果仅包含本次 tool approval 查询。
  • Session Runtime、application、decision、view、handlers、apperror、server 包测试:通过。Session Runtime 首次全包运行在关闭/准入并发用例处超时;该用例单独复跑及全包重新运行均通过。
  • TestPostgresDecisionSurvivesGracefulShutdown:真实 PostgreSQL 18 + Memory / Valkey 两组通过,验证接管、回答与重复提交。
  • 黑盒 TestSRBASE001BaselineCompletesAndPersists 和 TestSRDEC001DecisionPersistsRunAndTurnAcrossRestart:通过;单 Server + Memory,覆盖 graceful shutdown / SIGKILL,断言同一 run/turn、pending 请求、续跑完成及回执幂等。使用确定性 OpenAI-compatible fixture provider。
  • 0170 down/up:通过;session_runs、user_input_requests、tool_approval_requests 的 RLS 与 FORCE RLS 均保持启用。
  • 前端决策及 HTTP/SSE 错误测试:3 个文件、135 项通过。
  • Go lint、ESLint、UI contract guard:通过。ESLint 有 20 条 warning,contract 有 3 条 warning,均位于本次改动范围之外。mise run lint 的嵌套任务使用了环境里的 pnpm 11,因 lockfile 配置不匹配失败;切回仓库指定 pnpm 10 后逐项运行相同检查通过,lockfile 未修改。
  • vue-tsc --noEmit:通过。

Real provider / headed-browser E2E

2026-10-28,在同一 head aec751c21、独立 dev compose stack memoh-askuser-s2 上,以真实 mimo-v2.6-pro 和有窗口的 Chromium 156.0.8078.4(headless=false,隔离 X11/Xvfb 桌面)完成以下三条用户流程。Web:http://localhost:44282/bot/pr1707-real-mimo;Server:http://localhost:44280;单 Server + Memory live backend,数据库 migration 170,无 checkpoint engine unit。

通过实际聊天页面发送自然语言任务:生成 NAS 迁移草稿与执行日志 → ask_user 选择切换窗口 → 生成最终计划。发送消息、回答、刷新、关闭/重新打开标签页,以及点击最终文件链接,均在真实浏览器中操作;PostgreSQL、工具调用记录和工作区文件提供独立核对。

用户流程 观察结果
刷新浏览器 + 正常重启 Server 原问题仍可回答,同一 run 恢复;fence 11 → 13,选择“周六白天”后正常完成,最终文件使用该选择。
关闭标签页 + SIGKILL Server + 启动后重新打开标签页 原问题恢复,同一 run 完成;fence 14 → 15,选择“周日晚上”后正常生成最终计划。
慢网双标签页提交冲突答案 仅延迟第二个标签页的服务端 WS 帧;第一个标签页提交“周六白天”,落后标签页随后提交“周日晚上”。迟到提交返回 user_input.expired 并显示过期提示;持久化答案和最终文件均保留“周六白天”。

独立核对结果:三个 run 全部为 completed,三个问题均为 submitted,已结束 run 遗留的 pending 问题数为 0。每个任务持久化的 draft.md 写入、final.md 写入和 ask_user 调用各一次;草稿前后内容一致,实际 activity.log 中“草稿已生成”和“计划已确认”各一行。点击聊天中的 final.md 链接后,应用文件编辑器正常打开最终计划并显示正确的切换窗口。

应用发出的 19 次真实模型请求全部返回 HTTP 200:provider usage 共报告 input 366,587 tokens、output 8,033 tokens,其中 cached input 339,968 tokens。这些数字仅统计应用请求,不含接入探测。模型 context window 配置为 200k,本轮验证范围是等待决策与重启续跑。

接入方式:临时代理在内存中注入认证并转发到真实网关;初始 Python User-Agent 探测被网关以 403 拒绝,改为 curl/8.14.1 User-Agent 后,上述应用请求全部成功。真实密钥未写入配置、数据库、日志或仓库;验收结束后代理已停止,临时 provider 已禁用。

覆盖边界:这三条代表性用户流程通过;Redis 双 Server 拓扑、其他频道及工具审批尚未使用本次真实 provider 重跑。上述自动化与 Agent 浏览器验收不等同于 Human QA。

Screenshots / Recordings

2026-11-02 current head (1b9001f3b)

当前版本真实聊天页面的待回答问题:

当前 head:等待用户回答

SIGKILL Server 后刷新原页面,问题卡片仍可回答:

当前 head:崩溃重启后恢复原问题

在恢复后的卡片提交 Continue,随后显示 fixture 输出;同一 run/turn 完成由上面的数据库核对支持:

当前 head:回答后同一任务完成

Real MiMo / headed Chromium

正常重启后,在原问题卡片提交回答,同一 run 完成并保留草稿、选择和最终文件。

真实 MiMo:正常重启后完成原任务

SIGKILL 并重新打开标签页后,原问题仍可回答;截图包含完整 Chromium 窗口和地址栏。

真实浏览器:SIGKILL 后重新打开原问题

在恢复后的问题中选择“周日晚上”,同一 run 完成并生成对应计划。

真实 MiMo:崩溃接管后按用户选择完成

第二个标签页提交迟到的冲突答案时显示过期提示,并保留先前已生效的“周六白天”。

真实浏览器双标签页:迟到答案过期提示

点击聊天中的最终文件链接,应用文件编辑器显示实际生成的 NAS 迁移计划和已确认窗口。

真实浏览器:打开生成的最终计划

Deterministic fixture evidence

以下保留首次独立分支验收的确定性 fixture 截图:重启后原问题保持可回答、回答后同一 run 完成,以及迟到回答显示过期提示。

Server 重启后原问题保持可回答

恢复后回答使同一 run 完成并保留问题卡片

迟到答案显示过期提示并收敛到已生效的答案

Human QA

  • Human QA passed

@github-actions github-actions Bot added bug Fixes a bug or unexpected behavior change:migrations Adds, modifies, or removes database migrations change:server Changes backend code, configuration, or API contracts change:web Changes web frontend or shared frontend packages size:L PR size uses the larger of added or deleted lines, excluding generated files labels Oct 28, 2026
@ChrAlpha
ChrAlpha requested a review from qqqqqf-q October 28, 2026 14:33
@ChrAlpha
ChrAlpha marked this pull request as ready for review October 28, 2026 15:16
@chen-ran
chen-ran force-pushed the fix/ask-user-restart-independent branch from aec751c to 1b9001f Compare November 1, 2026 22:24
@chen-ran
chen-ran merged commit 524b734 into felinics:main Nov 1, 2026
24 checks passed
chen-ran added a commit that referenced this pull request Nov 22, 2026
…p dead tests and CI entries (#1831)

Toolchain
- go.mod, mise.toml and the three Go base images move from 1.26.10 to 1.27.4.
  CI reads the version from go.mod.
- golangci-lint moves from 2.10.1 to 2.15.0 (mise.toml, go-ci.yml). 2.10.1 is
  built with Go 1.26 and cannot load a Go 1.27 module at all.

Behavior change that comes with Go 1.27
- encoding/json is backed by the v2 implementation, and the Field of an
  UnmarshalTypeError is now the full path, with the index of an array element
  and the key of a map value. Two places pass that field on:
  - request.field_invalid from httpx.Binder: "items.1.count" where it was
    "items.count", "meta.k.count" where it was "meta.count".
  - the decode error a tool call returns to the model: "ids.2 must be an
    integer" where it was "ids must be an integer".
  Top-level and nested object fields are unchanged. docs/errors.md describes
  the field, and a test for each place pins it; both fail on Go 1.26.10.

What the new linter reports on the existing code (0 findings on 2.10.1, 205 on
2.15.0, 193 of them in test files)
- noctx (166): httptest.NewRequest becomes NewRequestWithContext. A request
  that was given a context right after takes that context directly.
- errcheck (19): an error received from a channel and dropped. Tests log it or
  assert it; cmd/bridge reaps Xvnc after killing it and says so.
- gosec G602 (7): loops that re-evaluated turns[i].Messages for every element
  index a named slice; two test helpers become slices.Equal.
- govet nilness, staticcheck SA4023: a `case !existingReady` that follows
  `case existingReady` is the default, and a clipboard reader that only
  returns on failure is not checked for a nil error.
- gofumpt (4), predeclared (1), and four findings kept with a stated reason.

Lint job
- golangci-lint ran with only-new-issues, so findings in code a PR did not
  touch were never reported; that is how the above accumulated behind a green
  check. The job lints the whole module now and no longer needs full history.

Commit hook
- .husky/checks.mjs decided whether it was the entry point by comparing
  argv[1] with its own real path. In a checkout reached through a symlink
  (macOS /tmp, a linked worktree directory) the two differ, so the hook ran
  nothing and exited 0, for an unknown check name too. It compares real paths.
- scripts/hook-checks.test.mjs inherited the caller's MEMOH_* settings, so a
  commit that touches .husky/ and uses the documented
  MEMOH_CHECK_TIMEOUT_SECONDS override failed three of its own regression
  tests. The fixture drops them.

Removed, not replaced
- internal/channel/identities/service_integration_test.go: `//go:build ignore`
  since February; no build includes it.
- internal/settings/default_agent_concurrency_postgres_integration_test.go:
  has not compiled since #1110 changed botagents.Service.Delete, and no CI
  step builds the integration tag for that package.
- internal/audio/adapter/edge/ws_integration_test.go: calls the live Edge TTS
  service with no skip condition and writes mp3 files to the temp directory.
- go-ci.yml: the RedisDecision alternative of a -run pattern, which has
  matched no test since #1707 renamed it (the new name is still selected).
- eslint.yml: four path filters shadowed by "packages/**" in the same list.
- eslint.config.mjs: an ignore entry for a file #1813 deleted.
- .golangci.yml: `go: "1.25"` (the default reads go.mod) and settings for two
  linters that are not enabled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Fixes a bug or unexpected behavior change:migrations Adds, modifies, or removes database migrations change:server Changes backend code, configuration, or API contracts change:web Changes web frontend or shared frontend packages size:L PR size uses the larger of added or deleted lines, excluding generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants