Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(codegen): resolve request.security TA index+length per call site (helper inlining)#47

Merged
luisleo526 merged 1 commit into
mainfrom
fix/security-helper-per-callsite-index-and-length
Jul 7, 2026
Merged

fix(codegen): resolve request.security TA index+length per call site (helper inlining)#47
luisleo526 merged 1 commit into
mainfrom
fix/security-helper-per-callsite-index-and-length

Conversation

@luisleo526

Copy link
Copy Markdown
Contributor

Two coupled, additive fixes let a request.security nested in a multi-call helper transpile and compute correctly. Both have a byte-identical fallback → every already-transpiling strategy is unchanged.

Fixes

  1. History index (security.py): request.security(sym, tf, ta.ema(close, length)[idxHigher]) inside a helper rejected [idxHigher] (a helper param, not a NumberLiteral). Added _resolve_security_index_literal — tries the existing literal check first (short-circuit → identical), else resolves the index through the helper binding stack / global_expr_map and constant-folds batch-constant barstate flags (matching the folding codegen already does elsewhere).
  2. Constructor length (base.py): a request.security in an N-call helper is cloned per call site, but the shared TA site's ctor_args were resolved once against call site 0 → four security EMAs all sized from crossFastLen (21) instead of per-site [21,55,21,55]. Route each sec's ctor-arg resolution through the existing per-call-site function-clone TA remap (_func_cs_ta_remap); identity for cs0/non-clones.

Result

Recovers officialjackofalltrades-concordance-execution-mandate-joat from transpile-error → strong (matchPct 99.1%, entry/exit price p90 both 0.0000% exact; residual countAbsDelta 2–3 is strategy-logic trade-count precision, not codegen — excellent needs exact count parity).

Verification (fresh-context R7 = GO)

  • Corpus emission byte-identical 265/265 (HEAD vs parent, swap-sensitivity proven: parent CompileErrors on mandate, HEAD succeeds). All 21 request.security corpus strategies unchanged.
  • pytest 1446 passed.
  • mandate clang++ exit 0.
  • Sentinels (3commas-pol-grid, lukeborgerding) + corpus security probes byte-identical.

🤖 Generated with Claude Code

…(helper inlining)

Two coupled fixes let a request.security nested in a multi-call helper transpile
+ compute correctly. Both are additive with a byte-identical fallback, so every
already-transpiling strategy is unchanged (corpus 265/265 byte-identical).

1. History index (security.py). `f_secure_ema(tf, length, idxHigher, idxCurrent)
   => request.security(sym, tf, ta.ema(close, length)[idxHigher])[idxCurrent]`
   rejected because the TA history index `[idxHigher]` is a helper param, not a
   NumberLiteral. Add _resolve_security_index_literal: try the existing literal
   check first (short-circuit → identical), else resolve the index through the
   helper binding stack / global_expr_map and constant-fold batch-constant
   barstate flags (_fold_security_const_bool: isrealtime/islast→false,
   ishistory→true) — matching the flag folding codegen already does elsewhere.

2. Constructor length (base.py). A request.security in a helper called N times is
   cloned per call site (distinct sec_id + callsite_idx), but the shared TA
   site's ctor_args were resolved ONCE against call site 0 — so four security
   EMAs all sized from crossFastLen (21) instead of the per-site [21,55,21,55].
   Route each sec's ctor-arg resolution through the existing per-call-site
   function-clone TA remap (_func_cs_ta_remap); identity for cs0/non-clones.

Recovers officialjackofalltrades-concordance-execution-mandate-joat from
transpile-error → STRONG (was: could not transpile). Entry/exit price p90 both
0.0000% exact, countAbsDelta 2 (residual is strategy-logic trade-count precision,
not codegen — excellent needs exact count parity). pytest 1446 passed; clang
exit 0.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@luisleo526 luisleo526 merged commit 2be4676 into main Jul 7, 2026
9 checks passed
@luisleo526 luisleo526 deleted the fix/security-helper-per-callsite-index-and-length branch July 7, 2026 14:29
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