feat(session): add turn-aware retention and reliable archive recovery - #3380
Merged
Conversation
# Conflicts: # openviking/storage/transaction/lock_context.py
yeshion23333
marked this pull request as ready for review
July 23, 2026 06:39
qin-ctx
requested changes
Jul 23, 2026
qin-ctx
left a comment
Collaborator
There was a problem hiding this comment.
Turn-aware retention 与归档恢复的总体方向合理,但当前仍有两处会破坏核心上下文保证的阻塞问题:核心预算规划可能丢掉最新 final Step,VikingBot 的最终二次裁剪也可能重新丢掉 user anchor。请修复 inline comments 中的两个边界场景后再合并。
qin-ctx
approved these changes
Jul 24, 2026
ZaynJarvis
added a commit
that referenced
this pull request
Jul 24, 2026
Rebase onto main (#3380 turn-aware retention) changed archive refs to carry an archive_id; update the test mock's _list_archive_refs return so the missing pending archive still routes through _get_uncovered_archive_messages and is skipped (not raised).
baojun-zhang
pushed a commit
that referenced
this pull request
Jul 24, 2026
* fix(kernel): stop conflating storage failures with not-found Sweep findings: A-03, A-07, A-11, A-12, B-07. Preserve storage and parse failures instead of reporting missing or empty state. * fix(review): restore archive failure handling Addresses blocking review finding on #3417. * fix(review): terminalize corrupt archive records Addresses blocking review finding on #3417. * test: adapt pending-archive-skip test to refactored archive scan Rebase onto main (#3380 turn-aware retention) changed archive refs to carry an archive_id; update the test mock's _list_archive_refs return so the missing pending archive still routes through _get_uncovered_archive_messages and is skipped (not raised).
21 tasks
nexw
pushed a commit
to nexw/OpenViking
that referenced
this pull request
Jul 29, 2026
…volcengine#3380) * 优化OpenViking的 session compact逻辑,active message 改为turn,压缩 assistant,保留完整user。 详见RFC:volcengine#3330 * Vikingbot 使用 ov turn session * fix pr comment * 更新文档 * fix pr issue
nexw
pushed a commit
to nexw/OpenViking
that referenced
this pull request
Jul 29, 2026
…ine#3417) * fix(kernel): stop conflating storage failures with not-found Sweep findings: A-03, A-07, A-11, A-12, B-07. Preserve storage and parse failures instead of reporting missing or empty state. * fix(review): restore archive failure handling Addresses blocking review finding on volcengine#3417. * fix(review): terminalize corrupt archive records Addresses blocking review finding on volcengine#3417. * test: adapt pending-archive-skip test to refactored archive scan Rebase onto main (volcengine#3380 turn-aware retention) changed archive refs to carry an archive_id; update the test mock's _list_archive_refs return so the missing pending archive still routes through _get_uncovered_archive_messages and is skipped (not raised).
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.
背景与目标
本 PR 落地 RFC #3330:
原有
keep_recent_count按物理 Message 数量切分。在工具密集型对话中,一次 User 请求可能展开成多条 assistant/tool 消息,导致 active context 从 assistant 开始、call/result 被拆开,或单个长 Turn 长期占满上下文。同时,异步 commit 期间的 pending/failed archive 还存在原始消息暂时或永久不可见的风险。本次改动目标:
assistant text + tool calls + results作为原子 Step;latest_archive_overview + messages的公开返回结构兼容。改动概览
commit_count与 markerget_session_context(token_budget)控制本次读取1. Turn-aware retention
turn_id、message_kind、source_message_ids;旧消息仍可通过 role/parts 推断。turn_budget模式及keep_recent_turn_count、retained_message_token_budget、min_raw_tail_steps参数。tool-results/。2. Checkpoint 与 Working Memory
message_kind=checkpoint的ContextPart,连接归档前缀与保留的 raw tail。3. Archive 状态与恢复
commit_count仅保留为统计信息。latest completed overview + uncovered pending/failed raw + root messages.jsonl组装,并按 message ID stable dedup。covered_failed_archives将其 roll forward 到新 overview。working_memory=false的已完成 archive 保持归档,不把 raw 放回 active;旧.donemarker 继续兼容。4. API、SDK 与 VikingBot 接入
retention_mode=turn_budget时继续沿用keep_recent_count,现有接入无需修改。get_session_context(token_budget)独立控制本次overview + messages返回预算;retained_message_token_budget只用于 commit 阶段。auto_memory_search;默认保留 3 个 Turn、6000 retained tokens、1 个 raw tail Step。commit_keep_recent_count继续保留,避免已有配置解析失败。行为与兼容性
Human Involvement
Related
Type of Change
Testing
git diff --check通过。Checklist
Additional Notes