Skip to content

fix(task): sync Data JSON status when sweepTimedOutTasks marks task as failed (#5715)#5769

Open
zhangzhichaolove wants to merge 2 commits into
QuantumNous:mainfrom
zhangzhichaolove:fixtask
Open

fix(task): sync Data JSON status when sweepTimedOutTasks marks task as failed (#5715)#5769
zhangzhichaolove wants to merge 2 commits into
QuantumNous:mainfrom
zhangzhichaolove:fixtask

Conversation

@zhangzhichaolove

@zhangzhichaolove zhangzhichaolove commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

任务超时被 sweepTimedOutTasks 强制标记为失败时,仅更新了外层 task.Status = FAILURE,但 task.Data(存储上游原始 JSON 响应)中的 status 字段未同步修改,导致下游通过 TaskModel2Dto 查询任务时,外层状态为 FAILURE,而 data.status 仍为 IN_PROGRESS 或 QUEUED,产生矛盾。

修复方式:新增 patchDataStatus 辅助函数,在标记超时失败、写入数据库前,解析 task.Data JSON 并将其中顶层 status 字段覆写为 FAILURE。使用 map[string]json.RawMessage 保证其他字段保持原始字节不变,避免 float64 精度丢失。若 Data 为空、非 JSON 对象或不含 status 字段,则原样返回,不破坏现有数据。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix)
  • ✨ 新功能 (New feature)
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 Issues 与 PRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地编译通过(go build ./...),无新增编译错误。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

编译验证:

$ go build ./service/
# 无错误输出,编译通过

Summary by CodeRabbit

  • Bug Fixes
    • When timed-out tasks are marked as failed, their stored details now also reflect the failed status.
    • Task history and status displays should now stay consistent after timeout handling, reducing mismatches between summary and underlying task data.

…s failed (QuantumNous#5715)

When sweepTimedOutTasks force-marks a task as FAILURE after timeout, the
outer task.Status is updated but task.Data (upstream raw JSON) retains
its pre-timeout status (e.g. IN_PROGRESS, QUEUED). Downstream consumers
reading data.status see a contradictory state.

Add patchDataStatus helper to overwrite the status field inside Data JSON
before persisting, ensuring internal and external status are consistent.
@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Timed-out tasks now update both the task record and the embedded JSON payload so the stored status matches the forced failure state.

Changes

Timed-out task status sync

Layer / File(s) Summary
Failure transition patch
service/task_polling.go
sweepTimedOutTasks now patches task.Data to set the embedded "status" to failure, and patchDataStatus rewrites JSON object payloads while leaving invalid or non-object data unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hopped by timeout’s quiet den,
And matched the status now and then.
In JSON burrows, bright and neat,
Failure lands on both feet.
No more split task tales again!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the timeout-failure Data JSON status sync fix and matches the PR scope.
Linked Issues check ✅ Passed The change updates task.Data.status to FAILURE during timeout sweeps and preserves unchanged data cases, matching #5715.
Out of Scope Changes check ✅ Passed The patch is narrowly focused on syncing embedded task status during timeout handling and adds no unrelated changes.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@service/task_polling.go`:
- Line 72: The timeout handling in task polling only forces the top-level task
status to FAILURE, leaving provider-specific status fields stale for some
adapters. Update the task status patching in the polling flow so it also
overwrites the provider-derived status data used by adaptors like
ali/adaptor.go’s status serialization, or adjust those adaptors to prefer
task.Status whenever the row is terminal. Use the existing task.Data mutation
path in task_polling.go and the provider response status fields referenced by
the adaptors to keep client-visible status consistent.
- Around line 636-645: The patchDataStatus logic currently unmarshals task.Data
into a generic map and re-marshals the whole payload, which can change unrelated
numeric fields; update patchDataStatus to modify only the top-level status field
directly from the raw JSON instead of decoding into map[string]any. Keep the
existing behavior around detecting whether status exists, but implement the
replacement in a way that preserves the rest of the original bytes and avoids
touching other fields in task.Data.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 32f820ea-fb04-4966-bc70-628c98d36590

📥 Commits

Reviewing files that changed from the base of the PR and between 6c35e1e and 73e5ab9.

📒 Files selected for processing (1)
  • service/task_polling.go

Comment thread service/task_polling.go
Comment thread service/task_polling.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

任务超时被强制标记为失败后,下游查询还是处理中

1 participant