Skip to content

refactor(tasks): converge task/work store contract - #6136

Merged
qin-ctx merged 5 commits into
volcengine:mainfrom
runyunzhou:refactor/task-work-store
Oct 16, 2026
Merged

qin-ctx merged 5 commits into
volcengine:mainfrom
runyunzhou:refactor/task-work-store

Conversation

@runyunzhou

Copy link
Copy Markdown
Collaborator

Description

重构 Task 与 QueueFS Work 的跟踪机制,统一收敛到与存储实现无关的
TaskWorkStore 契约。

本次改动明确拆分了持久化 Task 状态、Work 生命周期协调、QueueFS delivery
处理和进程内取消句柄。File Store 持久化 Task,并在服务重启时根据 QueueFS
恢复尚未完成的 Work;同时统一 Task 终态聚合、队列状态统计和取消处理。

Human Involvement

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

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

  • 新增与存储实现无关的 Task/Work 领域模型和 TaskWorkStore 语义接口,覆盖状态迁移、取消、等待、清理、统计和恢复。
  • 重构 File Store,采用 copy-on-write mutation、按记录加锁和有界 I/O;Task 持久化到文件,未完成 Work 由 QueueFS 快照恢复。
  • 将 QueueFS enqueue、process、requeue、cancel、clear 和终态聚合接入 Store 管理的 Work 状态。
  • 在队列 payload 中独立保留 Task owner,避免业务内容 owner 与 Task owner 混淆。
  • 修复写盘取消后的缓存发布、删除时锁内重新校验、clear 后 Work 悬挂以及 requeue 执行耗时累计错误。
  • 修复 ExternalTask requeue 丢失 _task_work_id 的问题,确保 replacement delivery 沿用同一个逻辑 Work,不会遗留 pending Work 导致 Task 卡在 running。
  • 按 CONTRIBUTING.md 更新并精简测试:保留生命周期、持久化、取消、恢复、隔离和锁释放等公开契约,删除缓存结构、文件写次数和旧 TaskWorkIndex 测试双身相关断言。

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

已执行:

  • Task/Work、QueueFS、Session、Memory Compile、Semantic、Admin、Bot 和 AGFS restore 相关回归:766 passed。
  • ExternalTask 完成、取消、失败、重启和重试的参数化回归:50 passed。
  • Semantic 迁移聚焦测试:26 passed。
  • Task/Work 与 content-write 聚焦测试:54 passed。
  • Memory Compile 与 Session 测试:83 passed。
  • Ruff、Python 编译检查和 git diff --check 均通过。
  • 使用隔离配置和端口启动真实 OpenViking 服务,验证并发异步导入、事件持久化、用户隔离、取消、正常重启、SIGKILL 恢复和同步等待。

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

  • File Store 中的 Work 状态是进程内状态,并通过 QueueFS 恢复,不提供跨节点一致性;分布式部署应使用共享的持久化 TaskWorkStore。

@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.

统一 Task/Work 状态归属的方向合理,但当前实现会让同步内容写入等路径等待自身的 Inline Work,导致请求无法正常完成;每次 Work 状态变化还会复制整个任务的全部 Work,引入明显的二次方开销。这两处回归需要在合并前解决。另有清理过程重复读取任务文件、终态错误明细失去上限的问题,详见 inline comments。

Comment thread openviking/service/task_tracker.py Resolved
Comment thread openviking/service/task_store.py Resolved
Comment thread openviking/service/task_store.py Resolved
Comment thread openviking/service/task_store.py Resolved
@runyunzhou
runyunzhou force-pushed the refactor/task-work-store branch from 319636f to ffde5d6 Compare October 15, 2026 16:27
@runyunzhou
runyunzhou requested a review from qin-ctx October 15, 2026 16:31
@ZaynJarvis ZaynJarvis added the kernel Core server, runtime, storage, retrieval, SDK, and CLI. label Oct 16, 2026

@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.

本轮已验证:Work 整集合深拷贝、清理重复读取及终态错误明细上限三个问题已修复。同步等待的修复仍不完整:真实内容写入会创建锁协调消息,调用方等待协调消息,而协调消息又等待调用方的 Inline Work 结束,仍会持续重新入队。另有消费阶段为状态检查反复计算全部 Work 耗时的非阻塞性能问题。

Comment thread openviking/service/task_store.py Resolved
@runyunzhou
runyunzhou requested a review from qin-ctx October 16, 2026 07:37

@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.

统一 Task/Work 状态归属的方向合理。顶层内容写入的循环等待和消费阶段全量状态读取问题已修复,但快照恢复的独立入口仍会等待自身的 Inline Work,导致恢复重建任务无法结束、文件锁无法正常释放,需要在合并前修复。另外,删除用户任务时两层重复全量读取任务文件,作为非阻塞问题列出。

Comment thread openviking/service/task_tracker.py Resolved
@runyunzhou
runyunzhou requested a review from qin-ctx October 16, 2026 09:42
@qin-ctx
qin-ctx merged commit 013e988 into volcengine:main Oct 16, 2026
7 of 9 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project Oct 16, 2026

@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.

补充一项在数据面 API 回归中复现的 Session commit 问题,详见行级评论。

Comment on lines +53 to +54
if not metadata.account_id or not metadata.user_id:
raise TaskWorkRejected(f"Task {metadata.task_id} work is missing owner metadata")

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.

[Bug] (blocking) 普通 Session commit 会被新的入队校验拒绝,返回 HTTP 500

创建会话并写入待归档消息后,正常调用 POST /api/v1/sessions/{session_id}/commit 会在这里失败,服务端报 TaskWorkRejected: work is missing owner metadata,无法提交后续记忆抽取任务。

Session.commit 为本次归档生成新的 task_id,但入队前没有绑定对应的 TaskContext。prepare_task_payload() 只从 task_id 匹配的上下文读取任务归属,因此这里得到的 account_id、user_id 都为空。原来的 TaskWorkIndex.register() 允许先登记这条 Work,本 PR 新增的严格校验则直接拒绝它,而 Session 入口没有同步适配。

同一路径还未满足“Task 必须先存在”的新要求:本 PR 最终 Head 的 session.py:1650–1661 仍然先 enqueue()、后 get_task_tracker().create();新的入队流程却会先调用 register_work(),Task 不存在时也会拒绝。因此只补 owner 字段仍不足以让这条入口满足新契约。

在 v0.5.1 候选提交 6bd89a36be81 的真实 HTTP 回归及逐项复跑中均已复现,53 个 Session、归档、记忆和 Task 相关 API 用例都在这个前置 commit 调用收到 500。已核对该缺口在本 PR 最终 Head 8f6c8ddbdca4 中就存在,不依赖后续 #6175 对任务登记锁范围的调整。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

已在 #6258 中修复

hezhang-1216 pushed a commit that referenced this pull request Oct 29, 2026
* refactor(tasks): converge task/work store contract

* fix(tasks): avoid cyclic waits and full task reads

* refactor(tasks): return store operation results

* fix(tasks): prevent task deletion and inline work regressions

* test(tasks): consolidate task lifecycle coverage

---------

Co-authored-by: qin-ctx <qinhaojie.exe@bytedance.com>
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