Fix short-seed close collisions with physical entry identity#131
Merged
Conversation
There was a problem hiding this comment.
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_incarnationprovenance fromPendingOrder→PyramidEntry→Trade, 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 on lines
+35
to
+36
| from collections import Counter | ||
| from collections.abc import Iterable |
luisleo526
marked this pull request as ready for review
July 22, 2026 15:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PendingOrderthrough pyramid lots and closed tradesRoot 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
GO, publication-ready); matrix fingerprintae314d35a4926ff89a70f3ab372439cb9f2a3f71ff0ba1a803eaf9320d1fe519No grader threshold was relaxed. Missing, ambiguous, or legacy entry identity prevents Excellent certification at the affected collision key.