Skip to content

Fix short-seed close collisions with physical entry identity#131

Merged
luisleo526 merged 1 commit into
mainfrom
codex/order-collision-c-20260722
Jul 22, 2026
Merged

Fix short-seed close collisions with physical entry identity#131
luisleo526 merged 1 commit into
mainfrom
codex/order-collision-c-20260722

Conversation

@luisleo526

@luisleo526 luisleo526 commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • reproduce TradingView's authoritative default-FIFO short-seed three-object broker transaction behind a deliberately narrow eligibility gate
  • carry a per-run physical entry incarnation from PendingOrder through pyramid lots and closed trades
  • export that identity from the runtime C ABI, propagate it through all runners, and make the corpus verifier fail closed at TV-proven multi-entry collision keys
  • keep tolerant price projection deterministic and fail closed for overlapping tolerance neighborhoods

Root cause and impact

When a short seed, an opposite-side close, and a final short shared the same user-facing order ID, PineForge could collapse distinct physical entries. That changed which lot TradingView closed and left six source-faithful corpus strategies at Strong despite otherwise exact tapes. The runtime now preserves physical entry identity while retaining partial-close identity and resetting incarnation state for reused handles.

Validation

  • clean engine build and CTest: 118/118 passed
  • verifier suite: 35/35 passed, including tolerance-boundary, ambiguity, and non-transitive-overlap cases
  • unchanged generated strategies linked to the new runtime export exactly 28 public C symbols
  • two real collision probes: 94 TV-proven keys, zero identity mismatches, 3,432 nonzero identity rows
  • final latest-runtime + clean-main-codegen 416-strategy sweep: 409 ok, 1 no-trades anomaly, 5 expected transpile errors, 1 expected run error, 0 compile/driver errors, and 0 unresolved timeouts
  • final board: 361 Excellent / 40 Strong / 4 Moderate / 2 Weak; 401/407 are Excellent or Strong, with zero downward tier moves
  • immediate attribution: six new Strong-to-Excellent moves; the seventh move against the older frozen snapshot was already exact in the preceding UDT run
  • exhaustive N=3 publication matrix: 8/8 passed, 0 failed, 0 skipped; all-off remained Strong at 99.7% with count delta 3, while all-on reached Excellent at 100% with count delta 0
  • matrix publication gate and adjudicator both passed (GO, publication-ready); matrix fingerprint ae314d35a4926ff89a70f3ab372439cb9f2a3f71ff0ba1a803eaf9320d1fe519

No grader threshold was relaxed. Missing, ambiguous, or legacy entry identity prevents Excellent certification at the affected collision key.

Copilot AI review requested due to automatic review settings July 22, 2026 15:09

Copilot AI 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.

Pull request overview

This PR addresses TradingView “short-seed” default-FIFO close-collision behavior by introducing a run-scoped physical entry identity (“entry incarnation”) and using it to (1) reproduce a very specific 3-object broker transaction under a narrow gate and (2) fail corpus verification closed when TradingView proves distinct same-tick entries.

Changes:

  • Add per-run entry_incarnation provenance from PendingOrderPyramidEntryTrade, plus a new runtime C ABI accessor (strategy_closed_trade_entry_incarnation) and propagate it through Python/docker runners and CSV output.
  • Implement a narrowly gated short-seed collision path in the fill loop to match the authoritative TradingView 3-object ordering, including fail-closed safeguards.
  • Extend corpus verification + tests to detect/forbid false “Excellent” results when multiple physical entries share the same (time, price, direction) key.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_short_seed_close_collision.cpp New regression + control tests for the short-seed collision and entry-incarnation behavior.
tests/test_handle_reuse_reset.cpp Ensures handle reuse produces identical trades including entry_incarnation.
tests/test_c_abi_setters.cpp Adds coverage for the new runtime C ABI accessor and its bounds/legacy behavior.
tests/CMakeLists.txt Registers the new C++ test TU and adds the new Python identity test to CTest.
src/engine_strategy_commands.cpp Records a per-bar “rejected entry call” tombstone to disqualify the special collision gate.
src/engine_run.cpp Resets per-run order incarnation and rejection tombstone on handle reuse.
src/engine_orders.cpp Plumbs entry_incarnation through market-entry execution and stamps it onto lots/trades.
src/engine_fills.cpp Adds the short-seed collision gate + role tagging and implements the special materialize/close-only kernels.
src/c_abi.cpp Exports strategy_closed_trade_entry_incarnation from the runtime library.
scripts/verify_corpus.py Adds entry-signal/identity parsing, identity-aware fragment consolidation, and a fail-closed distinct-entry gate.
scripts/test_verify_corpus_metrics.py Adds extensive unit tests around identity-aware consolidation/projection and gating outcomes.
scripts/test_run_strategy_identity.py New focused tests for CSV emission and report mapping of entry_incarnation.
scripts/run_strategy.py Reads entry_incarnation via the new C ABI accessor and emits it to engine CSVs (entry rows only).
scripts/pf_release_run.py Preserves entry_incarnation in the release-report-to-runner mapping.
scripts/check_c_abi_runtime.py Updates the pinned runtime symbol inventory to include the new accessor.
README.md Updates documented stable C ABI symbol count and adds the new accessor to the table.
include/pineforge/pineforge.h Declares and documents strategy_closed_trade_entry_incarnation as a runtime export.
include/pineforge/engine.hpp Adds entry_incarnation to PyramidEntry/Trade, adds collision-role enum, and exposes a C++ accessor.
docs/pages/index.md Updates docs “API at a glance” to 28 functions and includes the new lifecycle symbol.
docs/pages/abi-stability.md Updates the ABI symbol inventory and runtime export description to include the new accessor.
docs/coverage.md Updates the documented C ABI symbol list and count.
docker/run_json.py Adds optional per-trade entry_incarnation emission when the accessor is present.
docker/run_json_diagnostics_test.py Tests optional alignment/behavior of the new entry_incarnation field in docker JSON reports.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/verify_corpus.py
Comment on lines +35 to +36
from collections import Counter
from collections.abc import Iterable
@luisleo526
luisleo526 marked this pull request as ready for review July 22, 2026 15:25
@luisleo526
luisleo526 merged commit cca49f1 into main Jul 22, 2026
8 checks passed
@luisleo526
luisleo526 deleted the codex/order-collision-c-20260722 branch July 22, 2026 15:26
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.

2 participants