Skip to content

Commit f064b1c

Browse files
luisleo526claude
andcommitted
Docs: session-day facts in the migration map, the ADR rulings E26-6/E26-7, OT7 (R5 lane F5, item 4)
- pine-to-native.md: rows for session.ismarket, session.isfirstbar and session.islastbar in the calculation-context map (C++ fact, C byte, the witness that runs it, and what a Pine author would guess wrong: the masked-overnight difference from the generated time-of-day session.ismarket, the run edges, the open-ended close, the undeclared early close a stream cannot see). The "session facts" row now also holds for C. The coverage guard is unchanged: offered=131 covered=131. - ADR-0001: line 240's "barstate/session flags in pine_language_state.hpp" was false (AUDIT3 E26-7); it now names where each lives -- PineLanguageState for series and position views, PineStrategyHost for the session flags it selects from the kernel, BacktestEngine::barstate_islast_ still the adapter's to write, the live-probe overrides and their one session policy. Section B gains the row for the kernel's session-day mechanism (calibrated on the E25/E26 tapes; no knob: the open-ended reading is a second fact, not a switch). Two rulings close lane E26's open items: E26-6 RULED retained -- a bar with nothing held after it steps the calendar, so a stream or a live probe's forming bar cannot see an early close the session string does not declare; the remedy is an early-close calendar, a spec extension of its own. E26-7 RESOLVED by the move of item 2: no Pine session state is left on the kernel class. - native-feature-parity.md OT7: generic since F5, the adapter selects, the COOF lookahead defect it ended, E26-6 ruled, the recalculation's own flags are lane F1's. - native-engine.md: the decision context's four facts and native_calendar::session_day_at. live-surface.md: the forming tail bar reads the kernel's open-ended close; its early-close residue is ruled. - pine_v6_coverage_detail.md: the two inventory rows named the deleted writer scheduler_set_session_bar_state. - Citations the code items moved are re-anchored (check_doc_anchors.py --fix, then reanchor_doc_citations.py --ref fd78592: 53 carried through the base->HEAD line map, 0 left for a human); check_doc_anchors: 1589 anchors, every one resolves; check_doc_lint 0; design inventory 0 findings; check_native_feature_rulings OK; kernel residuals 109 hits, 0 findings. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> (cherry picked from commit 9249f11f65352c99d4e4d6ba7e6372e30c243da6)
1 parent a13360a commit f064b1c

7 files changed

Lines changed: 260 additions & 202 deletions

‎docs/adr/0001-kernel-adapter-boundary.md‎

Lines changed: 57 additions & 26 deletions
Large diffs are not rendered by default.

‎docs/design/native-feature-parity.md‎

Lines changed: 44 additions & 44 deletions
Large diffs are not rendered by default.

‎docs/pages/contributing-llm.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ policy layer that *uses* kernel features. Where every TradingView rule lives.
237237

238238
**front door** — one of the three ways in: PineScript through codegen, C++
239239
through `NativeStrategyHost` native_host.hpp:826, or C through the
240-
`strategy_native_*` surface native_c_api.h:2455.
240+
`strategy_native_*` surface native_c_api.h:2492.
241241

242242
**twin** — a test unit compiled twice, once against a frozen historical header
243243
closure and once against the current one, so a behaviour change has to be

‎docs/pages/live-surface.md‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,16 @@ configuration**, not one-shot: it stays in effect until a caller passes
6666
peek at, so it asks whether the next bucket — this bar's timestamp plus
6767
one script-TF step — falls out of session, or belongs to another session
6868
day), pinned to agree with the `i+1` lookahead on every interior bar of
69-
the 24x7 lanes. Historical bars read early closes correctly from the
70-
session day alone, with no holiday calendar; a *forming* tail bar still
69+
the 24x7 lanes. Since R5 lane F5 that is the kernel's answer, not the
70+
host's: the tail bar reads `NativeDecisionContext::closes_session_day_open_ended`
71+
(`market_driver.hpp:157`), the same fact as `closes_session_day` on every
72+
bar except a batch's final one, which it reads off the calendar instead
73+
of the run end. Historical bars read early closes correctly from the
74+
session day alone, with no holiday calendar; a *forming* tail bar
7175
cannot, because the calendar step it takes is one the session string
72-
declares as open. Non-24x7 tail bars therefore still need the v2
73-
`SessionCalendar` for early closes.
76+
declares as open. That is a ruled retention (ADR-0001, ruling
77+
"Session-day facts at a bar with nothing held after it"): the remedy
78+
is an early-close calendar, which the run spec does not carry.
7479
3. `bar_index` stays put; `last_bar_index` is frozen at the horizon bar
7580
(`horizon_bars - 1`), when `horizon_bars > 0`. `last_bar_time` is exact
7681
when the horizon bar is in the script-bar array, one script-TF step per
@@ -104,8 +109,9 @@ The one dispatch-path caveat that remains is not this flag's, and it is
104109
narrower than it was: every historical bar ends its session at the session
105110
day (R5 lane E26), so a non-24x7 tape's early closes are read from the tape
106111
itself. Only the forming tail bar is left — its calendar step cannot know a
107-
close the session string does not declare — so it still needs the v2
108-
`SessionCalendar`.
112+
close the session string does not declare — and that residue is ruled, not
113+
open (ADR-0001, ruling "Session-day facts at a bar with nothing held after
114+
it"): it needs an early-close calendar the run spec does not carry.
109115

110116
Default off (`on == 0`): every historical run stays byte-identical to
111117
before this flag existed.

‎docs/pages/native-engine.md‎

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,9 @@ byte-identical** to the spec. Conflicting values are a preflight refusal:
438438
spec fields.
439439

440440
The rich `run(bars, n, input_tf, script_tf, inputs, syminfo, overrides, …)`
441-
overload (`engine.hpp:1751-1762`) is **not** refused as a source mutation: it
441+
overload (`engine.hpp:1737-1748`) is **not** refused as a source mutation: it
442442
reaches `NativeExecutionConsumer::run_rich`
443-
(`native_execution_consumer.cpp:8026-8064`), which admits the begin, checks the
443+
(`native_execution_consumer.cpp:8180-8218`), which admits the begin, checks the
444444
timeframe arguments against the spec, preflights and pumps the batch exactly
445445
like the plain overload. `inputs` / `syminfo` / `overrides` are carried only as
446446
`NativeBeginArgs` fields to `prepare_native_begin` — the overrides as the
@@ -593,11 +593,11 @@ a host reacts to its own execution and may submit again. A request born there,
593593
mid-bar on a continuous segment, is eligible on the **remaining path suffix** of
594594
that segment — the birth is admitted at the current cursor and the geometric
595595
search then sees only the unconsumed suffix (`born_on_remaining_path`,
596-
`native_execution_consumer.cpp:5036-5040`). Requests accepted before the
596+
`native_execution_consumer.cpp:5048-5052`). Requests accepted before the
597597
segment, and discrete points, keep the ordinary birth gate above.
598598

599599
`on_native_bar_open` fires at the modeled opening, before that point's matching
600-
pass (`native_execution_consumer.cpp:6290-6292`). **Lookahead warning:** the
600+
pass (`native_execution_consumer.cpp:6302-6304`). **Lookahead warning:** the
601601
`Bar` it receives is the *complete* script bar — the consumer has already set
602602
`engine.current_bar_ = bar` (`native_execution_consumer.cpp:4176`) — so its
603603
high, low and close are the finished bar's, not what is known at the open. A
@@ -1778,9 +1778,27 @@ rather than relabelled. Failure copy and move do not allocate.
17781778
`NativeDecisionContext` (`market_driver.hpp:114`): the point's
17791779
`NativeCoordinate` (`market_driver.hpp:71` — ordinal, the interval stamps,
17801780
the effective time, the `NativePathPhase` and the `NativeCompletionKind`),
1781-
the decision floor and both calendar intervals. It is a presentation snapshot
1781+
the decision floor, both calendar intervals, and the script bar's
1782+
session-day facts (R5 lane F5): `in_session` (`market_driver.hpp:154`),
1783+
`opens_session_day`, `closes_session_day` and
1784+
`closes_session_day_open_ended`. They read the run's own calendar and
1785+
session day — the cycle that rolls at the session's first window start,
1786+
keyed to its trading date, so an overnight session is one day across local
1787+
midnight — and the bar before or after the script bar: the one the run
1788+
holds (its batch input or stream warmup), otherwise the calendar's slot one
1789+
script width away. A run's first bar opens its session day and a batch's
1790+
final bar closes it; the open-ended close reads the calendar at that final
1791+
bar instead, for a host whose last input is still forming; a D/W/M bar holds
1792+
whole days, so all four are true. Every callback of one script bar carries
1793+
the same four, fills and fill recalculations included, and a C host reads
1794+
the first three from `pf_native_decision_v1`'s session bytes
1795+
(`native_c_api.h:916`). The kernel resolves each session day once through
1796+
`native_calendar::session_day_at` (`native_calendar.hpp:407`), which a host
1797+
may call too. `tests/test_native_session_day_facts.cpp` replays the
1798+
TradingView session tapes through a bare host. It is a presentation snapshot
17821799
copied onto the callback stack: writing to it cannot move the floor, the
1783-
matching time or the after-calculation coordinate. `on_native_input` receives
1800+
matching time or the after-calculation coordinate, and the session-day facts
1801+
fold into no digest. `on_native_input` receives
17841802
`NativeInputContext` (`native_host.hpp:754`) instead — the two intervals, the
17851803
input index and whether this input completes the script interval — and
17861804
`on_native_tick` receives `NativeTickContext` (`native_host.hpp:766`), the
@@ -1811,11 +1829,11 @@ host that marks its own equity keeps this default and owns the whole series.
18111829

18121830
**The scalar extremes are not part of that bargain.** `max_drawdown_`,
18131831
`max_runup_` and `max_contracts_held_all_` / `_long_` / `_short_` — read back
1814-
through `max_drawdown_percent()` (`engine.hpp:1485`), `max_runup_percent()`
1832+
through `max_drawdown_percent()` (`engine.hpp:1471`), `max_runup_percent()`
18151833
(`engine.hpp:940`) and `max_contracts_held_all/long/short()`
18161834
(`engine.hpp:1794-1796`) — are a property of the RUN: what it drew down, what
18171835
it ran up, the most it ever held. The kernel folds them
1818-
(`update_equity_extremes`, `engine.hpp:1340`) at every script calculation
1836+
(`update_equity_extremes`, `engine.hpp:1326`) at every script calculation
18191837
under **every** report policy, so a `HostRecorded` host reads them truthfully
18201838
without asking the kernel to record anything. Before R5 lane E2 the fold was
18211839
reachable only through the two recording policies, and a defaulted host read
@@ -1835,11 +1853,11 @@ drawdown/run-up walk, and metrics computed over a real series.
18351853
The per-bar **broker-state hash** is a row of that same report, so
18361854
`KernelRecorded` records it too. It stays behind the recording switch it
18371855
always had — `set_broker_state_hash_recording(true)`
1838-
(`engine.hpp:2102`; C: `strategy_set_broker_state_hash_recording`), off by
1856+
(`engine.hpp:2088`; C: `strategy_set_broker_state_hash_recording`), off by
18391857
default, set while no run is active — because each row is a full
18401858
`broker_state_hash()` over the lots and the closed rows. With the switch on,
18411859
one row follows each point, after the extremes that point just folded
1842-
(`record_script_report_point`, `native_execution_consumer.cpp:6854`), so
1860+
(`record_script_report_point`, `native_execution_consumer.cpp:6992`), so
18431861

18441862
```text
18451863
broker_state_hash_len == equity_curve_len == script_bars_processed
@@ -1959,7 +1977,7 @@ bare host's own rows get theirs: the margin model's liquidation books
19591977
under the ticket the model or the run named. A host running its own forced
19601978
close states the cause on the row it produced.
19611979

1962-
`closed_trade_close_cause(i)` (`engine.hpp:1811`) is the C++ read and
1980+
`closed_trade_close_cause(i)` (`engine.hpp:1797`) is the C++ read and
19631981
`strategy_closed_trade_close_cause` (`pineforge.h:1212`) the C one, with the
19641982
same numbering: `-1` for a bad index or a NULL handle, `0` UNKNOWN, `1`
19651983
SCRIPT, `2` BRACKET, `3` MARGIN_CALL, `4` INTRADAY_LOSS_CAP, `5`
@@ -2560,7 +2578,7 @@ declared subscription does: an `authoritative_bars` feed, the `gaps` and
25602578
series' place in the run's continuous identity. Prefer `subscriptions` unless
25612579
you want none of those.
25622580
2563-
`set_native_security_feed` (`engine.hpp:1708`) is the host ingress for
2581+
`set_native_security_feed` (`engine.hpp:1694`) is the host ingress for
25642582
`authoritative_bars` installed before a run — see *Authoritative bars* above —
25652583
and not a way to register a series: registration is
25662584
`NativeRunSpec::subscriptions` or `declare_timeframe_subscriptions`. In-run the
@@ -2638,7 +2656,7 @@ These are existing refusals, not implied future features:
26382656
A C host has the same stream and the same commands. Streaming needs no new
26392657
symbol — `strategy_stream_begin` and its family (`native_c_api.h:37-38`) take
26402658
a `pf_strategy_t` from `strategy_native_host_create_v1` unchanged — and
2641-
`strategy_native_submit_v1` (`native_c_api.h:2494`) obeys the one legality
2659+
`strategy_native_submit_v1` (`native_c_api.h:2531`) obeys the one legality
26422660
rule its C++ spelling does.
26432661
26442662
Rebuild strategy libraries against this engine. An ABI-v4 module without the

0 commit comments

Comments
 (0)