Skip to content

Commit 439bd52

Browse files
luisleo526claude
andcommitted
engine: ABI v4 groundwork — last_run_status, version 0.14.0 (live runtime surface)
Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EtGc9e9jfVe87cm7XUaQq3
1 parent 3c106d8 commit 439bd52

11 files changed

Lines changed: 59 additions & 13 deletions

File tree

‎VERSION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.13.1
1+
0.14.0

‎benchmarks/throughput/grid_search_repro.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ class pf_report_t(ctypes.Structure):
128128

129129
# pf_report_t is caller-allocated; a layout mismatch means the runtime
130130
# writes past this script's report buffer. Verify the ABI before running.
131-
EXPECTED_PF_ABI = 3
131+
# v4 is groundwork for the live-runtime surface and does not change
132+
# the pf_report_t/pf_trade_t layout this mirror describes.
133+
EXPECTED_PF_ABI = 4
132134

133135
def check_abi(lib):
134136
try:

‎docker/run_json.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,9 @@ def engine_version(lib: ctypes.CDLL) -> dict:
704704

705705
# pf_report_t is CALLER-allocated: a .so built against a different ABI
706706
# writes past (or short of) our ReportC buffer. Assert version up front.
707-
EXPECTED_PF_ABI = 3
707+
# v4 is groundwork for the live-runtime surface and does not change
708+
# the pf_report_t/pf_trade_t layout this mirror describes.
709+
EXPECTED_PF_ABI = 4
708710

709711

710712
def check_abi(lib: ctypes.CDLL) -> None:

‎include/pineforge/engine.hpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3472,6 +3472,11 @@ class BacktestEngine {
34723472
// insert + ``string`` push_back; subsequent calls with the same name
34733473
// are a single map lookup.
34743474
bool trace_enabled_ = false;
3475+
3476+
// Live-runtime surface (ABI v4). All default off/zero; historical runs are
3477+
// byte-identical when untouched (tests/test_live_flags_off_identity.cpp).
3478+
int last_run_status_ = 0; // 0 completed, 1 NOT_COMPLETED (abort)
3479+
34753480
std::vector<TraceEntryC> trace_buffer_;
34763481
std::vector<std::string> trace_names_;
34773482
std::unordered_map<std::string, int32_t> trace_name_index_;
@@ -4596,6 +4601,9 @@ class BacktestEngine {
45964601
void set_trace_enabled(bool on) { trace_enabled_ = on; }
45974602
bool trace_enabled() const { return trace_enabled_; }
45984603

4604+
// --- Live-runtime status API (ABI v4) ---
4605+
int last_run_status() const { return last_run_status_; }
4606+
45994607
// Push a typed per-bar value into the trace buffer. Cheap when
46004608
// disabled — a single bool branch and return. When enabled, name
46014609
// interning amortises to a single hash lookup per call after the

‎include/pineforge/pineforge.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@
7676
* macro have no pf_abi_version symbol — treat dlsym failure as
7777
* version 1. Value 3 appends pf_trade_t::open_at_end (the range-end
7878
* close flag); a v2 reader iterating trades with the v2 stride would
79-
* misindex every row after the first. */
80-
#define PF_ABI_VERSION 3
79+
* misindex every row after the first. Value 4 appends the live-runtime
80+
* accessors and the per-bar broker-state hash array to pf_report_t. */
81+
#define PF_ABI_VERSION 4
8182

8283
/** Feature probe for the opt-in split chart/request.security feed boundary.
8384
* When defined, #strategy_set_aux_security_feed is available. */

‎scripts/run_strategy.py‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -795,12 +795,15 @@ class ReportC(ctypes.Structure):
795795
# pf_report_t is CALLER-allocated: running an old .so against the v3
796796
# ReportC mirror (or vice versa) silently corrupts memory, so the .so's
797797
# pf_abi_version() export is asserted before any run. v3 appended
798-
# pf_trade_t::open_at_end (TradeC above); test_run_strategy_range_end.py
799-
# pins this constant to the header's macro, because the campaign's
800-
# verifier runs every probe through THIS harness and a stale guard here
801-
# is a run-error on every slug (the f-1d spark pre-check of 2026-09-02
802-
# found exactly that: ".so reports 3, harness expects 2" x64).
803-
EXPECTED_PF_ABI = 3
798+
# pf_trade_t::open_at_end (TradeC above); v4 is groundwork for the
799+
# live-runtime surface (last_run_status_ etc.) and does not change the
800+
# pf_report_t/pf_trade_t layout this mirror describes.
801+
# test_run_strategy_range_end.py pins this constant to the header's
802+
# macro, because the campaign's verifier runs every probe through THIS
803+
# harness and a stale guard here is a run-error on every slug (the
804+
# f-1d spark pre-check of 2026-09-02 found exactly that: ".so reports
805+
# 3, harness expects 2" x64).
806+
EXPECTED_PF_ABI = 4
804807

805808

806809
def _check_abi(lib: ctypes.CDLL) -> None:

‎scripts/test_run_strategy_range_end.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def test_expected_abi_is_the_headers_macro(self) -> None:
312312
self.assertIsNotNone(m)
313313
assert m is not None
314314
self.assertEqual(EXPECTED_PF_ABI, int(m.group(1)))
315-
self.assertEqual(EXPECTED_PF_ABI, 3)
315+
self.assertEqual(EXPECTED_PF_ABI, 4)
316316

317317
def test_trade_mirror_ends_with_open_at_end(self) -> None:
318318
names = [name for name, _ in TradeC._fields_]

‎src/engine_run.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ void BacktestEngine::reset_run_state() {
806806

807807
void BacktestEngine::run(const Bar* bars, int n) {
808808
last_error_.clear();
809+
last_run_status_ = 0;
809810
if (n > 0 && bars != nullptr) {
810811
last_bar_time_ = bars[n - 1].timestamp;
811812
last_bar_index_ = n - 1;
@@ -1305,6 +1306,7 @@ void BacktestEngine::run(const Bar* input_bars, int n_input,
13051306
int magnifier_samples,
13061307
MagnifierDistribution magnifier_dist) {
13071308
last_error_.clear();
1309+
last_run_status_ = 0;
13081310
if (n_input > 0 && input_bars != nullptr) {
13091311
last_bar_time_ = input_bars[n_input - 1].timestamp;
13101312
} else {
@@ -2009,6 +2011,7 @@ void BacktestEngine::run(const Bar* input_bars, int n_input,
20092011
int magnifier_samples,
20102012
MagnifierDistribution magnifier_dist) {
20112013
last_error_.clear();
2014+
last_run_status_ = 0;
20122015
try {
20132016
// Store syminfo and inputs
20142017
syminfo_ = syminfo;

‎tests/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ set(TEST_SOURCES
214214
test_famae_declined_reversal_trail_gap
215215
test_trail_activation_tick_bar
216216
test_session_predicates_daily_chart
217+
test_live_run_status
217218
)
218219

219220
find_package(Threads REQUIRED)

‎tests/test_live_run_status.cpp‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <pineforge/bar.hpp>
2+
#include <pineforge/engine.hpp>
3+
#include <pineforge/pineforge.h>
4+
#include <cstdio>
5+
using namespace pineforge;
6+
namespace {
7+
int failures = 0;
8+
#define CHECK(cond) do { if (!(cond)) { std::fprintf(stderr, "FAIL %s:%d %s\n", __FILE__, __LINE__, #cond); ++failures; } } while (0)
9+
Bar flat_bar(double p, int64_t ts) { return Bar{p, p, p, p, 1.0, ts}; }
10+
class NoopStrategy final : public BacktestEngine {
11+
public:
12+
void on_bar(const Bar&) override {}
13+
};
14+
}
15+
int main() {
16+
CHECK(PF_ABI_VERSION == 4);
17+
NoopStrategy s;
18+
CHECK(s.last_run_status() == 0);
19+
const Bar bars[] = {flat_bar(100.0, 0), flat_bar(101.0, 60'000)};
20+
s.run(bars, 2);
21+
CHECK(s.last_error().empty());
22+
CHECK(s.last_run_status() == 0);
23+
return failures == 0 ? 0 : 1;
24+
}

0 commit comments

Comments
 (0)