Skip to content

fix(queue): bound add_resource poison-message replay and dead-letter it - #5919

Closed
akushonkamen wants to merge 1 commit into
volcengine:mainfrom
akushonkamen:fix/5879-poison-message-delivery-cap
Closed

akushonkamen wants to merge 1 commit into
volcengine:mainfrom
akushonkamen:fix/5879-poison-message-delivery-cap

Conversation

@akushonkamen

Copy link
Copy Markdown
Contributor

Description

修复 add_resource 队列 at-least-once 流程中的毒消息无界重投:进程级原生崩溃(Windows 上 pdfium.dll BEX64)会绕过一切 Python 异常路径——没有异常可捕获、没有 finally 可清理——任务卡在 running、消息卡在 processing。Rust 端 RecoverStale 每次启动把同 message_id 无条件翻回 pending 重投,同一份 payload 再次触发崩溃,服务器陷入"启动即崩溃"死循环,重启或删除任务 JSON 文件都无法解除。

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

Fixes #5879

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

根因:

  • 原生崩溃绕过 Python 异常路径后,任务卡 running、消息卡 processing。
  • Rust 端 RecoverStale(crates/ragfs/src/plugins/queuefs/backend.rs:495-514)在 stale_sec <= 0 时无时间闸、也无投递计数,每次启动把同 message_id 无条件翻回 pending 重投。
  • Python 侧无任何有界重试兜底:tracker.create 对 running 任务直通(add_resource_processor.py:150-178 的 terminal 守卫不含 RUNNING);replay_result 为 None 即全量重解析(:180-183);唯一有界重排只覆盖锁交接路径(:124-131)。

修法(纯 Python 面,不动 Rust 后端):

  • 在 add_resource_processor._process 的 terminal 守卫后读取任务记录 meta 中持久化的 delivery_attempt 计数——QueueFS 后端没有 in-place 消息更新操作,meta 是随重启存活、且与 message 一一对应的持久账本。
  • 任何崩溃高危工作开始前,经 tracker.update_stage 先持久化自增该计数,进程被硬杀也能在下一次启动时读到。
  • 达到上限 MAX_ADD_RESOURCE_DELIVERY_ATTEMPTS = 3 时:清理 staged/prepared 产物、tracker.fail 标记任务 failed(含运维可行动的错误信息)、返回 ProcessResult.failed 使 NamedQueue.dequeue 无条件 ack(named_queue.py:245-248)永久移除毒消息(死信),并打 [AddResourceDeadLetter] 日志——服务器从此可在毒消息存在时正常启动。

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/storage/test_add_resource_poison_message.py(进程内 BaseException 崩溃模拟构造 processing -> RecoverStale -> 重投循环;子进程用例走真实 os._exit(1) 崩溃往返)。

红(main 未修改):

timeout 300 .venv/bin/python -m pytest tests/storage/test_add_resource_poison_message.py -q --no-cov

结果:2 failed。失败原因即无界重投本身:进程内用例 assert 4 == 3(第 4 次投递仍重跑崩溃解析、无 ack、任务卡 running),子进程用例 assert 4 == 3(4 次真实 os._exit(1) 崩溃、永不死信)。

绿(修复后):

  • 同命令 → 2 passed。
  • timeout 300 python -m pytest tests/storage -q → 24 failed / 940 passed / 6 skipped / 84 errors。
  • timeout 600 python -m pytest tests/storage tests/service -q → 43 failed / 1315 passed / 6 skipped / 85 errors。

与 main 基线(同命令 24F/938P/84E 与 43F/1313P/85E)的 FAILED+ERROR 清单逐字节 diff 一致(diff 为空):全部失败为环境缺 ragfs_python Rust 绑定的既有问题(ImportError: ragfs_python native library is not available,main 实跑确认),非本次引入;分支净增 2 passed 即新增测试。

ruff check openviking/storage/queuefs/add_resource_processor.py tests/storage/test_add_resource_poison_message.py
ruff format --check openviking/storage/queuefs/add_resource_processor.py tests/storage/test_add_resource_poison_message.py

结果:All checks passed! / 2 files already formatted。

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

Scope:本 PR 只覆盖 issue Expected #2(有界重投 + failed 标记)。Expected #1(解析子进程隔离,使原生崩溃不再杀死整个服务器进程)是独立的后续工作,commit message 中已注明 scope。死信后运维可在 [AddResourceDeadLetter] 日志定位问题文件,移除或转换该资源后服务器正常服务。

A native parser crash (pdfium.dll BEX64 on Windows) kills the whole server
process mid-parse. The interrupted task stays non-terminal and the durable
message stays 'processing'; on the next startup RecoverStale resets it to
'pending' with its payload unchanged (crates/ragfs
queuefs/backend.rs recover_stale has no delivery counter), so the identical
message_id is replayed — and crashes the server again — on every restart.
Neither restarting nor deleting the task JSON files clears the loop, and
nothing on the Python path counts deliveries: tracker.create() passes
through for tasks already stuck in running, and the only bounded requeue
covers the lock-handoff path (lock_handoff_retry).

Scope: issue Expected #2 (bounded replay + failed marking). Worker-process
isolation for parsing (Expected #1) is a separate follow-up.

Fix:
- Persist a per-task delivery_attempt counter in the task record's meta
  before any crash-prone work, so a hard death still counts on restart.
- After MAX_ADD_RESOURCE_DELIVERY_ATTEMPTS (3) deliveries, dead-letter the
  message (handler returns failed -> NamedQueue acks it for good), mark the
  task failed via tracker.fail with an actionable error, release staged
  artifacts, and log [AddResourceDeadLetter] for operators.

Tests (tests/storage/test_add_resource_poison_message.py):
- an in-process BaseException crash emulation constructing the
  processing -> RecoverStale -> re-deliver loop, asserting the parse runs
  exactly 3 times, the 4th delivery dead-letters (acked) and the task ends
  failed; red on main (parse ran a 4th time, no ack, task stuck running).
- a subprocess test performing real os._exit(1) crash round-trips, same
  assertions; red on main (4 crashes, never dead-lettered).

Fixes volcengine#5879

Signed-off-by: akushonkamen <akushonkamen@163.com>
@qin-ctx

qin-ctx commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

通过修复并发安全修复

@qin-ctx qin-ctx closed this Oct 13, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project Oct 13, 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

3 participants