Skip to content

Commit e163980

Browse files
luisleo526claude
andauthored
Fail the run on an unaccepted timezone or a failed void setter (#837)
The scoped-timezone mechanism ignored the result of setenv, and a memory failure while a zone was switched left the caller in the previous zone or in UTC. A zone name written in a script reached setenv and tzset unchecked in three families (the time fields hour to weekofyear, time() and time_close() with the session predicates, and str.format_time), and an unknown name such as "America/Newyork" silently read as UTC, where TradingView stops the run. The fourteen void C setters for the instrument and run settings swallowed every exception, whether an allocation failure or a change the engine refused, so a run could start with a setting that was never applied and finish with a wrong result. An unaccepted timezone name now stops the run with the new code pine_timezone_error (class strategy, not retryable, since 1.12.0). Its arguments are bar_index, function and zone. The message is TradingView's text (runtime error RE10133) with the engine's bar prefix, "Error on bar N: ", or "Error before the first bar: " when no bar is being executed. The prefix comes from the one function that already builds it for the regular-expression stop, run_error_bar_prefix; a second function, run_error_bar_index, supplies the argument (-1 when no bar is being executed). Generated code reaches the stop through pine_timezone_stop(function, zone, english), offered under its own macro, PINEFORGE_HAS_TIMEZONE_STOP_V1; the caller passes the English without a prefix. TradingView's function name is captured for time and timestamp only: the other ten names of the vocabulary are the engine's choice, and the session predicates report time although their zone is the symbol's. Accepted names are remembered in a table of eight slots per thread, so a repeated name is not checked again. A failed setenv (out_of_memory for ENOMEM, engine_unclassified_error with the errno kept for any other error) and a memory failure while the timezone is switched now fail the run. The void C setters now record every exception on the handle: strategy_last_run_status reads 1, and strategy_get_last_error and strategy_get_last_error_code return the text and the code. The text begins with the same bar prefix. A setup failure makes the next run start fail once with that record; the following start clears it and starts normally. The failed setter did not apply its value, so a retry of the start without applying the setter again runs on the previous value. The documented refusal of a quote write after a selected run has sealed is unchanged: it is still dropped silently and read through strategy_state_query_status_v1. Non-positive or NaN mintick and pointvalue in a --syminfo document, and path_order modes outside 0, 1 and 2, now give typed refusals (the existing symbol metadata error for the tick and the point value, setting_rejected for the mode) instead of being ignored or reset to AUTO. The new tests use a counting replacement of the global operator new (tests/fail_alloc_seam.hpp) to refuse each allocation of a run in turn: every allocation must end in a typed failure or in a closed-trade list (and its totals) identical to the clean run, never in a different completed result, and the sweeps print the indexes at which a run completed. The setenv failure is injected by an interposer in the test, with no hook in the production code. One test covers the timezone name check and the zone switch, one the setter paths, and a Python test reads the --syminfo refusals. The new code is also registered where codes are counted and announced: tests/test_run_failure_code_numbers.py pins its number (88) and the enumerator count (89), the page docs/pages/run-failure-codes.md counts 88 named codes and 89 registry entries and names the code in its preamble, and the registry count pinned in tests/test_run_failure_codes.cpp becomes 89. Documentation sentences this change removes or rewrites: - docs/pages/run-failure-codes.md, the preamble: "The catalog contains 87 named failure codes: 38 first released in 1.4.0, 26 first released in 1.5.0, 5 added in 1.7.0, 10 added in 1.9.0 (3 run-quota codes and 7 report-channel codes), and 8 added in 1.11.0." and "One unnamed `none` sentinel gives 88 registry entries; existing numbers stay fixed." They now count 88 named codes (one added in 1.12.0) and 89 registry entries. - docs/pages/live-surface.md: "Any other `mode` is clamped to AUTO." An out-of-range path_order mode now records a typed setting_rejected error. - docs/adr/0001-kernel-adapter-boundary.md, the row of strategy_set_path_order: "clamps an out-of-range mode to AUTO" and "A `void` ABI v4 setter cannot answer a refusal." The setter now refuses and records setting_rejected, readable through strategy_get_last_error, strategy_get_last_error_code and strategy_last_run_status; the void signature is unchanged. - docs/coverage.md, the pine_str_format_time row: "Empty / `"UTC"` / `"Etc/UTC"` use `gmtime_r`; everything else swaps `TZ` under `tz_util::ScopedTimezone` and uses `localtime_r`." It now says "other accepted names" and describes the new error. - docs/pages/run-failure-codes.md: "hardwires its code and takes only literals the transpiler emits"; pine_timezone_stop takes the zone string the script computed. - docs/adr/0001-kernel-adapter-boundary.md, the row of run-failure code names: the sentence "Each name states the failure in the terms of the script that caused it" gains the timezone argument. ADR-0001 lists pine_timezone_error with the other code names and gives pine_timezone_stop its own row, because the kernel calls it. The ownership manifest lists the new code. The catalog gains the code, so a release that carries this change is a minor one. The allocation-bound manifest lists three new groups (the number-to-text temporaries of the setter refusal messages, and the message string of the timezone refusal with its temporary; ceiling 1415 -> 1418, pinned count 1599 -> 1602) and its site inventory is re-emitted, and the allowlist of uncoded rethrows counts the two new rethrows. The lines added to the sources move the lines the documentation cites below them; the anchors that follow them are re-pointed by the number of lines added (digits only). Five pre-existing sentences of docs/adr/0001-kernel-adapter-boundary.md (two) and docs/design/native-feature-parity.md (three) are also reworded, because the re-pointed lines count as added lines and the older wording named an internal work stream by a word that public text does not use; they now say "work item" and mean the same. Co-authored-by: Claude Fable 5.2 <[email protected]>
1 parent cdb8ae8 commit e163980

49 files changed

Lines changed: 3060 additions & 660 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ version number follows semantic versioning over the surfaces the
1212
An invalid regular expression now stops the run with a typed error, as TradingView does; it used to return an empty string. The message is TradingView's text with the engine's bar prefix, `Error on bar N: `, or `Error before the first bar: ` when no bar is being executed.
1313
Patterns the engine's regular-expression library does not support also stop the run now, with the same error. On the Linux build these include lookbehind, named groups, inline flags such as `(?i)`, comment groups, atomic groups, conditionals, `\p{...}` classes and `{,n}` repeats; lookahead, lazy quantifiers, back-references, POSIX classes and `\b` are accepted.
1414
- A memory failure during a session-calendar lookup now fails the run with a typed error instead of reading the bar as out of session.
15+
- A failed `setenv` or a memory failure during a timezone switch now fails the run instead of continuing in the previous zone or in UTC.
16+
- A timezone name written in a script that the engine does not accept now raises `pine_timezone_error` with the function and zone instead of silently reading UTC. This addition to the public failure catalog requires a minor release. The message is TradingView's text with the engine's bar prefix, `Error on bar N: `, or `Error before the first bar: ` when no bar is being executed, and the arguments carry `bar_index`.
17+
- The void C setters for instrument and run settings now record exceptions on
18+
the handle, including allocation failures and changes refused by the engine.
19+
`strategy_last_run_status` reads 1; `strategy_get_last_error` and
20+
`strategy_get_last_error_code` return the failure text and code.
21+
The recorded text begins "Error before the first bar: " (or "Error on bar N: "
22+
when a bar is being executed). A setup failure makes the next run start fail
23+
once with that record; the following start clears it and starts normally.
24+
The failed setter did not apply its value, so retrying the start without
25+
reapplying the setter uses the previous value. The documented refusal of a
26+
quote write after a selected run has sealed is still dropped silently and
27+
read through `strategy_state_query_status_v1`.
28+
- Non-positive or NaN `mintick` or `pointvalue` values in `--syminfo`, and
29+
`path_order` modes outside 0, 1 and 2, now produce typed refusals instead of
30+
being ignored or reset to AUTO. Invalid point values use the existing symbol
31+
metadata error.
1532
- A percent-of-equity default quantity above 100 percent is now capped at 100 percent of equity when `margin_long` and `margin_short` are both 0 (#805).
1633
- With `process_orders_on_close` and the default FIFO close rule, the named `strategy.exit` calls of a reversing `strategy.entry` with an explicit quantity, placed in the same execution after a `strategy.close` of the old position, are now sized from the new entry's own quantity: a percentage exit takes its share of the new entry and an absolute-quantity exit keeps its quantity, instead of being sized from a basis reduced by the old position (#803).
1734
- Without `process_orders_on_close`, the named `strategy.exit` calls placed with a reversing `strategy.entry` of explicit quantity now take their percentage from the new entry when its size differs from the position it replaces, and a take-profit given as an absolute quantity now fires; before, the percentage was taken from the position being replaced and an absolute-quantity take-profit never fired (#803).

‎ci/cr150-source-bounds.yaml‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ ceilings:
103103
# Two more unreviewed groups: the declarations of the run-error bar prefix
104104
# function, in the installed header and in its source. Each call returns one
105105
# short string and nothing retains it: 1413 -> 1415.
106-
unreviewed: 1415
106+
# Three more unreviewed groups on failure paths: the number-to-text
107+
# temporaries of the three setter refusal messages in the engine header, and
108+
# the message string and its temporary in the timezone refusal. Each builds
109+
# one short message, once, when a value is refused: 1415 -> 1418.
110+
unreviewed: 1418
107111
pending-flat-memory: 184
108112
owners:
109113
- {name: "generated-cpp", globs: ["tutorial/**"]}
@@ -228,6 +232,7 @@ entries:
228232
- {id: "U0082", file: "include/pineforge/engine.hpp", symbol: "security_eval_states_", ops: ["decl"], container: "std::vector<SecurityEvalState>", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 1484}
229233
- {id: "U0083", file: "include/pineforge/engine.hpp", symbol: "security_input_tf_", ops: ["decl"], container: "std::string", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 1487}
230234
- {id: "U0084", file: "include/pineforge/engine.hpp", symbol: "session", ops: ["assign", "decl"], container: "std::string", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 483}
235+
- {id: "U1850", file: "include/pineforge/engine.hpp", symbol: "std::to_string", ops: ["temp"], container: "unresolved by the index: std::to_string(...)", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 2396}
231236
- {id: "U0085", file: "include/pineforge/engine.hpp", symbol: "stream_order_actions_", ops: ["decl"], container: "std::vector<StreamOrderAction>", owner: "engine-core", phase: "bar", state: "pending-flat-memory", inventory: "E17", grows_with: ["unproved-bound"], line: 1452}
232237
- {id: "U0086", file: "include/pineforge/engine.hpp", symbol: "syminfo_metadata_", ops: ["decl"], container: "std::unordered_map<std::string, double>", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 676}
233238
- {id: "U0087", file: "include/pineforge/engine.hpp", symbol: "tf", ops: ["decl"], container: "std::string", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 1457}
@@ -1279,7 +1284,9 @@ entries:
12791284
- {id: "U1507", file: "src/timeframe.cpp", symbol: "starts", ops: ["decl"], container: "std::vector<int>", owner: "calendar-time", phase: "unclassified", state: "unreviewed", note: "CR150-CX 10-26 (c171d), class: scratch of one call. Local in SessionDaySchedule::parse_many (more than 8 windows only): sized by the number of windows in ONE session string, an input value; freed on return; nothing is retained across bars. Bound not argued, so OPEN.", line: 1930}
12801285
- {id: "U1183", file: "src/timeframe.cpp", symbol: "trade_instants", ops: ["decl"], container: "std::vector<int64_t>", owner: "calendar-time", phase: "unclassified", state: "unreviewed", line: 1770}
12811286
- {id: "U1184", file: "src/timeframe.cpp", symbol: "tz", ops: ["assign", "decl"], container: "std::string", owner: "calendar-time", phase: "unclassified", state: "unreviewed", note: "Partition setup copies the caller timezone into one p.tz string in the explicit-cache overload. Payload length follows the input string, with no proved byte cap; other timezone declarations stay inventoried.", line: 200}
1287+
- {id: "U1851", file: "src/timezone.cpp", symbol: "<temp:string>", ops: ["temp"], container: "unresolved by the index: std::string", owner: "calendar-time", phase: "unclassified", state: "unreviewed", line: 83}
12821288
- {id: "U1186", file: "src/timezone.cpp", symbol: "body", ops: ["decl"], container: "std::string", owner: "calendar-time", phase: "unclassified", state: "unreviewed", line: 71}
1289+
- {id: "U1852", file: "src/timezone.cpp", symbol: "english", ops: ["decl"], container: "std::string", owner: "calendar-time", phase: "unclassified", state: "unreviewed", line: 83}
12831290
- {id: "U1188", file: "src/timezone.cpp", symbol: "hour_s", ops: ["assign", "decl"], container: "std::string", owner: "calendar-time", phase: "unclassified", state: "unreviewed", line: 72}
12841291
- {id: "U1189", file: "src/timezone.cpp", symbol: "minute_s", ops: ["assign", "decl"], container: "std::string", owner: "calendar-time", phase: "unclassified", state: "unreviewed", line: 73}
12851292
- {id: "U1190", file: "src/timezone.cpp", symbol: "normalize_timezone_for_posix", ops: ["decl"], container: "std::string", owner: "calendar-time", phase: "unclassified", state: "unreviewed", line: 50}

0 commit comments

Comments
 (0)