Repository navigation
[Historical AI validation] SG duplicate execution leaves claimed command unresolved #482
Description
Historical SG rebalance claim deduplication bug
- Repository:
QuantStrategyLab/LongBridgePlatform - Source ref:
ai-history-sg-claim-dedup-20260915 - Baseline revision:
26844fa9b909e98e867acf4c50120b90acc6c792 - Execution mode: historical offline sandbox only
Problem
In the SG rebalance path, a due durable command is claimed before execution. In
the same session, the service can then find evidence in the execution marker or
prior report that the signal was already executed. The service skips duplicate
execution, but the current claim remains in CLAIMED, so later processing sees a
stale in-flight command and is blocked.
The historical evidence is:
- The affected cycle is SG 9/11, with signal 9/10 and effective date 9/11.
- The command was claimed once (
cmd-3915a5fb16264cb4eab5cd4a970de069). - Same-cycle evidence says the duplicate was skipped because the signal dated 9/10
for the 9/11 execution session had already been recorded. - The observed report had
action_done=false,
broker_submission_done=false, andorders=0. - The later unresolved state is caused by the claimed command remaining
durable, not by evidence of a broker submission.
Requested repair
Inspect the existing claim, marker, prior-report, and terminal-state flow and
propose the smallest repair that closes the current claim when duplicate
execution is positively confirmed and no new submission is made. Preserve the
existing duplicate-execution protection.
Do not cancel or otherwise terminally resolve a claim when marker/report
reading fails, identity cannot be established, evidence is ambiguous, or the
broker outcome is unknown. Those cases must remain fail-closed and retain the
claim for reconciliation.
The repair and regression coverage may modify only:
application/rebalance_service.pytests/test_rebalance_service.py
The regression must be deterministic, offline, and use historical fixtures. It
must cover both the positively confirmed duplicate path and a negative path in
which marker/report evidence is unavailable or unreadable; the latter must
remain CLAIMED with zero orders/submissions. Do not perform live orders,
deployments, remote state changes, or workflow dispatch.
Required response
Return the proposed patch and tests for human review, with the exact files
changed, the evidence used, and the test command/result. If the source or
evidence needed to establish a safe terminal state is absent, stop and report
the gap instead of guessing.
This is an authorized historical research task, not an active production incident. The bridge may create one draft PR against the historical sandbox branch after its isolated tests pass. Do not merge, deploy, or modify the production main branch.
Previous attempt diagnostic feedback (append-only; preserve the issue body above)
Use the fixed repository state only: QuantStrategyLab/LongBridgePlatform, branch ai-history-sg-claim-dedup-20260915, baseline commit 26844fa9b909e98e867acf4c50120b90acc6c792. The allowed write set remains exactly application/rebalance_service.py and tests/test_rebalance_service.py; do not modify other files, prompts, frameworks, grants, claims, deployment, or trading behavior.
The prior generated test was diagnosed offline with these concrete failures: CommandStore.current_state was always CLAIMED; enqueue returned the same already-due command, so the positive path had duplicate due work; the frozen plan dates were inconsistent; and the append_event return value of None was not verified. These are diagnostic facts, not a request to copy the previous human repair.
Regenerate and implement the smallest fix in the two allowed files against the supplied baseline. The positive test must exercise the real path from an initially QUEUED command to one claim, use an independent future command for the new signal, and use the frozen plan date transition 2026-09-10 to 2026-09-11 with the correct marker key. It must verify the actual marker/prior-report reads, final state CANCELLED, exactly one claim, and zero orders.
Keep negative cases independent and verify they actually read the evidence, remain CLAIMED, emit no close event, and submit zero orders. Cover marker-missing/prior-report-present behavior. If evidence reads fail, or append_event returns None, do not claim closure; preserve the unresolved/claimed state and emit the existing warning behavior without inventing a new return protocol.
Return targeted edits against the supplied baseline. The bridge, not this model session, applies the patch and runs the pinned offline tests; do not claim test execution or results yourself. Do not claim AI success from a human patch, do not call another model, do not dispatch production work, and do not merge or publish.
Activity
quantcrossrepoautomation commentedon Sep 15, 2026
{"status":"blocked","reason":"无法访问本地 checkout:sandbox 初始化失败(RTM_NEWADDR: Operation not permitted),因此无法可靠返回两份完整文件内容或执行 pinned offline tests。未修改任何文件、未执行测试、未进行部署或 broker 操作。"}
quantcrossrepoautomation commentedon Sep 15, 2026
Codex Audit
Codex execution failed with exit code
1.No files were pushed. Check the bridge workflow logs for details.
quantcrossrepoautomation commentedon Sep 15, 2026
结论:问题已在提供的快照中得到确认,属于“已成功认领但重复证据分支未收敛命令状态”的状态机缺陷。它不会直接证明重复下单,但会让后续周期持续被旧的
CLAIMED命令阻塞。关键证据:
run_strategy()先对 due command 调用claim_due(),设置live_command_claimed=True。execution_state_store.has_marker()和has_prior_execution_report()。execution_already_recorded分支,构造action_done=False的结果。execution_command_store.append_event(),因此当前命令仍保持CLAIMED。风险判断:High。主要影响是持续阻塞后续 durable live commands;现有保护逻辑不会因此允许重复下单。
建议的最小修复方向:
CANCELLED,并记录明确原因duplicate_execution_confirmed。expected_previous_state=CLAIMED,避免并发状态覆盖。has_marker()或 prior-report 读取失败、证据无法区分普通 claim 与已完成执行、身份不匹配、存在 pending/unknown order 时,不写终态,继续保持CLAIMED。CLAIMED;CLAIMED,零订单、零提交。当前无法安全给出具体补丁或测试结果:本次明确是 review-only,且快照没有提供
ExecutionCommandStore的完整终态语义,无法确认哪个终态最准确,也不能声称测试已执行。ಿನ್ನೆPigbibi commentedon Sep 15, 2026
固定历史案例的依赖源码补充
来源:LongBridgePlatform
26844fa9b909e98e867acf4c50120b90acc6c792的uv.lock将 QuantPlatformKit 固定在d51bb79dea8dc5773384d21b06e726620276558c。以下逐段复制该依赖提交的原始源码;不是当前 main,不含修复版本,不授予生产或交易权限。补充范围仅为持久命令的状态、认领与事件存储,以及既有 execution report 去重读取;写入范围仍仅限原批准的两个 LongBridge 文件。
src/quant_platform_kit/common/execution_commands.py—ExecutionCommandState原始源码 L35–L44
src/quant_platform_kit/common/execution_commands.py—TERMINAL_EXECUTION_COMMAND_STATES原始源码 L47–L53
src/quant_platform_kit/common/execution_commands.py—_ALLOWED_TRANSITIONS原始源码 L55–L104
src/quant_platform_kit/common/execution_commands.py—validate_execution_command_transition原始源码 L146–L153
src/quant_platform_kit/common/execution_commands.py—is_due_on原始源码 L214–L215
src/quant_platform_kit/common/execution_commands.py—ExecutionCommandStore原始源码 L323–L479
src/quant_platform_kit/common/execution_state.py—has_prior_execution_report原始源码 L316–L368
src/quant_platform_kit/common/execution_state.py—_report_matches_execution原始源码 L638–L667
src/quant_platform_kit/common/execution_state.py—_is_successful_no_action_report原始源码 L670–L675
src/quant_platform_kit/common/execution_state.py—_report_signal_date_keys原始源码 L678–L686
src/quant_platform_kit/common/execution_state.py—_report_effective_date_keys原始源码 L689–L694
src/quant_platform_kit/common/execution_state.py—_report_signal_snapshot原始源码 L697–L702
src/quant_platform_kit/common/execution_state.py—_date_keys原始源码 L705–L706
src/quant_platform_kit/common/execution_state.py—_date_key原始源码 L709–L713
quantcrossrepoautomation commentedon Sep 15, 2026
Codex Audit
Codex execution failed with exit code
1.No files were pushed. Check the bridge workflow logs for details.
quantcrossrepoautomation commentedon Sep 15, 2026
Codex Audit
Codex execution failed with exit code
1.No files were pushed. Check the bridge workflow logs for details.
quantcrossrepoautomation commentedon Sep 15, 2026
Codex Audit
修复摘要
仅修改
application/rebalance_service.py与tests/test_rebalance_service.py。修复在已成功 claim 的 durable live command 上补充重复证据收敛:只有 marker/prior-report 读取成功、至少一项明确匹配、且当前周期未产生订单时,才以
expected_previous_state=CLAIMED写入CANCELLED。读取失败或事件写入返回None时保持CLAIMED,继续 fail-closed。新增离线历史回归覆盖:
CANCELLED;CLAIMED、零订单。未执行本地测试;按约定由 AIAuditBridge 应用补丁并运行 pinned bounded test。
Created fix PR: #483
This PR is high-risk for unattended merge and requires human review.
high108application/rebalance_service.pytests/test_rebalance_service.pyAdded
human-review-requiredto the PR so operators can review it before merge.