Skip to content

feat(session): distributed Redis-backed idle auto-commit scheduler - #6046

Merged
qin-ctx merged 8 commits into
volcengine:mainfrom
jiakun-lu:feat/session-idle-auto-commit
Oct 15, 2026
Merged

qin-ctx merged 8 commits into
volcengine:mainfrom
jiakun-lu:feat/session-idle-auto-commit

Conversation

@jiakun-lu

Copy link
Copy Markdown
Collaborator

Description

当前内核的 session 空闲超时自动提交依赖后台周期扫描全量 session 的 .meta.json,在 session 数量大时存在存储 IO 与性能问题。本 PR 新增一套可选的、基于 Redis 的分布式 expiry 调度能力,把"发现到期 session"从轮询扫描改为按分
钟桶精准调度,并保持默认行为(idle_backend=legacy)与现有提交语义完全不变。

Human Involvement

  • A human participated in the implementation or review loop

Related Issue

Type of Change

  • New feature (non-breaking change that adds functionality)
  • Performance improvement
  • Documentation update

Changes Made

  • 新增 openviking/scheduling/expiry/ 分布式 expiry 调度模块:业务接入 facade/registry、Redis 资源桶与分钟调度桶、publisher、callback consumer、临时 shard 租约、runtime/shard_runner 生命周期,以及一组原子 Lua 脚本。
  • 新增 openviking/service/session_expiry.py,在服务层完成纯 idle 检查后直接复用原 Session.commit_async,不在业务锁内做原子检查+提交,也不新增 idle 专用提交 API。
  • SessionService.commit_on_timeout 改为加载最新 session/meta 后在服务层检查,取代旧的"锁内 idle 检查 + idle 归档恢复"路径;idle_backend 可选 legacy(默认,行为不变)或 redis。
  • openviking/server/bootstrap.py 支持在 publisher_separate_process=true 时由 openviking-server 拉起/回收内部 publisher 子进程;新增 openviking_cli/expiry_bootstrap.py 与 expiry 配置项(service_name、
    shard_count、session_consumer_concurrency、redis.*)。
  • auto_commit_policy.py 为 idle 超时写入增加下限校验(MIN_IDLE_TIMEOUT_SECONDS),默认策略常量保持不变。
  • 文档:更新 docs/zh|en/guides/01-configuration.md、docs/zh|en/api/05-sessions.md。
  • 测试:新增 tests/scheduling/expiry/ 全套用例,以及 session 提交、bootstrap、policy、expiry publisher 相关测试。

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

本分支相关测试套件本地全绿:tests/scheduling/expiry/、tests/session/test_session_commit.py、tests/unit/test_server_bootstrap_expiry_publisher.py、tests/unit/session/test_auto_commit_policy.py、tests/server/ test_bootstrap.py。

说明:仓库 tests/server/test_api_sessions.py 中有 5 个失败用例,经核验为 main 上已有的旧账(默认策略常量在历史提交 98a0104aa 改过,断言未同步更新),与本 PR 改动无关。

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

Additional Notes

  • Redis 为可选能力,默认 idle_backend=legacy,不配置 Redis 时行为与现状一致。

jiakun-lu and others added 5 commits October 13, 2026 16:08
- Remove docs/zh/design session-idle-auto-commit scheduler design docs
- Rename tests/scheduling/expiry/test_config.py to test_expiry_config.py
  to avoid pytest module-name collision with tests/unit/crypto/test_config.py

Co-authored-by: TRAE CLI <traecli@bytedance.com>
…o-commit

# Conflicts:
#	Dockerfile
#	MANIFEST.in
#	openviking/server/bootstrap.py
#	pyproject.toml
#	setup.py
#	uv.lock

@qin-ctx qin-ctx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

用 Redis 到期索引替代全量 session 扫描,方向有价值;复用现有归档和队列流程也合理。

当前接入还未保持已有自动提交契约,并存在受支持 Python 版本下的运行问题。请先解决行内标出的 4 个阻塞问题再合入。另有 1 条关于额外元数据读写的非阻塞设计建议,请结合生命周期约束说明取舍。

Comment thread openviking/scheduling/expiry/consumer.py Outdated
Comment thread openviking/session/session.py
Comment thread openviking/service/session_service.py
Comment thread openviking/service/session_expiry.py
Comment thread openviking/service/session_service.py Outdated
@ZaynJarvis ZaynJarvis added the kernel Core server, runtime, storage, retrieval, SDK, and CLI. label Oct 15, 2026
@qin-ctx
qin-ctx merged commit 89fbcb9 into volcengine:main Oct 15, 2026
16 of 17 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel Core server, runtime, storage, retrieval, SDK, and CLI.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants