Skip to content

fix(codegen): int64 epoch promotion on reassignment, UDT lvalue aliasing, HTF history-offset gating#30

Merged
luisleo526 merged 1 commit into
mainfrom
fix/int64-reassign-udt-alias-htf-history
Jun 29, 2026
Merged

fix(codegen): int64 epoch promotion on reassignment, UDT lvalue aliasing, HTF history-offset gating#30
luisleo526 merged 1 commit into
mainfrom
fix/int64-reassign-udt-alias-htf-history

Conversation

@luisleo526

Copy link
Copy Markdown
Contributor

Summary

Three verified codegen bugs (+ a latent SIGSEGV the UDT fix unmasked), each reproduced by patching generated.cpp and confirmed trade-for-trade against TradingView. Found by an evidence-gated diagnostic sweep over the scraped-strategy parity gaps.

  1. int → int64_t promotion now considers := reassignments. var int t = na; t := time was emitted as 32-bit int, overflowing the epoch-ms (~1.74e12) → time-delta logic (MaxHold) misfired on bar 1. → rsi-dip-ema-trend-long-dca 690→511 trades, 99.8% match, 100% price-exact.
  2. request.security OHLC history-offset pushes gated on is_complete. high[1]/low[2] advanced every partial eval under lookahead_on instead of per completed HTF bar. → waranyutrkm-inside-day-breakout 393→121, entries now match TV (residual is a by-design TV margin-call liquidation).
  3. UDT lvalue init aliases instead of value-copying. Pine UDTs are reference types; pivot p = cond ? varMemberA : varMemberB must alias so p.field := … writes through. Emits a C++ ref (or pointer when rebound). Value-snapshot / read-only locals are not aliased (regression-tested). → jevondijefferson 0→143 trades (structure arms, no crash).
  4. drawing-style constant → std::string param now coerces to std::string("") instead of (char const*)0 (null-strlen SIGSEGV).

Gates

  • pytest: 1383 passed, 1 skipped (+11 new regression tests, incl. CAUTION control tests for non-aliasing).
  • Engine corpus parity intact: verify_corpus --all = 251 excellent / 1 documented anomaly. Exactly 3 corpus strategies' generated C++ change (BUG 2's is_complete gating only); all stay excellent and their engine trades are byte-identical. BUG 3 + the string coercion changed zero corpus strategies.
  • 0 new transpile/compile failures across the 100 scraped strategies.
  • Independently re-verified by an adversarial review pass (corpus diff re-run from scratch, byte-compared).

🤖 Generated with Claude Code

…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 luisleo526 merged commit fb533b5 into main Jun 29, 2026
9 checks passed
@luisleo526 luisleo526 deleted the fix/int64-reassign-udt-alias-htf-history branch June 29, 2026 23:13
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant