Skip to content

feat(session): 返回 memory diff URI#2789

Merged
chenjw merged 1 commit into
mainfrom
feat/session-memory-diff-uri
Jun 23, 2026
Merged

feat(session): 返回 memory diff URI#2789
chenjw merged 1 commit into
mainfrom
feat/session-memory-diff-uri

Conversation

@qin-ctx

@qin-ctx qin-ctx commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Description

本 PR 调整 session commit 的 memory_diff_uri 暴露时机:POST /sessions/{id}/commit 的即时响应仍只表示任务已 accepted,不返回 memory_diff_uri;后台 Phase 2 中长记忆抽取完成后,会先检查 memory_diff.json 是否实际存在,存在时才在 task result 返回 memory_diff_uri,方便调用方确认本次归档对应的记忆 diff 文件。

长记忆抽取阶段如果没有生成任何 memory operations,也会由 SessionCompressorV2 写入空结构的 memory_diff.json,避免“长记忆抽取已完成但没有 diff 文件”的状态。

示例:

{
  "status": "accepted",
  "task_id": "uuid-xxx",
  "archive_uri": "viking://user/alice/sessions/a1b2c3d4/history/archive_001",
  "archived": true
}

任务完成后:

{
  "status": "completed",
  "result": {
    "session_id": "a1b2c3d4",
    "archive_uri": "viking://user/alice/sessions/a1b2c3d4/history/archive_001",
    "memory_diff_uri": "viking://user/alice/sessions/a1b2c3d4/history/archive_001/memory_diff.json",
    "memories_extracted": {
      "memory_write": 1
    }
  }
}

Related Issue

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • 调整 session.commit 即时响应:不再提前返回 memory_diff_uri
  • 在长记忆抽取成功完成后,基于 VikingFS.exists() 确认 memory_diff.json 存在,再将 memory_diff_uri 写入 task result;execution-only、跳过长记忆抽取或文件未产出时不返回该字段。
  • 将无 operations 的空 memory_diff.json 生成收敛到 SessionCompressorV2.extract_long_term_memories 内部,并同步中英文文档与测试。

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

已运行:

  • python -m py_compile openviking/session/session.py openviking/session/compressor_v2.py
  • git diff --check -- openviking/session/session.py openviking/session/compressor_v2.py tests/session/test_session_commit.py tests/server/test_api_sessions.py docs/en/api/05-sessions.md docs/zh/api/05-sessions.md
  • env UV_CACHE_DIR=/private/tmp/openviking-uv-cache uv run python -m pytest tests/server/test_api_sessions.py::test_compress_session

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

不适用

Additional Notes

memory_diff_uri 现在表示“长记忆抽取阶段已完成,并且对应 diff 文件已经实际存在”。该字段不会出现在 commit accepted 响应中,也不会在没有调度长记忆抽取或未产出 diff 文件的 task result 中返回。

@qin-ctx qin-ctx force-pushed the feat/session-memory-diff-uri branch from 8a80b2b to a744eae Compare June 23, 2026 12:32
@chenjw chenjw merged commit 5f8547a into main Jun 23, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project Jun 23, 2026
@chenjw chenjw deleted the feat/session-memory-diff-uri branch June 23, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants