Skip to content

fix(autostockpile): 复核详情页价格后重算购买决策#1604

Merged
MistEO merged 11 commits intov2from
fix/auto-stockpile
Mar 26, 2026
Merged

fix(autostockpile): 复核详情页价格后重算购买决策#1604
MistEO merged 11 commits intov2from
fix/auto-stockpile

Conversation

@single-ptilopsis
Copy link
Copy Markdown
Contributor

@single-ptilopsis single-ptilopsis commented Mar 25, 2026

summary:

  • 识别与选择共用一份决策状态,详情页 OCR 价格变化后会重新计算商品/数量决策,并按结果继续、重试或跳过。
  • AutoStockpile 按 Region 参数拆成 ValleyIV / Wuling 两套入口,去掉 anchor 依赖,补上复核、中继和命中计数清理的回退链路。
  • 票据和阈值解析更稳了:支持调度券万位小数,校验保留调度券配置上限,并细分 OCR 缺失时的 warn/skip 中止原因。
  • 本地化和维护文档同步更新,补齐价格修正提示、Region 说明和新的配置约束。

close #1577

Summary by Sourcery

优化 AutoStockpile 的区域/配置处理、决策流程与对账逻辑,并更新文档与本地化内容以匹配新行为。

Bug 修复:

  • 将缺失配额/库存单 OCR 以及数量为 0 / 配额不足的情况视为明确的警告/跳过中止原因,而不是在数据不完整的情况下继续执行。
  • 改进库存单金额解析,能够稳健处理大数值和带“万”单位的小数,同时强制遵守安全整数上限。

功能增强:

  • 从任务的 custom_action_param.Region 驱动区域解析,并通过物品映射校验替代硬编码锚点,同时注册单独的对账操作入口。
  • 引入共享决策状态和 computeDecision 辅助方法,使识别、选择与对账保持一致,并简化决策复用。
  • 细化中止原因语义,通过基于后缀的 fatal/warn/skip 辅助方法区分严重程度,并相应调整跳过/停止的路由与日志记录。
  • 为商品价目表新增受环境变量控制的测试价格改写辅助方法,以支持可复现的确定性测试。

文档:

  • 扩展 AutoStockpile 的中英文维护文档,说明任务选项/附加键、基于 Region 的决策节点、预留库存单前置条件,以及更新后的区域扩展步骤。
Original summary in English

Summary by Sourcery

Refine AutoStockpile region/config handling, decision flow, and reconciliation, and update documentation and localization to match the new behavior.

Bug Fixes:

  • Treat missing quota/stock bill OCR and zero/quota-insufficient cases as explicit warn/skip abort reasons instead of continuing with incomplete data.
  • Improve stock bill amount parsing to robustly handle large values and 10k-unit decimals while enforcing safe integer limits.

Enhancements:

  • Drive region resolution from task custom_action_param.Region with item-map validation instead of hard-coded anchors, and register a separate reconcile action entry point.
  • Introduce shared decision state and a computeDecision helper to keep recognition, selection, and reconciliation in sync and simplify decision reuse.
  • Refine abort reason semantics with suffix-based fatal/warn/skip helpers and adjust skip/stop routing and logging accordingly.
  • Add an env-gated test-price rewrite helper for goods price lists to support deterministic testing.

Documentation:

  • Expand AutoStockpile maintenance docs in English and Chinese to describe task options/attach keys, Region-based decision nodes, reserve stock bill prerequisites, and updated region extension steps.

Summary by Sourcery

改进 AutoStockpile 的区域处理、共享决策状态以及决策对账逻辑,以便在价格被更正时能够做出响应,同时加强对进货单与配额的解析,并更新相关文档与本地化内容。

Bug 修复:

  • 将缺失或无法读取的配额和进货单 OCR 视为明确的 Warning/Skip 终止原因,而不是在数据不完整的情况下继续执行。
  • 更健壮地解析进货单金额,包括大额数值和以万为单位的小数,同时强制使用安全整数范围。

增强功能:

  • 从任务的 custom_action_param.Region 驱动区域解析,并配合商品映射校验,替换硬编码锚点;在识别、选择和对账流程之间复用共享的决策计算辅助方法。
  • 引入共享的内存决策状态以及专用的 ReconcileDecision 动作,当用户更正商品价格时重新计算选择和数量,并据此在继续、重试或跳过路径之间进行路由。
  • 通过标准化的 Fatal/Warn/Skip 后缀对终止原因按严重程度分类,并更新跳过/停止的路由、日志记录以及 relay 节点覆盖逻辑,包括新增“decision-ready” relay 节点,以及在跳过或重试时清理 relay/selection 节点。
  • 为已识别商品新增受环境变量控制的测试价格重写机制,以支持选择逻辑的可重复性测试。

文档:

  • 扩展英文和中文的 AutoStockpile 维护文档,描述任务选项/附加键、基于 Region 的决策节点、预留进货单前置条件,以及更新后的区域扩展与校验流程。
Original summary in English

Summary by Sourcery

