fix(codegen): int64 epoch promotion on reassignment, UDT lvalue aliasing, HTF history-offset gating#30
Merged
Conversation
…ing, HTF history-offset gating
Three verified codegen bugs (plus a latent SIGSEGV the UDT fix unmasked), each
reproduced by patching generated.cpp and confirmed against TradingView:
- int->int64_t promotion now considers := reassignments, not just the
initializer. `var int t = na; t := time` was emitted as 32-bit int, overflowing
the epoch-ms (~1.74e12), so time-delta logic (e.g. MaxHold) misfired on bar 1.
(rsi-dip-ema-trend-long-dca: 690->511 trades, 99.8% match, 100% price-exact)
- request.security OHLC history-offset pushes (high[1], low[2], ...) are now gated
on is_complete, so offsets advance per completed HTF bar instead of per partial
eval under lookahead_on. (waranyutrkm-inside-day-breakout: 393->121, entries match TV)
- UDT lvalue init now aliases (C++ ref, or pointer when rebound) instead of
value-copying, honouring Pine UDT reference semantics: mutations through a
local bound to a `var` UDT member (incl. ternary/switch selections) write back.
Value-snapshot and read-only UDT locals are NOT aliased (regression-tested).
(jevondijefferson-big-breakout: 0->143 trades; Wyckoff structure arms, no crash)
- drawing-style constant passed positionally to a std::string param now coerces
to std::string("") instead of (char const*)0 -> null strlen SIGSEGV.
Gates: pytest 1383 passed, 1 skipped (+11 regression tests). Engine corpus parity
intact: verify_corpus --all = 251 excellent / 1 documented anomaly. Exactly 3
corpus strategies' generated.cpp change (BUG B is_complete gating only); all stay
excellent and their engine trades are byte-identical. 0 new transpile/compile
failures across the scraped strategy set.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
luisleo526
added a commit
that referenced
this pull request
Jun 30, 2026
… stays in HTF context (#31) `request.security(tf, ta.<fn>(...)[k], lookahead=...)` — a security expression that is a TA call read at a history offset — was mis-transpiled. In security.py::_build_security_expr the `Subscript` branch only handled `Subscript(Identifier)` (OHLC fields / helper bindings); a `Subscript(FuncCall-TA)` fell through to the generic chart-context path, which re-lowered the inner TA to the CHART member and gated a `_hist_call` buffer on `is_first_tick_` (chart tick) instead of `is_complete` (HTF-bar boundary). Without a magnifier is_first_tick_ is true every bar, so it produced the chart-timeframe TA — the correctly-computed security value `_secval_*` was discarded. Mirror the OHLC history-offset machinery (#30) for TA call-sites: declare a per-(sec, site) `Series<double> {member}_hist`, push the already-committed `_secval_*` gated on is_complete (so the indicator is not double-stepped), and read `hist[k-1]` for offset k>=1 (offset 0 reuses the bare `_secval_*`). Handles scalar, tuple (mixed OHLC+TA), and lower_tf security exprs; cleared in all clear_security branches. A non-literal TA history index errors loudly. Regression-safe: when the security tf == chart tf the engine sets is_complete every bar, so the history advances every bar (identical to chart behaviour); OHLC `close[1]` stays on the untouched Identifier branch. officialjackofalltrades-caldera-meridian (htfBasis = ta.ema(close,55)[1] @ "240"): 78.5% -> 97.5% match vs TradingView. 3commas-triple-rsi-dca (ta.rsi(...)[1] in security): no-trades -> 29% (recovered). quant-synthesis / waranyutrkm unchanged. Full gate PINEFORGE_ENGINE_INCLUDE=... pytest: 1384 passed, 1 skipped, 0 failed (incl. 254-strategy corpus compile sweep). New test_request_security_ta_history_offset_uses_htf_gating has teeth (fails before the fix). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Three verified codegen bugs (+ a latent SIGSEGV the UDT fix unmasked), each reproduced by patching
generated.cppand confirmed trade-for-trade against TradingView. Found by an evidence-gated diagnostic sweep over the scraped-strategy parity gaps.:=reassignments.var int t = na; t := timewas emitted as 32-bitint, overflowing the epoch-ms (~1.74e12) → time-delta logic (MaxHold) misfired on bar 1. →rsi-dip-ema-trend-long-dca690→511 trades, 99.8% match, 100% price-exact.request.securityOHLC history-offset pushes gated onis_complete.high[1]/low[2]advanced every partial eval underlookahead_oninstead of per completed HTF bar. →waranyutrkm-inside-day-breakout393→121, entries now match TV (residual is a by-design TV margin-call liquidation).pivot p = cond ? varMemberA : varMemberBmust alias sop.field := …writes through. Emits a C++ ref (or pointer when rebound). Value-snapshot / read-only locals are not aliased (regression-tested). →jevondijefferson0→143 trades (structure arms, no crash).std::stringparam now coerces tostd::string("")instead of(char const*)0(null-strlenSIGSEGV).Gates
verify_corpus --all= 251 excellent / 1 documented anomaly. Exactly 3 corpus strategies' generated C++ change (BUG 2'sis_completegating only); all stay excellent and their engine trades are byte-identical. BUG 3 + the string coercion changed zero corpus strategies.🤖 Generated with Claude Code