Skip to content

Commit e5f5e20

Browse files
committed
Add the generic cohort owner, intrabar path, pre-open hook and pre-begin configuration provider to the native kernel (R4-D L1)
Implement the fenced generic lowering prerequisites: - native v5 cohort ownership/authority, live NoTarget deferral, deterministic roster resolution, receipts, and continuation hashing; - native v2 owned lower-timeframe intrabar paths and v5 driver decision context/delivery; - native host v17 pre-open and pre-begin provider hooks plus staged ingress; - v7 native-consumer matching, validation, lifecycle, hash/ABI fences, relocation matrix, and native witnesses. Contract rules: §3.1; P7a; P8a/P8b; P11; P15; P-DA1/P-DA3; amendments A1/A3/A5/A7/A8. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016iF71UAEuQ7F6eqWgecAHm
1 parent 5928e32 commit e5f5e20

45 files changed

Lines changed: 2194 additions & 519 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/ci.md‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,20 @@ their matching prepared receipts under `settlement-abi-base/`,
9090
configuration and version-source mismatches refuse reuse without deleting the old evidence.
9191
Each profile needs matching providers; a Mac Release archive cannot replace
9292
a Linux sanitizer build. CTest itself performs no network fetch.
93-
The full settlement matrix uses those six archives plus live v16. Its
93+
The full settlement matrix uses those six archives plus live v17. Its
9494
host/order matrix retains the historical v13/v14/v15 verdicts and requires
95-
both v15→v16 and v16→v15 rejection pairs, and frozen-v16 ↔ live-v16
96-
same-epoch positive pairs; matching v16 callers/providers succeed. The
97-
unchanged driver v4 keeps its historical positive links where its
98-
owner domain is unchanged. Current source callers authenticate the
99-
`pineforge-source-adapter/v1` domain, while the frozen v15 provider remains an
100-
immutable historical identity.
95+
both v16→v17 and v17→v16 rejection pairs; matching v17 callers/providers
96+
succeed. The unchanged historical driver-v4 controls remain, while live
97+
driver values are v5. Current source callers authenticate the
98+
`pineforge-source-adapter/v2` domain, while the frozen v15/v16 providers remain
99+
immutable historical identities.
101100
The [ABI guide](../tests/fixtures/settlement_cpp_abi/README.md) describes the
102101
actual old/new library pairs and their immutable inputs.
103102

104103
CTest writes `settlement-abi-receipt.json` for the seven-archive matrix and
105104
`native-abi-receipt.json` for native controls. The native receipt includes the
106-
active `v14_current_execution_shape_agnostic_compile`, frozen-v15/frozen-v16
107-
surface controls, and v16-current rejection controls against authenticated tar
105+
active `v14_current_execution_shape_agnostic_compile`, frozen-v16
106+
surface controls, and v17-current rejection controls against authenticated tar
108107
closures. `CURRENT_TERMS_SURFACE_READY = True`: the complete current-execution,
109108
FX, and missing-Cancelled controls are active, and the good caller compiles
110109
before its intentional negative compile control. Ordinary compile failures

‎docs/native-refactor-progress.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,12 @@ accepted.
125125

126126
## Current R4-C epoch baseline
127127

128-
The current baseline uses `native_order_v4`, engine/host
129-
`engine_script_run_v16`, `native-consumer/v6`, broker/stream version 16, and
130-
the source extension domain `pineforge-source-adapter/v1`. The frozen e7cdf05
131-
provider remains v15. Identity values remain `native_order_v1`; native run-spec
132-
and calendar remain v1, the driver remains v4, and `PF_ABI_VERSION` remains 4.
128+
The current L1 baseline uses `native_order_v5`, engine/host
129+
`engine_script_run_v17`, `native-consumer/v7`, broker/stream version 17, and
130+
the source extension domain `pineforge-source-adapter/v2`. The frozen ab9714b
131+
provider remains v16 for the required bidirectional rejection pairs. Identity
132+
values remain `native_order_v1`; native run-spec is v2, calendar remains v2,
133+
the driver is v5, and `PF_ABI_VERSION` remains 4.
133134

134135
## Completed R3 settlement and observation milestones
135136

‎docs/pages/abi-stability.md‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,21 @@ notice:
116116
- The shape of internal log lines (use them for humans, not parsers).
117117

118118
Rebuild generated and native C++ objects against matching engine headers and
119-
runtime. R4-C advances `BacktestEngine`, `NativeStrategyHost`, and the private
120-
consumer to `engine_script_run_v16`; the host capability macro is
121-
`PINEFORGE_HAS_NATIVE_STRATEGY_HOST_V16`. `PendingOrder` is no longer an engine
122-
epoch type: it is `pineforge::source::PendingOrder`, with the explicit
123-
`pineforge-source-adapter/v1` source-hash domain. Native request/core/event
124-
values remain `native_order_v4`, the private consumer identity remains
125-
`native-consumer/v6`, and driver types remain `native_driver_v4`.
119+
runtime. R4-D L1 advances `BacktestEngine`, `NativeStrategyHost`, and the
120+
private consumer to `engine_script_run_v17`; the host capability macro is
121+
`PINEFORGE_HAS_NATIVE_STRATEGY_HOST_V17`. `PendingOrder` remains a source
122+
epoch type (`pineforge::source::PendingOrder`) with the explicit
123+
`pineforge-source-adapter/v2` source-hash domain. Native request/core/event
124+
values are `native_order_v5`, the private consumer identity is
125+
`native-consumer/v7`, driver types are `native_driver_v5`, and run specs are
126+
`native_run_spec_v2`.
126127

127128
| Matrix role | Internal identity |
128129
| --- | --- |
129-
| Live engine/host library | `engine_script_run_v16` |
130+
| Live engine/host library | `engine_script_run_v17` |
130131
| `host-e7cdf05` immutable provider | `engine_script_run_v15` |
131132
| `host-ab9714b` immutable provider | `engine_script_run_v16` |
132-
| Source extension | `pineforge-source-adapter/v1` |
133+
| Source extension | `pineforge-source-adapter/v2` |
133134

134135
The current v16 archive is checked with six archived provider inputs: the real
135136
e60 R2 and 0e R3 providers, authenticated c3ed455 v13 and f736676 v14 host

‎include/pineforge/engine.hpp‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,16 @@ struct SymInfo {
427427
double qty_step = 0.0;
428428
};
429429

430+
// Value-owned runtime input transport shared by the public rich run overload
431+
// and the generic native pre-begin provider. It contains no frontend policy.
432+
using InputsMap = std::unordered_map<std::string, std::string>;
433+
430434
// The C++ subclass contract is internal, unlike pineforge.h's stable C ABI.
431435
// Changing its layout or vtable requires all generated/native C++ objects to be rebuilt.
432436
// v6 adds explicit owner-bound exit-leg activation and Pine placement evidence.
433437
// Version the mangled class name so older headers' member offsets/vtable cannot
434438
// silently bind out-of-line members of this different object layout.
435-
inline namespace engine_script_run_v16 {
439+
inline namespace engine_script_run_v17 {
436440
class BrokerStateHashSink;
437441
class BacktestEngine {
438442
protected:
@@ -3794,5 +3798,5 @@ class BacktestEngine {
37943798
void trace(const std::string& name, int value) { trace(name, static_cast<double>(value)); }
37953799
};
37963800

3797-
} // inline namespace engine_script_run_v16
3801+
} // inline namespace engine_script_run_v17
37983802
} // namespace pineforge

‎include/pineforge/execution_consumer.hpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace pineforge {
1313
struct SymInfo;
1414
namespace source { struct StrategyOverrides; }
1515

16-
inline namespace engine_script_run_v16 {
16+
inline namespace engine_script_run_v17 {
1717

1818
class BacktestEngine;
1919

@@ -66,5 +66,5 @@ class IExecutionConsumer {
6666
std::unique_ptr<IExecutionConsumer> make_legacy_execution_consumer();
6767
std::unique_ptr<IExecutionConsumer> make_native_execution_consumer();
6868

69-
} // inline namespace engine_script_run_v16
69+
} // inline namespace engine_script_run_v17
7070
} // namespace pineforge

‎include/pineforge/market_driver.hpp‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
#include <string>
99

1010
namespace pineforge {
11-
inline namespace native_run_spec_v1 { struct NativeRunSpec; }
12-
inline namespace native_driver_v4 {
11+
inline namespace native_run_spec_v2 { struct NativeRunSpec; }
12+
inline namespace native_driver_v5 {
1313

1414
// Semantic versions hashed into native continuation identity.
15-
inline constexpr const char* kNativeDriverSemanticVersion = "native-driver/v4";
16-
inline constexpr const char* kNativeConsumerSemanticVersion = "native-consumer/v6";
15+
inline constexpr const char* kNativeDriverSemanticVersion = "native-driver/v5";
16+
inline constexpr const char* kNativeConsumerSemanticVersion = "native-consumer/v7";
1717
inline constexpr const char* kNativeCalendarSemanticVersion = "native-calendar/v1";
1818

1919
enum class NativePriceProvenance : std::uint8_t {
@@ -74,6 +74,14 @@ struct NativeDecisionContext {
7474
int64_t decision_floor_ms = 0;
7575
native_calendar::NativeInterval input_interval{};
7676
native_calendar::NativeInterval script_interval{};
77+
// A non-magnified run is the one-element intrabar path. The sub-bar
78+
// timestamp is deliberately separate from the script label: execution
79+
// ledgers use the former while script-time policy uses the latter.
80+
int sub_index = 0;
81+
int sub_count = 1;
82+
bool is_terminal_sub_bar = true;
83+
int64_t sub_bar_open_ms = 0;
84+
int64_t script_bar_open_ms = 0;
7785
};
7886

7987
// Pump-produced events obtain ordinals from the consumer allocator.
@@ -155,5 +163,5 @@ NativeInputPreflightResult preflight_native_inputs(
155163
int n,
156164
NativeInputPolicy policy);
157165

158-
} // inline namespace native_driver_v4
166+
} // inline namespace native_driver_v5
159167
} // namespace pineforge

‎include/pineforge/native_host.hpp‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <vector>
1616

1717
namespace pineforge {
18-
inline namespace engine_script_run_v16 {
18+
inline namespace engine_script_run_v17 {
1919

2020
enum class NativeLifecycleKind : std::uint8_t {
2121
Unconfigured = 0,
@@ -345,12 +345,32 @@ using NativeCurrentExecutionResult = std::variant<NativeCurrentRefusal,
345345
native_order::ExecutionAppliedEvent, native_order::NoEffectEvent,
346346
native_order::MatchRejectedEvent, native_order::CancelledEvent>;
347347

348+
// Borrowed begin-call facts. The bar/input/override pointers expire when
349+
// prepare_native_begin returns; retained configuration must copy them by
350+
// value (for example into NativeRunSpec::intrabar).
351+
struct NativeBeginArgs {
352+
const Bar* bars = nullptr;
353+
int n = 0;
354+
std::string input_tf;
355+
std::string script_tf;
356+
bool bar_magnifier = false;
357+
int magnifier_samples = 4;
358+
MagnifierDistribution magnifier_distribution = MagnifierDistribution::ENDPOINTS;
359+
bool magnifier_volume_weighted = false;
360+
int magnifier_volume_weighted_min_samples = 2;
361+
int magnifier_volume_weighted_max_samples = 64;
362+
const InputsMap* inputs = nullptr;
363+
const void* overrides_opaque = nullptr;
364+
bool is_stream = false;
365+
int warmup_n = 0;
366+
};
367+
348368
// Most-derived native strategy host. Binds NativeExecutionConsumer in the
349369
// protected engine constructor. Noncopyable and nonmovable. Lives in the
350370
// same inline engine epoch as BacktestEngine so old-header/new-library
351371
// linkage cannot resolve an unversioned constructor against a different
352372
// base layout.
353-
#define PINEFORGE_HAS_NATIVE_STRATEGY_HOST_V16 1
373+
#define PINEFORGE_HAS_NATIVE_STRATEGY_HOST_V17 1
354374
class NativeStrategyHost : public BacktestEngine {
355375
public:
356376
NativeStrategyHost();
@@ -362,7 +382,11 @@ class NativeStrategyHost : public BacktestEngine {
362382

363383
void on_bar(const Bar& bar) final;
364384

385+
virtual void prepare_native_begin(const NativeBeginArgs&) {}
365386
virtual void on_native_run_begin() {}
387+
// Precedes the matching pass at the script bar's open decision point.
388+
// inspect_current_execution/execute_current are legal in this hook.
389+
virtual void on_native_bar_open(const Bar&, const NativeDecisionContext&) {}
366390
virtual void on_native_bar(const Bar& bar, const NativeDecisionContext& context) = 0;
367391

368392
virtual void on_native_applied(const native_order::ExecutionAppliedEvent&,
@@ -393,6 +417,9 @@ class NativeStrategyHost : public BacktestEngine {
393417
native_order::ReplaceResult replace_market(const native_order::RequestHandle& target,
394418
const native_order::Request& request);
395419
native_order::CancelResult cancel(const native_order::RequestHandle& target);
420+
native_order::CohortHandle cohort_open();
421+
void cohort_add(native_order::CohortHandle cohort, native_order::RequestHandle origin);
422+
void cohort_remove(native_order::CohortHandle cohort, native_order::RequestHandle origin);
396423

397424
NativePhysicalPosition physical_position() const;
398425
double native_marked_equity(double mark) const;
@@ -406,5 +433,5 @@ class NativeStrategyHost : public BacktestEngine {
406433
friend class NativeExecutionConsumer;
407434
};
408435

409-
} // inline namespace engine_script_run_v16
436+
} // inline namespace engine_script_run_v17
410437
} // namespace pineforge

0 commit comments

Comments
 (0)