feat(continue): 将 /continue 默认改为原地恢复,并引入会话锁与占用确认#617
Merged
Conversation
…conflict) /continue N 默认改为「原地续」:接管原会话日志、后续轮次写回同一文件,取代旧的 镜像复制(supersedes b4356c7 的 mirror 方案),不再每次续接都 fork 新会话、日志增殖。 - 空闲会话 → 直接原地接管;被活进程占用 → 弹窗确认后才复制一份续。 - 每会话出生持锁(temp/model_responses/.locks/<logid>.lock),整进程共用一个心跳 线程每 5s touch mtime、30s 无心跳判死可接管;atexit 干净释放,崩溃/强杀靠超时兜底。 - 切走/新对话不再「快照+清空」(原 _snapshot_current_log 因 logid≠pid 实为死代码, 从未生成过快照),旧日志原样留作空闲会话,新对话铸新 logid。 - list_sessions 新增 exclude_log,修正 exclude_pid=getpid 失效导致当前会话出现在 自己列表里的问题。 - continue_cmd 仅新增函数,reset_conversation/restore/handle 未改动 → 其他前端 (IM/qt/streamlit 等)行为完全不变。 - 改动仅限 continue_cmd.py + tui_v3.py + tuiapp_v2.py;rewind/worldline 逻辑不在本 PR。
lsdefine
pushed a commit
that referenced
this pull request
Jul 23, 2026
…conflict) (#617) /continue N 默认改为「原地续」:接管原会话日志、后续轮次写回同一文件,取代旧的 镜像复制(supersedes b4356c7 的 mirror 方案),不再每次续接都 fork 新会话、日志增殖。 - 空闲会话 → 直接原地接管;被活进程占用 → 弹窗确认后才复制一份续。 - 每会话出生持锁(temp/model_responses/.locks/<logid>.lock),整进程共用一个心跳 线程每 5s touch mtime、30s 无心跳判死可接管;atexit 干净释放,崩溃/强杀靠超时兜底。 - 切走/新对话不再「快照+清空」(原 _snapshot_current_log 因 logid≠pid 实为死代码, 从未生成过快照),旧日志原样留作空闲会话,新对话铸新 logid。 - list_sessions 新增 exclude_log,修正 exclude_pid=getpid 失效导致当前会话出现在 自己列表里的问题。 - continue_cmd 仅新增函数,reset_conversation/restore/handle 未改动 → 其他前端 (IM/qt/streamlit 等)行为完全不变。 - 改动仅限 continue_cmd.py + tui_v3.py + tuiapp_v2.py;rewind/worldline 逻辑不在本 PR。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景与动机
现有
/continue N采用镜像复制策略(见 #612):恢复历史会话时,将源会话日志复制进当前进程日志,后续轮次写入该副本。此策略保证多个会话可并发恢复同一来源而互不冲突,但每次恢复都会派生一份新的会话副本,导致temp/model_responses/下的日志文件持续增殖。本 PR 将
/continue N的默认行为改为原地恢复(in-place restore):直接接管所选会话的日志文件,后续轮次写回该文件本身。如此在最常见的场景(恢复一个已结束的会话)下不再产生副本。方案
恢复时按目标会话的占用状态分流:
并发安全由每会话一把文件锁保证「同一时刻至多一个写者」。原镜像策略「多会话并发恢复同一来源」的能力予以保留,仅在目标确实被占用时需要一次确认。
实现
会话锁与存活判定
temp/model_responses/.locks/<logid>.lock。O_EXCL创建。atexit在正常退出时即时释放;进程被强制终止或崩溃时,由 30 秒超时兜底回收。/continue。移除快照机制
_snapshot_current_log依据 PID 拼接文件名,而会话日志实际以随机 logid 命名,二者永不匹配,该函数从未实际生成过快照(遗留死代码)。修正
list_sessionsexclude_log参数,按文件名排除调用方自身的当前会话。原exclude_pid因相同的 PID 与 logid 不匹配问题而失效,导致当前会话出现在自己的恢复列表中。影响范围与兼容性
frontends/continue_cmd.py、frontends/tui_v3.py、frontends/tuiapp_v2.py三个文件。continue_cmd.py中reset_conversation、restore、handle、handle_frontend_command等既有接口未作改动,新增逻辑均以新函数形式提供。dcapp、tgapp、stapp、qtapp 等其他前端行为不变。测试
py_compile与导入检查。continue_cmd的锁获取、存活判定、原地恢复、复制恢复、新建会话、过期接管、心跳刷新、抢锁竞态等场景均通过离线单元测试。