Skip to content

fix(resource): preserve lock contention during auto-naming#3201

Open
huangruiteng wants to merge 1 commit into
volcengine:mainfrom
huangruiteng:codex/fix-resource-reservation-backpressure
Open

fix(resource): preserve lock contention during auto-naming#3201
huangruiteng wants to merge 1 commit into
volcengine:mainfrom
huangruiteng:codex/fix-resource-reservation-backpressure

Conversation

@huangruiteng

Copy link
Copy Markdown
Contributor

动机

修复 #3122 在当前 main 上仍存在的误导性错误。Embedding/Semantic circuit breaker 已会等待 retry_after 再 requeue,但自动命名会把 101 个候选 URI 的锁竞争全部吞掉,最后统一抛 FileExistsError;即使磁盘上没有同名路径,调用方也会误判为文件冲突。异步 understanding 路径还复制了一份相同逻辑。

改动思路

保留两种失败语义:

  • 候选路径确实全部存在:继续抛 FileExistsError
  • 至少一个不存在的候选仅因锁占用失败:抛可重试的 ResourceBusyError,并给出 auto_name_reservation_busy conflict type。

异步 understanding 路径不再维护第二份 100 次循环,改为调用 ResourceProcessor.reserve_unique_candidate()

关键代码

last_busy_error = None
for candidate in auto_named_candidates:
    if exists(candidate):
        continue
    try:
        return reserve(candidate)
    except ResourceBusyError as exc:
        last_busy_error = exc

if last_busy_error:
    raise ResourceBusyError(retryable=True, conflict_type="auto_name_reservation_busy")
raise FileExistsError(...)

复现与验证

python -m pytest \
  tests/unit/test_resource_reservation.py \
  tests/server/test_error_mapping.py \
  -q --disable-warnings --no-cov

结果:18 passed。新增覆盖包括全候选锁竞争、真实路径全部存在、以及跳过已存在名称后成功取得下一候选。Ruff check、compileall、git diff --check 均通过。

扩展运行的 resource_processor_mvresource_service_watch 暴露了未初始化 VikingFS/TaskTracker 的既有 fixture 漂移;在未修改的 origin/main 上用相同测试可稳定复现,因此未混入本 runtime PR,已独立记录后续。

风险与边界

本改动不改变候选命名顺序、最大尝试次数或锁获取策略,只修正耗尽后的异常分类并去除重复实现。调用方现在会收到结构化 409 conflict,应该按 retryable=true 退避重试,而不是创建更多编号副本或检查磁盘重名。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant