Skip to content

fix(memory): wake the worker after every session close - #565

Open
Anson-Se wants to merge 1 commit into
MemTensor:memmy_1031/v1.2.0from
Anson-Se:fix-session-close-wake-worker
Open

Anson-Se wants to merge 1 commit into
MemTensor:memmy_1031/v1.2.0from
Anson-Se:fix-session-close-wake-worker

Conversation

@Anson-Se

Copy link
Copy Markdown
Contributor

任务与行为

  • **关联记录:**Memmy 问题清单第 5 条"关闭会话后,新排的 L3 任务不会唤醒 worker"。
  • **触发场景:**L3 世界模型 v2 会话中,episode 在关闭会话之前已经关掉(空闲超时或 end_topic),随后宿主发来关闭会话请求(例如 /new、会话结束钩子)。
  • **修改前:**关闭接口只有在结果里带着被关闭的 episode、任务或 scheduledEvolution 时,才唤醒自动 worker。closeSession 会冻结这个会话的 L3 证据批次,并排队 l3_world_model_update 任务,但不把它们放进结果。episode 已经提前关掉时,closedEpisodeIds 为空,worker 就不会被唤醒。worker 也不做周期轮询,这些 L3 任务要等下一个无关请求唤醒 worker 才会执行,实测等了 2 分 41 秒。
  • **修改后:**关闭接口每次都唤醒一次 worker,和压缩边界接口冻结批次后的做法一致。没有后续任务时,只是多做一次空的 drain。

修改范围

  • Memory/src/server/http.ts:关闭会话接口改为无条件调用 autoWorker.schedule(),1 行代码加 1 行注释。
  • Memory/tests/contract/memory-rest-service.test.ts:新增用例。L3 v2 会话先用"结束会话"关掉 episode,再经 REST 关闭会话,断言 closedEpisodeIds 为空、冻结出 1 个 L3 任务,并且 worker 在 1 秒内捡起了它。
  • 无前置依赖。不改接口和数据结构,不迁移数据。没有改 session-turn-service.ts。

验证证据

  • 分支 fix-session-close-wake-worker,起点 d101fd58(即当前 memmy_1031/v1.2.0),提交 29ef0723。提 PR 前已 fetch 并 merge 集成分支(Already up to date)。
  • 环境:macOS arm64,Node v25.1.0,npm 11.6.2。
  • 新增用例在修改前失败:Error: timed out waiting for condition,等满 1 秒后 L3 任务仍是 queued、attempts 为 0;修改后通过,连续跑 8 次都通过。原有的关闭用例仍通过。
  • npm run memory:test:106 个测试文件中 104 个通过、1 个跳过(仅在 Windows 上运行的安装器集成测试)、1 个失败;921 个用例中 919 个通过。失败的是 l3-world-model.test.ts 的 "keeps source IDs in evidence order and caps them at the latest 256…",原因是超时:上限 20 秒,这台机器跑全量时它要 35 秒左右。这个失败和本 PR 无关:
    • 在不含本 PR 改动的 d101fd58 上,同样条件下跑全量,也是这一条超时(35.4 秒,920 个用例中 918 个通过)。
    • 单独运行这条用例能通过,用时 13.5 秒。
  • npm run lint、npm run typecheck 通过。
  • git diff --check upstream/memmy_1031/v1.2.0...HEAD 无输出;交付差异只含上面两个文件。
  • 和 upstream/v1.1.9 做过试合并(git merge-tree),没有冲突。

已知限制

  • 测试环境没有配置模型,新用例只断言 worker 捡起了 L3 任务,不验证 L3 的写入结果。
  • episode 提前关闭只测了 end_topic,空闲关闭没有单独写用例。两种情况走的是同一段关闭接口代码。
  • 打开会话接口只在 v2 会话带 projectId 时唤醒 worker。v1.1.9 在切换 v2 会话时会新排工作记忆任务,不带 projectId 时同样不会被唤醒。这条路径不在本 PR 范围内。

🤖 Generated with Claude Code

The session close route only woke the auto worker when the close result
listed closed episodes, jobs, or scheduled evolution. For an L3 World
Model v2 session, closeSession also freezes the pending L3 evidence
batches and queues l3_world_model_update jobs, but it does not return
them. When the session's episode had already closed earlier (idle
timeout or end_topic), closedEpisodeIds was empty and nothing woke the
worker. The worker does not poll, so the new L3 jobs stayed queued until
an unrelated request happened to wake it.

The close route now always schedules the worker, as the token compaction
boundary already does after freezing batches. A close with no follow-up
work costs one empty drain. A new REST contract test closes an L3 v2
session whose episode had already ended and checks that the worker picks
up the frozen L3 job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings September 29, 2026 04:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Anson-Se

Copy link
Copy Markdown
Contributor Author

@origami-chen 麻烦审核一下这个 PR:修复关闭会话后新冻结的 L3 任务不会唤醒 worker 的问题。关闭接口改为每次都唤醒一次 worker,只改了 1 行。细节见 PR 描述。谢谢!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants