Skip to content

Commit a3b4b97

Browse files
committed
Kernel: session-day facts on a UTC calendar resolve no calendar interval per bar (R5 lane PERF-KEDGE)
Wave G's KERNEL-EDGE made present_session_day read the bar's label and each neighbour at the first eligible instant of its script interval, and resolved those intervals through the calendar memo at every bar: three interval_containing calls a bar (two ring hits, one resolution). On FeedTolerant labels -- the Pine adapter's shape -- nothing else asks the calendar per bar, so the 100 public benchmark slots ran a median +11.9 % more instructions than 1a0e7ea (INT25 finding 1); callgrind puts all of slot 033's +1,020 Ir a bar in those calls. On a UTC calendar an instant that is itself in session reads exactly as its interval's first eligible instant does. The calendar is integer arithmetic there (no libc zone, no mktime) and its session days are the fixed daily cycles [date + origin, next date + origin), which tile time: every instant has one session day, and both the memo's candidate-date lookup and the consumer's session-day memo find it. The interval's open is that day's origin plus a whole number of buckets at or before the instant, and its first eligible instant is the first in-session instant of [open, instant] -- on that day, in session. So present_session_day reads such an instant's session point directly and resolves an interval only for an instant out of session, for the walk to the previous eligible slot and for the scheduled close (the last two only with nothing held). Every other zone issues the calendar calls in the order the base issued them, because a libc zone's mktime can answer from the previous call's offset. - native_calendar_memo.hpp / native_calendar.cpp: utc_calendar(calendar, memo), the memo's own once-per-calendar UTC decision, and SessionDayMemo::interval_resolutions(), a derived cost reading folded nowhere. - native_execution_consumer: calendar_is_utc() (cached, reset with the calendar memos); eligible_session_point() out of line, so the neighbour reading stays inlined; the bar's own interval resolved lazily. ADR-0001 rule 2: no capability, spec field or knob is added and no answer moves. The reading is the run's own calendar -- its zone is data -- the same for every venue, and nothing branches on a platform. Nothing is hashed: the facts fold into no digest and the new members are derived memos. Witness, tests/test_native_session_day_utc.cpp (kernel-only): the calendar's UTC decision; the same tapes under "UTC" and "UTC0" (the same clock through the zone path) present identical facts at every bar open, bar, fill recalculation, applied execution and print across 6 sessions, 6 timeframe pairings, both label policies, 5 tape shapes and 4 drive modes (1152 runs, 1.77M facts); and a UTC FeedTolerant batch resolves 1 interval where UTC0 resolves 529 for 528 bars. Fail-before at 0d76a09: "no member named 'interval_resolutions' in 'pineforge::native_calendar::SessionDayMemo'". Six mutants -- either fallback dropped, the walk's or the scheduled close's slot left unresolved, every zone taken for UTC, the shortcut removed -- each fail it. Floors: kernel 277 -> 278, release 678 -> 679, PR registration 659/659/668 -> 660/660/669 (ci_verify.py, its self-test pin and docs/ci.md). 24 doc anchors carried through the exact line map from 0d76a09; the 6 that cite the two rewritten floor lines set by hand (ci_verify.py:247, :357). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> (cherry picked from commit 16788d057fe06407fcd39843b9368ec1ab2782d9) INT26 pick note (late pick, accepted 2026-09-26 10:30, after INT26 item iv): the kernel and test hunks applied without conflict. The floors take this lane's row on top of item (iv)'s integrated counts -- KERNEL 285 -> 286, RELEASE 700 -> 701, EXCLUDED_REGISTERED_MIN 681/681/690 -> 682/682/691 (after PAR-ORDERS-2's and PAR-MARGIN-2's picks) -- and each floor comment lists it with wave H's other rows; test_ci_verify and docs/ci.md follow (docs/ci.md's floor sentence still named PAR-MARGIN's 680/278, which item iv missed). The four floor citations name the merged lines; the pages merged on citation digits only.
1 parent d1e4b5a commit a3b4b97

15 files changed

Lines changed: 612 additions & 50 deletions

‎CONTRIBUTING.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ What each gate refuses:
152152
### The floors
153153

154154
`ci_verify.py` counts the CTest rows that actually **ran** and fails below a
155-
floor — `KERNEL_MIN_TESTS` ci_verify.py:258 and `RELEASE_MIN_TESTS`
156-
ci_verify.py:387.
155+
floor — `KERNEL_MIN_TESTS` ci_verify.py:260 and `RELEASE_MIN_TESTS`
156+
ci_verify.py:389.
157157
A deleted or silently skipped row is a failure, not a quieter run. If your
158158
change adds rows, raise the floor in the same commit and say by how much; if it
159159
legitimately removes one, lower it deliberately and say why. `--min-tests`

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

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

‎docs/ci.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ requires the rows that actually ran to equal the second count, and records
100100
`registered`, `labelled = registered - selected`, and `ran` in
101101
`ctest-exclusion.log` and `ci-summary.json`. A skip, missing executable, lost
102102
registration below the PR registration floor, unreadable enumeration, or
103-
missing label fails. The PR registration floors at INT25 are 659 for Debug
104-
and sanitizers and 668 for native (653 and 662 at the INT24 base, plus wave G's
105-
six rows). The full-run release and kernel floors are 680 and 278 rows that
106-
ran; full runs do not exclude a label.
103+
missing label fails. The PR registration floors at INT26 are 682 for Debug
104+
and sanitizers and 691 for native (653 and 662 at the INT24 base, plus wave G's
105+
six rows and wave H's twenty-three). The full-run release and kernel floors are
106+
701 and 286 rows that ran; full runs do not exclude a label.
107107

108108
Preflight also runs the detached-comment census of the kernel compile closure
109109
(`detached-comments`: `scripts/measure_detached_comments.py --check-ceiling`)

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

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

‎docs/pages/contributing-llm.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ finding to report, not a step to take.
117117
`scripts/check_doc_reverts.py`.
118118

119119
10. **A test row never silently disappears.** Each profile counts the rows that
120-
*ran* against a floor: `KERNEL_MIN_TESTS` ci_verify.py:258 and
121-
`RELEASE_MIN_TESTS` ci_verify.py:387. Adding rows means raising the floor
120+
*ran* against a floor: `KERNEL_MIN_TESTS` ci_verify.py:260 and
121+
`RELEASE_MIN_TESTS` ci_verify.py:389. Adding rows means raising the floor
122122
in the same commit.
123123

124124
## The recipe for a lane
@@ -264,7 +264,7 @@ measurement that produced it, so a later change to it is visible as a change to
264264
the record, not as an edit to a literal.
265265

266266
**floor** — the minimum number of CTest rows a profile must actually run
267-
(`KERNEL_MIN_TESTS` ci_verify.py:258, `RELEASE_MIN_TESTS` ci_verify.py:387). It
267+
(`KERNEL_MIN_TESTS` ci_verify.py:260, `RELEASE_MIN_TESTS` ci_verify.py:389). It
268268
counts rows that ran, so a skipped row does not pad it.
269269

270270
**receipt** — the recorded evidence an ABI-comparison row needs (a prepared

‎docs/pages/native-engine.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ spec fields.
463463
The rich `run(bars, n, input_tf, script_tf, inputs, syminfo, overrides, …)`
464464
overload (`engine.hpp:1623-1634`) is **not** refused as a source mutation: it
465465
reaches `NativeExecutionConsumer::run_rich`
466-
(`native_execution_consumer.cpp:9183-9223`), which admits the begin, checks the
466+
(`native_execution_consumer.cpp:9156-9196`), which admits the begin, checks the
467467
timeframe arguments against the spec, preflights and pumps the batch exactly
468468
like the plain overload. `inputs` / `syminfo` / `overrides` are carried only as
469469
`NativeBeginArgs` fields to `prepare_native_begin` — the overrides as the
@@ -2098,7 +2098,7 @@ default, set while no run is active — because each row is a full
20982098
the live state, not the run's length: the closed rows enter through a running
20992099
digest). With the switch on,
21002100
one row follows each point, after the extremes that point just folded
2101-
(`record_script_report_point`, `native_execution_consumer.cpp:7835`), so
2101+
(`record_script_report_point`, `native_execution_consumer.cpp:7833`), so
21022102

21032103
```text
21042104
broker_state_hash_len == equity_curve_len == script_bars_processed
@@ -2909,7 +2909,7 @@ Only completed buckets are published, so this recipe has no lookahead by
29092909
construction. It is the same class the kernel's own subscription evaluator
29102910
aggregates with, and the one the kernel's `script_bucket_completions` query
29112911
feeds when the Pine scheduler asks how its input span buckets
2912-
(`TimeframeAggregator` `native_execution_consumer.cpp:7917`). What it does
2912+
(`TimeframeAggregator` `native_execution_consumer.cpp:7913`). What it does
29132913
**not** give you is what a
29142914
declared subscription does: an `authoritative_bars` feed, the `gaps` and
29152915
`lookahead` delivery rules, the lazy-seal chronology, a C spelling, and the

‎docs/pages/pine-to-native.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ rather than defaulted.
127127
| `commission_type` | `NativeFeeKind` native_run_spec.hpp:19 | `fee_kind` pineforge.h:540 | `native_open_lots_strategy.cpp` | `Percent`, `CashPerUnit`, `CashPerExecution` — the same three TradingView offers. |
128128
| `commission_value` | `fee_value` native_run_spec.hpp:590 | `fee_value` pineforge.h:540 | `native_open_lots_strategy.cpp` | Quoted per execution by `quote_execution_commissions` engine_execution.cpp:1588. A cash-per-execution ticket is split by units over every slice of that execution. |
129129
| `slippage` | `slippage_ticks` native_run_spec.hpp:584 | `slippage_ticks` pineforge.h:540 | `native_price_grid_strategy.cpp` | Raw `ticks * price_tick`, applied once native_execution_consumer.cpp:3971-3972. TradingView's round-then-slip order is adapter-only. |
130-
| `process_orders_on_close` | `NativeCloseExecution` native_run_spec.hpp:33 | `close_execution` pineforge.h:541 | `native_open_lots_strategy.cpp` | `AfterCalculation` emits the post-calculation close point native_execution_consumer.cpp:7542-7543, so a request submitted in bar *k*'s calculation fills at bar *k*'s own close. |
130+
| `process_orders_on_close` | `NativeCloseExecution` native_run_spec.hpp:33 | `close_execution` pineforge.h:541 | `native_open_lots_strategy.cpp` | `AfterCalculation` emits the post-calculation close point native_execution_consumer.cpp:7540-7541, so a request submitted in bar *k*'s calculation fills at bar *k*'s own close. |
131131
| `pyramiding` | `max_open_lots` native_run_spec.hpp:596 | `max_open_lots` pineforge.h:543 | `native_open_lots_strategy.cpp` | Caps surviving+new physical lots (`resulting_lot_count` native_execution_consumer.cpp:2914). The Pine adapter keeps its own per-cycle *entry count*, ruled **adapter-policy** in ADR-0001's table row `max_open_lots`; measured against TradingView it is not TradingView's rule, and this cap is the closer one (14 of 15 tape scenarios against 8, `tests/test_pyramiding_count_differential.cpp`). |
132132
| `default_qty_type` | `Sized` native_order.hpp:164 with `CashValue` native_order.hpp:91 or `EquityFraction` native_order.hpp:97 | `PF_NATIVE_INTENT_SIZED` native_c_api.h:344 with `size_basis` native_c_api.h:2111 | `native_sized_report_strategy.cpp` | The size is a property of the *request*, not of the run: a native host may size one order by cash and the next by equity fraction. `Transact` native_order.hpp:41 is the fixed-units form. Pine itself has no per-call `qty_type` — TradingView's compiler refuses one — so a script's `strategy.entry(qty = ...)` is always units; the source layer's typed per-call entry, which only generated or C++ callers reach, converts its money exactly as the declared default does. |
133133
| `default_qty_value` | the basis's own scalar: `CashValue::cash` native_order.hpp:92, `EquityFraction::fraction` native_order.hpp:98 | `intent_value` native_c_api.h:2115 | `native_sized_report_strategy.cpp` | `SizeTime` native_order.hpp:106 chooses *when* the basis resolves and `SizePrice` native_order.hpp:146 *which* price it converts at; both compose. |

‎scripts/ci_verify.py‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239
# extracted from the page and run)
240240
# All six register in release too; RATIO-HARDEN, V19-FIX and K-IDX add no row.
241241
# 278 registered, 277 run: the WebSocket row still skips on a system libcurl.
242-
# 285 run = those 277 plus the eight source-free rows of wave H (INT26),
242+
# 286 run = those 277 plus the nine source-free rows of wave H (INT26),
243243
# counted with ctest -N on the integrated tree:
244244
# +1 H-MEASURE test_native_acid_composite (the G1 acid composite, C++
245245
# and C)
@@ -251,11 +251,13 @@
251251
# +1 PAR-ORDERS-2 test_native_current_cohort_refusal
252252
# +1 PAR-MARGIN test_native_margin_intrabar_samples
253253
# +1 PAR-MARGIN-2 test_native_margin_post_fill_path
254+
# +1 PERF-KEDGE test_native_session_day_utc (session-day facts on a UTC
255+
# calendar without a calendar interval per bar)
254256
# REL10 renames F6's row (test_deprecated_public_spellings ->
255257
# test_removed_public_spellings); PAR-ORDERS and CI-FLAKE add no row. All
256-
# eight register in release too. 286 registered, 285 run: the WebSocket row
258+
# nine register in release too. 287 registered, 286 run: the WebSocket row
257259
# still skips on a system libcurl.
258-
KERNEL_MIN_TESTS = 285
260+
KERNEL_MIN_TESTS = 286
259261
# Release-row floor, the same gate for the default profile. Before lane P7
260262
# only the kernel profile had one, so a row that left release alone (a
261263
# source-bound TU dropped from TEST_SOURCES, a deleted twin or ABI row) left a
@@ -363,8 +365,8 @@
363365
# wave-G lane adds a source-bound row (the K-ULP4 and K-ULP5 C checks and
364366
# V19-FIX's scaling rows are rows inside existing TUs). No release row skips,
365367
# so 678 registered is 678 run.
366-
# 700 = those 678 plus wave H's twenty-two (INT26), counted with ctest -N on
367-
# the integrated tree: the eight KERNEL_MIN_TESTS lists above, which register
368+
# 701 = those 678 plus wave H's twenty-three (INT26), counted with ctest -N on
369+
# the integrated tree: the nine KERNEL_MIN_TESTS lists above, which register
368370
# here too, H-MEASURE's eleven source-bound rows the kernel profile does not
369371
# build (AUDIT4 X14) and PAR-ORDERS-2's three tape rows:
370372
# +1 G2-09/-10/-12/-13, E20 f1 test_adapter_margin_schedule_differential
@@ -383,8 +385,8 @@
383385
# test_pooc_reversing_stop_tapes
384386
# PAR-MARGIN's own count also held the margin differential, which that lane
385387
# had cherry-picked for its pins; it counts once, as H-MEASURE's. No release
386-
# row skips, so 700 registered is 700 run.
387-
RELEASE_MIN_TESTS = 700
388+
# row skips, so 701 registered is 701 run.
389+
RELEASE_MIN_TESTS = 701
388390
# ADR-0001 ruled-count floors, beside the ctest floors (R5 lane H-DOCGATES,
389391
# AUDIT4-opus X13 / docs-a N7). check_kernel_residuals.py counts the rulings
390392
# its vocabulary reads -- 174 identifiers and 45 texts on the lane's tree: the
@@ -405,12 +407,12 @@
405407
# PR-only registration floors: the complete CTest populations of the three
406408
# excluded profiles at INT25, counted with ctest -N on the integrated tree --
407409
# 653/653/662 at 91d65ad6 (INT24) plus wave G's six rows (C-SURFACE-1 +1,
408-
# KERNEL-EDGE +1, K-ULP4 +2, K-ULP5 +1, DOC-TRUTH-4 +1) in each; 681/681/690
409-
# at INT26, each with wave H's twenty-two rows of RELEASE_MIN_TESTS (H-MEASURE
410-
# +12, H-DOCGATES +3, K-OCA-KEEP +1, PAR-ORDERS-2 +4, PAR-MARGIN +1,
411-
# PAR-MARGIN-2 +1), counted the same way. An excluded run must still discover
412-
# at least this many rows before -LE.
413-
EXCLUDED_REGISTERED_MIN = {'debug': 681, 'sanitizers': 681, 'native': 690}
410+
# KERNEL-EDGE +1, K-ULP4 +2, K-ULP5 +1, DOC-TRUTH-4 +1) in each; 682/682/691
411+
# at INT26, each with wave H's twenty-three rows of RELEASE_MIN_TESTS
412+
# (H-MEASURE +12, H-DOCGATES +3, K-OCA-KEEP +1, PAR-ORDERS-2 +4, PAR-MARGIN
413+
# +1, PAR-MARGIN-2 +1, PERF-KEDGE +1), counted the same way. An excluded run
414+
# must still discover at least this many rows before -LE.
415+
EXCLUDED_REGISTERED_MIN = {'debug': 682, 'sanitizers': 682, 'native': 691}
414416
# The ctest stage's bound. A full sanitizers run (push to main, a manual
415417
# dispatch, the maintainers' verification) ran out of its 30 minutes twice on
416418
# main's four-core runner before every row had finished, so it gets an hour; a

‎scripts/test_ci_verify.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ def test_ctest_label_exclusion_is_forwarded(self):
13311331

13321332
def test_pr_exclusion_proves_registered_minus_labelled_equals_ran(self):
13331333
self.assertEqual(ci_verify.EXCLUDED_REGISTERED_MIN,
1334-
{'debug': 681, 'sanitizers': 681, 'native': 690})
1334+
{'debug': 682, 'sanitizers': 682, 'native': 691})
13351335
for profile, registered in ci_verify.EXCLUDED_REGISTERED_MIN.items():
13361336
with self.subTest(profile=profile):
13371337
code, summary, scripted, _ = self.run_profile(

‎src/native_calendar.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,8 @@ struct SessionDayMemo::State {
15971597
std::size_t next_local = 0;
15981598
std::array<IntervalSlot, kIntervalSlots> intervals{};
15991599
std::size_t next_interval = 0;
1600+
// Intervals resolved rather than answered from `intervals`.
1601+
std::uint64_t interval_resolutions = 0;
16001602
};
16011603

16021604
namespace {
@@ -1893,6 +1895,10 @@ void SessionDayMemo::reset() noexcept {
18931895
calendar_ = nullptr;
18941896
}
18951897

1898+
std::uint64_t SessionDayMemo::interval_resolutions() const noexcept {
1899+
return state_ ? state_->interval_resolutions : 0;
1900+
}
1901+
18961902
SessionDayMemo::State& SessionDayMemo::bind(const SessionCalendar& calendar) {
18971903
auto fresh = std::make_unique<State>();
18981904
fresh->valid = calendar.valid();
@@ -1943,6 +1949,7 @@ std::optional<NativeInterval> interval_containing(const SessionCalendar& calenda
19431949
return slot.interval;
19441950
}
19451951
}
1952+
++m.interval_resolutions;
19461953
auto interval = memo_interval_containing(calendar, script_tf, input_tf, ms, m);
19471954
MemoState::IntervalSlot& slot = m.intervals[m.next_interval];
19481955
m.next_interval = (m.next_interval + 1) % MemoState::kIntervalSlots;
@@ -1989,5 +1996,9 @@ bool in_session(const SessionCalendar& calendar, int64_t ms, SessionDayMemo& mem
19891996
return ms_in_spans(day->spans, ms);
19901997
}
19911998

1999+
bool utc_calendar(const SessionCalendar& calendar, SessionDayMemo& memo) {
2000+
return memo.state(calendar).utc;
2001+
}
2002+
19922003
} // inline namespace native_calendar_v2
19932004
} // namespace pineforge::native_calendar

0 commit comments

Comments
 (0)