fix(core): capacity-memory checkpoint and cross-session recovery
Description
Two related bugs in the capacity-memory system prevent cross-session state recovery.
Bug 1: Missing shutdown checkpoint
When a session ends (via /exit, SIGTERM, etc.), the engine does not persist any memory record unless the user has explicitly enabled capacity.enabled = true. Since capacity scoring is disabled by default, the vast majority of users never get a checkpoint written.
Impact: A new exec --auto session starts with a completely blank CanonicalState — goal, confirmed_facts, and all other state fields are empty. The model cannot answer "what did we work on in the previous session?"
Location: crates/tui/src/core/engine.rs — no write happens on Op::Shutdown.
Bug 2: No cross-session scan fallback
Even when memory records exist (from a prior session that had capacity scoring enabled), rehydrate_latest_canonical_state() only looks at the current session ID's memory file at ~/.deepseek/memory/<current_session_id>.jsonl. Each exec --auto invocation generates a fresh random session UUID, so the current session's file is always empty.
Impact: Memory records from previous sessions are effectively orphaned. There is no fallback to scan sibling *.jsonl files in ~/.deepseek/memory/.
Location: crates/tui/src/core/engine/capacity_flow.rs — rehydrate_latest_canonical_state() only calls load_last_k_capacity_records(&self.session.id, 1).
Expected behavior
- On engine shutdown, a lightweight checkpoint record should always be written — regardless of whether capacity scoring is enabled.
- When starting a fresh session with no local records, the system should fall back to scanning all memory directories for the newest available record.
- Cross-session recovery must be opt-in and workspace-scoped to prevent memory bleed across unrelated projects.
Proposed fix
PR #937 implements all three requirements:
- Writes a shutdown checkpoint in
write_shutdown_checkpoint()onOp::Shutdown - Adds
find_latest_cross_session()fallback inrehydrate_latest_canonical_state() - Attaches workspace path to each record; cross-session scan filters by workspace
- Adds
capacity.cross_session_enabledopt-in flag (defaultfalse)
yes! thank you so much for finding this
this has been causing large bugs for me in other spaces - hpoing this fixes it
Thanks! I've since upgraded the fix in PR #937 to an even better approach — instead of relying on memory JSONL files, it now reads saved session JSON files directly via SessionManager. This gives us full message history for recovery and is naturally workspace-scoped. Same 3-tier fallback, cleaner design.
Would love your thoughts when you get a chance to look at the updated PR.
Code review 确认了一个额外的根因:
Runtime::new 静默丢弃 job 加载错误 (crates/core/src/lib.rs:672):
let _ = jobs.load_from_store(&state);
数据库损坏、schema 不匹配、I/O 失败等错误被完全静默 — 不报错、不警告、不 log。启动后 job 列表为空,用户无感知。
这和本 issue 描述的两个 bug 互补:
- Bug 1 (shutdown 不写 checkpoint) — 导致写入端没有数据
- Bug 2 (只查当前 session) — 导致读取端找不到数据
let _ =静默丢弃 — 导致即使有数据也可能加载失败且无提示
三者叠加意味着跨 session 恢复几乎必然失败。
是的,你的发现确实很及时,我本地的deepseek-TUI程序是没有考虑到您说的这两个BUG,但是我的#937 PR确实解决了跨会话恢复上下文(固定倒序读取最近20-30条对话历史记录,如果读取的对话历史记录足够恢复上次的对话场景,那么截断,反之则继续读取),仅在新对话/程序启动时的DeepSeek-TUI 的启动钩子事件:session_start触发。一直在使用中,还算稳定。现在发现hook事件有时候是“观察员”,而不是“执行员”,正在修复中。
Closing as not planned in a v0.9.4 board hygiene pass.
This is an older-milestone epic / design wishlist / exploratory feature that is not on the live execution train. Leaving it open taxes agents the same way stale rebrand tickets did.
If this is still wanted for a current release: open a new narrow issue with acceptance criteria and a milestone that is actually shipping — do not reopen this blob.
Reopened — this is on the v0.9.4 milestone (current train). Closed by mistake during a hygiene pass aimed at older-milestone fossils only. Sorry for the noise.
Thanks @m8f1m8f1 for the report.
This issue is staying open for maintainer triage. CodeWhale gets better because people bring us real edge cases from real machines, providers, regions, and workflows.
If you can add a reproduction, logs, version output, screenshots, or the provider/model involved, that makes it much easier for us to verify and harvest the fix. Maintainers may comment /lgtmi to mark recurring issue reporters as approved so this intake note is skipped next time.
Closed as superseded: memory direction locked 2026-08-03 (native Markdown+FTS5 store survives; no backend remake — see PR #5147). #1062's [capacity] feature never existed; #689's CLI surface is gone.