Refine AutoStockpile region handling, shared decision state, and decision reconciliation to react to price corrections, while tightening stock bill and quota parsing and updating related documentation and localization.

Bug Fixes:

  • Treat missing or unreadable quota and stock bill OCR as explicit warning/skip abort reasons instead of continuing with incomplete data.
  • Parse stock bill amounts more robustly, including large values and 10k-unit decimals, while enforcing safe integer bounds.

Enhancements:

  • Drive region resolution from task custom_action_param.Region with item-map validation, replacing hard-coded anchors, and reuse a shared decision computation helper across recognition, selection, and reconciliation.
  • Introduce a shared in-memory decision state and a dedicated ReconcileDecision action that recomputes selection and quantity when the user corrects item prices, routing between proceed, retry, or skip paths accordingly.
  • Classify abort reasons by severity via standardized Fatal/Warn/Skip suffixes and update skip/stop routing, logging, and relay node overrides, including a new decision-ready relay node and cleanup of relay/selection nodes when skipping or retrying.
  • Add an env-gated test-price rewrite mechanism for recognized goods to support deterministic testing of selection logic.

Documentation:

  • Extend the AutoStockpile maintenance docs in English and Chinese to describe task options/attach keys, Region-based decision nodes, reserve stock bill prerequisites, and updated region expansion and validation flows.

- 额度 OCR 失败时以告警原因中止并走 skip

- 修正调度券 OCR 对小数和万单位的解析

- 收紧保留调度券与价位阈值的配置校验
- 缓存当前选品与数量决策,支持按详情页价格重新计算
- Pipeline 增加复核重试、中继和回退重选链路
- 补充价格修正提示文案,并加入识别阶段测试价格覆盖
- 识别与选择阶段统一读取 Region 参数
- 为 ValleyIV 与 Wuling 拆分独立决策入口
- 调整购买前稳定检测与滑动回退链路
- 补充全局开关与 attach 键说明
- 更正新增地区时的 Region 配置要求
- 更新阈值校验与保留调度券前置条件
Copilot AI review requested due to automatic review settings March 25, 2026 17:24
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - 我在这里给出了一些总体反馈:

  • 新增的全局 decisionState(位于 state.go)在整个进程中是共享的;请考虑在多个 AutoStockpile 任务并发或交错运行时,它的行为会如何,并确保在所有终止路径上都能可靠地清理该状态,以避免不同运行之间的决策信息发生泄漏。
  • 新增的 AbortReason.isFatal/isWarn/isSkip 辅助方法完全依赖字符串后缀来判断;更安全的做法可能是集中校验后缀的正确性,或者改用显式分类机制(例如使用 map),从而避免未来新增原因时可以悄然绕过预期的分流逻辑。
给 AI 代理的提示
请根据本次代码评审中的评论进行修改:

## 综合评论
- 新增的全局 `decisionState`(位于 `state.go`)在整个进程中是共享的;请考虑在多个 AutoStockpile 任务并发或交错运行时,它的行为会如何,并确保在所有终止路径上都能可靠地清理该状态,以避免不同运行之间的决策信息发生泄漏。
- 新增的 `AbortReason.isFatal/isWarn/isSkip` 辅助方法完全依赖字符串后缀来判断;更安全的做法可能是集中校验后缀的正确性,或者改用显式分类机制(例如使用 map),从而避免未来新增原因时可以悄然绕过预期的分流逻辑。

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English

Hey - I've left some high level feedback:

  • The new global decisionState in state.go is shared process-wide; consider how this behaves if multiple AutoStockpile tasks can run concurrently or interleave, and ensure the state is reliably cleared on all terminal paths to avoid leaking decisions between runs.
  • The new AbortReason.isFatal/isWarn/isSkip helpers rely purely on string suffixes; it might be safer to either validate suffix correctness centrally or move to an explicit classification (e.g., a map) so adding new reasons in the future can’t silently bypass the intended routing logic.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new global `decisionState` in `state.go` is shared process-wide; consider how this behaves if multiple AutoStockpile tasks can run concurrently or interleave, and ensure the state is reliably cleared on all terminal paths to avoid leaking decisions between runs.
- The new `AbortReason.isFatal/isWarn/isSkip` helpers rely purely on string suffixes; it might be safer to either validate suffix correctness centrally or move to an explicit classification (e.g., a map) so adding new reasons in the future can’t silently bypass the intended routing logic.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@single-ptilopsis single-ptilopsis marked this pull request as draft March 25, 2026 17:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

该 PR 旨在改进 AutoStockpile 的“识别 + 购买决策”链路:将识别/选择共用同一份决策状态,并在详情页 OCR 价格变化后重新计算购买决策,通过 Pipeline 回退链路实现继续/重试/跳过;同时拆分地区入口、增强调度券与阈值解析健壮性,并同步更新维护文档与多语言文案。

