Skip to content

feat: legacy-safe result/store timing codec#252

Closed
Pigbibi wants to merge 4 commits into
mainfrom
codex/r1-s2-result-store-redesign-a
Closed

feat: legacy-safe result/store timing codec#252
Pigbibi wants to merge 4 commits into
mainfrom
codex/r1-s2-result-store-redesign-a

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Scope

R1S2 redesign v2 PR A only: legacy-safe timing metadata and store codec.

  • BacktestResult timing/identity metadata is keyword-only and positional-compatible.
  • v1 records remain readable; v2 timing identity is explicit and canonical profile IDs are serialized.
  • Default and explicit None remain legacy-only; LEGACY_EXECUTION_TIMING is explicit legacy-only; ANY_EXECUTION_TIMING is the only cross-timing query.
  • Timing keys are collision-free; store write revision is the tie-breaker with deterministic legacy fallback.

Spec: /Users/lisiyi/Documents/Codex/2026-07-14/ba-2/outputs/soxl_tqqq_result_store_redesign_v2_2026-07-14.md (PR A)
Commit: db366f157c1c59a55cbc739d87cc23c755152b72

Non-goals

No caller migration, orchestrator routing/copy paths, capability wiring, persist_mode, ephemeral/exporter, broker/live/account, or frozen PR #248/#251 changes.

Validation

601 full tests passed, 1 skipped; 62 focused/related passed; ruff, compileall, diff-check passed.

Co-Authored-By: Codex <noreply@openai.com>
@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

🤖 Codex PR Review

🚫 Merge blocked: 2 serious issue(s) found in high-risk files

⚖️ Codex Review Arbitration

🚫 block: 第一个阻塞点仍然成立:known_profile_aliases() 只展开规范名、注册别名及其 lower()/upper() 变体,load_latest_backtest() 也只按这些精确前缀做枚举,所以历史 v1 结果若实际落在 backtest/.../SoXl_SoXx_TrEnD_InCoMe/ 这类任意混合大小写目录下,按规范名 SOXL 查询仍不会扫描到。canonical_profile_id 只在新写入时持久化,不能修复既有 legacy 路径;新增测试也只证明“用同样的混合大小写去查能读到”,没有证明“规范查询能命中任意历史大小写”。不存在与 prior finding 的 contract conflict:当前第二条关于写入顺序的建议与 prior finding 同向,只是它本身已被新增的 test_any_timing_is_stable_independent_of_save_order 这类测试所反向约束,但这不影响第一条已被源码直接证实为真。

🚫 Blocking Issues

These issues must be fixed before this PR can be merged:

1. 🟠 [HIGH] Bug in src/quant_platform_kit/strategy_lifecycle/performance_store.py

load_latest_backtest() 只枚举规范 ID、注册别名以及这些别名的全小写/全大写前缀。v1 时代回测文件路径是直接用原始 strategy_profile 落盘的,路径在本地文件系统和对象存储里都是大小写敏感的,因此像 SoXl_SoXx_TrEnD_InCoMe 这类历史混合大小写前缀,后续如果按规范名 SOXL 查询将不会被扫描到。结果是历史记录明明存在却返回 None,与“v1 records remain readable”不一致。 (line 294)

Suggestion: 查询规范 profile 时不要只靠有限别名展开;要么基于持久化的 canonical_profile_id 建索引,要么在读取时做大小写无关的前缀发现/迁移,确保任意大小写的历史 profile 路径都能被规范查询命中。

2. 🟠 [HIGH] Logic in src/quant_platform_kit/strategy_lifecycle/performance_store.py

_backtest_sort_key() 现在用 (computed_at, param_version, result_identity_version, key) 排序,没有把写入顺序作为 tie-breaker。这样一来,只要两条记录共享相同的 computed_atparam_versionload_latest_backtest(..., execution_timing=ANY_EXECUTION_TIMING) 选出的就会是文件名字典序更大的那条,而不是最后写入的那条。由于 _backtest_key() 已把 timing 编进文件名,这会稳定地偏向某个 timing,导致“latest”读取到陈旧结果。 (line 650)

Suggestion:save_backtest_result() 持久化单调递增的 store_write_revision(或精确写入时间),并在 _backtest_sort_key() 中优先用它做 tie-breaker;只有读取没有该字段的 legacy 记录时,再退回到确定性的 key 排序。


Review by Codex PR Review bot • PR

Co-Authored-By: Codex <noreply@openai.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: db366f157c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/quant_platform_kit/strategy_lifecycle/performance_store.py Outdated
Comment thread src/quant_platform_kit/strategy_lifecycle/performance_store.py
Co-Authored-By: Codex <noreply@openai.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a8738cc9de

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

source_revision: str = ""
cost_model: str = ""

execution_timing: str | None = field(default=None, kw_only=True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve timing when orchestrator persists results

When a runner returns a timed BacktestResult through the standard BacktestOrchestrator.run path, persist_result reconstructs the result in src/quant_platform_kit/strategy_lifecycle/backtest_orchestrator.py:86-115 but never copies this new execution_timing field. The default None then makes the saved record use the legacy t0_missing key, so load_latest_backtest(..., execution_timing="next_open") cannot find a timed run unless callers bypass the orchestrator and save directly.

Useful? React with 👍 / 👎.

Comment thread src/quant_platform_kit/strategy_lifecycle/capabilities.py
Co-Authored-By: Codex <noreply@openai.com>
@Pigbibi

Pigbibi commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Contract arbitration note: the write-revision HIGH is not adopted. PR A source-of-truth defines ANY_EXECUTION_TIMING selection as deterministic and independent of save order; the tie-break is computed_at, param_version, result_identity_version, then stable key. The final tests exercise reversed save order and produce the same selected timing, so no wall-clock or monotonic revision is introduced.

@Pigbibi

Pigbibi commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

PERMANENT_FREEZE: arbitrary mixed-case legacy profile discovery requires an explicit prefix inventory/index/migration or narrowed compatibility contract; no further local patch. Preserve this PR as frozen evidence. The write-order HIGH remains rejected: ANY selection is deterministic and save-order-independent by approved contract/tests.

@Pigbibi Pigbibi closed this Jul 14, 2026
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