Changes:

  • Pipeline:按 Region 拆分 ValleyIV/Wuling 决策入口,新增详情页价格复核与重试/回退链路,并加入命中计数清理节点。
  • Go:引入共享决策状态与“复核后重算决策”自定义 Action;Region 解析改为读取节点 custom_action_param;阈值/调度券解析更严格、更稳健。
  • 文档与本地化:补齐 Region/attach 键说明、价格修正提示与新的配置约束,多语言文案同步更新。

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
docs/zh_cn/developers/auto-stockpile-maintain.md 更新中文维护文档:任务选项、attach 键、Region 扩展与注意事项说明
docs/en_us/developers/auto-stockpile-maintain.md 更新英文维护文档,与中文内容对齐
assets/resource/pipeline/AutoStockpile/Task.json 新增/重构地区决策节点、详情页价格复核与重试链路,调整部分节点命名与 next
assets/resource/pipeline/AutoStockpile/Main.json 调整入口/地区节点与 anchor,用于地区化决策节点路由
assets/locales/go-service/zh_tw.json 新增价格修正文案与细分 abort reason 文案键
assets/locales/go-service/zh_cn.json 同上(简中)
assets/locales/go-service/ko_kr.json 同上(韩语)
assets/locales/go-service/ja_jp.json 同上(日语)
assets/locales/go-service/en_us.json 同上(英文)
agent/go-service/autostockpile/types.go 细分 AbortReason(Warn/Skip/Fatal)并通过后缀判断路由策略
agent/go-service/autostockpile/thresholds.go 调整价格阈值 override 解析路径
agent/go-service/autostockpile/stockbill.go 调度券 OCR 解析增强:支持“万”单位小数并增加溢出保护
agent/go-service/autostockpile/state.go 新增共享 DecisionState(识别产出、选择/复核消费)
agent/go-service/autostockpile/selector.go 选择阶段使用统一 computeDecision,并写入 DecisionState 供复核使用
agent/go-service/autostockpile/register.go 注册新的自定义 Action:AutoStockpile.ReconcileDecision
agent/go-service/autostockpile/reconcile.go 新增详情页价格复核后重算决策逻辑与对应 Pipeline override
agent/go-service/autostockpile/recognition.go Region 解析改为读节点参数;溢出/额度解析更严格;加入可选测试价格重写
agent/go-service/autostockpile/options.go 保留调度券输入解析改为严格正整数并增加上限校验
agent/go-service/autostockpile/decision.go 抽取 computeDecision 复用选择与数量决策计算

@single-ptilopsis single-ptilopsis marked this pull request as ready for review March 26, 2026 01:50
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - 我给出了一些整体性的反馈:

  • applyTestPricesIfEnabled 辅助函数在没有固定种子的情况下使用了 rand.Shuffle,这削弱了“测试可重复、确定性”的目标;建议在测试环境变量被设置时,为 math/rand 使用一个固定常量种子,或者以确定性的方式生成选择结果(例如通过排序后的索引)。
  • AbortReason.isFatal/isWarn/isSkip 仅依赖字符串后缀判断,这在新增原因类型时很容易被破坏;你可能需要通过健全性检查来强制执行后缀约定(例如在 init() 中遍历 knownAbortReasons),以便在引入命名不规范的原因时快速失败。
用于 AI Agent 的提示词
Please address the comments from this code review:

## Overall Comments
- The `applyTestPricesIfEnabled` helper uses `rand.Shuffle` without a fixed seed, which undermines the goal of deterministic testing; consider seeding `math/rand` with a constant or deriving the selection deterministically (e.g., via sorted indices) when the test env var is set.
- `AbortReason.isFatal/isWarn/isSkip` rely solely on string suffixes, which is easy to break when adding new reasons; you might want to enforce suffix conventions via a sanity check (e.g., in an init() over `knownAbortReasons`) to fail fast if an incorrectly named reason is introduced.

Sourcery 对开源项目免费 —— 如果你觉得我们的代码评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码评审。
Original comment in English

Hey - I've left some high level feedback:

  • The applyTestPricesIfEnabled helper uses rand.Shuffle without a fixed seed, which undermines the goal of deterministic testing; consider seeding math/rand with a constant or deriving the selection deterministically (e.g., via sorted indices) when the test env var is set.
  • AbortReason.isFatal/isWarn/isSkip rely solely on string suffixes, which is easy to break when adding new reasons; you might want to enforce suffix conventions via a sanity check (e.g., in an init() over knownAbortReasons) to fail fast if an incorrectly named reason is introduced.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `applyTestPricesIfEnabled` helper uses `rand.Shuffle` without a fixed seed, which undermines the goal of deterministic testing; consider seeding `math/rand` with a constant or deriving the selection deterministically (e.g., via sorted indices) when the test env var is set.
- `AbortReason.isFatal/isWarn/isSkip` rely solely on string suffixes, which is easy to break when adding new reasons; you might want to enforce suffix conventions via a sanity check (e.g., in an init() over `knownAbortReasons`) to fail fast if an incorrectly named reason is introduced.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@MistEO MistEO merged commit 1706e45 into v2 Mar 26, 2026
18 checks passed
@MistEO MistEO deleted the fix/auto-stockpile branch March 26, 2026 09:17
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.

自动囤货价格识别错误

3 participants