Skip to content

Commit cdb8ae8

Browse files
luisleo526claude
andauthored
Fail the run when str.match or a calendar lookup meets a memory failure (#831)
str.match returned the empty string after any exception it met, and the four session-calendar lookups of the native path (the entry session point, the risk day, and the day and ordinal reads of the C callback host) answered "out of session" or "no day" after any exception. A memory failure, or a regular-expression resource limit, therefore let a run finish with a wrong result instead of failing. A std::bad_alloc now reaches the run's out_of_memory failure (status 1). Container length errors and the system errors that mean "out of memory or resources" carry the same code. Every other exception keeps its fallback. The regex library's error_space, error_complexity and error_stack depend only on the pattern and the input, never on memory, so they are not out_of_memory and not retryable: they stop the run with pine_string_error and the new reason regex_resource_limit. One inline function maps the 13 standard error codes to that outcome or to an invalid pattern. An invalid regular expression now stops the run with pine_string_error (reason invalid_regex_pattern), as TradingView does, instead of returning an empty string. Patterns the engine's regular-expression library does not support stop the run too, with the same error; on the Linux build these include lookbehind, named groups, inline flags, comment groups, atomic groups, conditionals, \p{...} classes and {,n} repeats. 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; one function, run_error_bar_prefix, builds the prefix from the ambient bar context. The catalog gains the two reasons and their message templates; its diff reads one changed entry, so a release that carries this change is a minor one. 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 the out_of_memory 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. They fail on the base tree at the allocations the old code swallowed. The table of the 13 regex error codes is its own small test: a one-line change of the mapping turns the expected rows red. docs/coverage.md: the pine_str_match row replaces the sentence "Empty string on no match or regex error." (introduced by cc4a56e) because an invalid pattern now stops the run instead of returning an empty string. ADR-0001 gets one row for the kernel's literal of TradingView's invalid-pattern text, which the residuals gate requires for a text that spells a Pine namespace, and the two pinned phrase counts of its unit tests move by one. The allocation-bound manifest lists the two declarations of the new function (ceiling 1413 -> 1415, pinned count 1597 -> 1599) and its site inventory is re-emitted. 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, no sentence changes). ADR-0001: give pine_string_stop a row of its own. The kernel's two regular-expression stop helpers in src/str_utils.cpp call pine_string_stop, so libpineforge_kernel.a now carries its weak symbol. The ADR still listed it among the codegen helpers marked "no archive symbol", and the kernel-residuals check on the built archive rejects that (hosted build-arm, ctest row test_kernel_residuals: "unruled 'pine_string_stop': ruled for the installed headers only ... but nm carries it"). The helper moves out of that row into a row of its own that says the kernel calls it; the other helpers keep their row. Only docs/adr/0001-kernel-adapter-boundary.md changes. The check that failed is the one that runs on the real archive, which the static preflight and the checker's own self-tests do not build. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 360c4ab commit cdb8ae8

33 files changed

Lines changed: 1814 additions & 255 deletions

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ version number follows semantic versioning over the surfaces the
77

88
## Unreleased
99

10+
- `str.match` no longer reports "no match" after a memory failure; the failure now reaches `out_of_memory`.
11+
A pattern over the limits of the engine's regular-expression library stops the run with `pine_string_error` and reason `regex_resource_limit`, which is not retryable.
12+
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.
13+
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.
14+
- 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.
1015
- 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).
1116
- 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).
1217
- 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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ ceilings:
100100
# Three more unreviewed groups: the selected-capacity Source stage's chunk
101101
# buffer, its record window and its stored message. None is bounded in the
102102
# gate's sense: no fixed input is declared for them.
103-
unreviewed: 1413
103+
# Two more unreviewed groups: the declarations of the run-error bar prefix
104+
# function, in the installed header and in its source. Each call returns one
105+
# short string and nothing retains it: 1413 -> 1415.
106+
unreviewed: 1415
104107
pending-flat-memory: 184
105108
owners:
106109
- {name: "generated-cpp", globs: ["tutorial/**"]}
@@ -362,6 +365,7 @@ entries:
362365
- {id: "U0230", file: "include/pineforge/order_cancellation.hpp", symbol: "state_", ops: ["assign"], container: "unresolved by the index: state_ = ...", owner: "native-kernel", phase: "unclassified", state: "unreviewed", line: 92}
363366
- {id: "U0231", file: "include/pineforge/position_close_obligation.hpp", symbol: "comment", ops: ["decl"], container: "std::string", owner: "native-kernel", phase: "unclassified", state: "unreviewed", line: 15}
364367
- {id: "U0232", file: "include/pineforge/run_failure.hpp", symbol: "args", ops: ["assign", "decl", "grow"], container: "std::shared_ptr<const std::string>", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 216}
368+
- {id: "U1800", file: "include/pineforge/run_failure.hpp", symbol: "run_error_bar_prefix", ops: ["decl"], container: "std::string", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 252}
365369
- {id: "U0233", file: "include/pineforge/run_failure.hpp", symbol: "text", ops: ["assign", "decl"], container: "std::string", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 180}
366370
- {id: "U0234", file: "include/pineforge/run_failure.hpp", symbol: "value", ops: ["decl"], container: "std::string", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 187}
367371
- {id: "U0235", file: "include/pineforge/selected_window_plan.hpp", symbol: "input_tf", ops: ["decl"], container: "std::string", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 88}
@@ -852,6 +856,7 @@ entries:
852856
- {id: "U0744", file: "src/run_failure.cpp", symbol: "json", ops: ["alloc", "append", "decl", "grow"], container: "unresolved by the index: make_shared", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 249}
853857
- {id: "U0745", file: "src/run_failure.cpp", symbol: "matched", ops: ["decl", "grow"], container: "std::vector<std::pair<const RegistryArg*, const RunFailureArg*>>", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 176}
854858
- {id: "U0746", file: "src/run_failure.cpp", symbol: "out", ops: ["grow"], container: "unresolved by the index: out.push_back(...)", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 120}
859+
- {id: "U1801", file: "src/run_failure.cpp", symbol: "run_error_bar_prefix", ops: ["decl"], container: "std::string", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 408}
855860
- {id: "U0747", file: "src/run_failure.cpp", symbol: "std::to_string", ops: ["temp"], container: "unresolved by the index: std::to_string(...)", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 259}
856861
- {id: "U0748", file: "src/run_failure.cpp", symbol: "text", ops: ["append", "decl"], container: "std::string", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 318}
857862
- {id: "U0749", file: "src/selected_report_view.cpp", symbol: "points", ops: ["alloc"], container: "unresolved by the index: new pf_equity_point_t", owner: "engine-core", phase: "unclassified", state: "unreviewed", line: 54}

‎ci/cr150-source-sites.json‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8414,6 +8414,16 @@
84148414
"spelling": "std :: shared_ptr < const std :: string >",
84158415
"ordinal": 1
84168416
},
8417+
{
8418+
"file": "include/pineforge/run_failure.hpp",
8419+
"symbol": "run_error_bar_prefix",
8420+
"scope": [
8421+
"namespace pineforge #1"
8422+
],
8423+
"cls": "decl",
8424+
"spelling": "std :: string",
8425+
"ordinal": 1
8426+
},
84178427
{
84188428
"file": "include/pineforge/run_failure.hpp",
84198429
"symbol": "<temp:Base>",
@@ -27346,6 +27356,27 @@
2734627356
"spelling": "json . push_back ( . . . )",
2734727357
"ordinal": 2
2734827358
},
27359+
{
27360+
"file": "src/run_failure.cpp",
27361+
"symbol": "run_error_bar_prefix",
27362+
"scope": [
27363+
"namespace pineforge #1"
27364+
],
27365+
"cls": "decl",
27366+
"spelling": "std :: string",
27367+
"ordinal": 1
27368+
},
27369+
{
27370+
"file": "src/run_failure.cpp",
27371+
"symbol": "std::to_string",
27372+
"scope": [
27373+
"namespace pineforge #1",
27374+
"std :: string run_error_bar_prefix ( ) #1"
27375+
],
27376+
"cls": "temp",
27377+
"spelling": "std :: to_string ( . . . )",
27378+
"ordinal": 1
27379+
},
2734927380
{
2735027381
"file": "src/run_failure.cpp",
2735127382
"symbol": "text",

‎docker/run_failure_codes.json‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,15 +835,19 @@
835835
"kind": "vocab",
836836
"values": [
837837
"substring_out_of_range",
838-
"format_index_overflow"
838+
"format_index_overflow",
839+
"invalid_regex_pattern",
840+
"regex_resource_limit"
839841
]
840842
}
841843
},
842844
"class": "strategy",
843845
"description": "A string built-in refused its arguments.",
844846
"english": [
845847
"basic_string::substr: __pos (which is {pos}) > this->size() (which is {size})",
846-
"stoul"
848+
"stoul",
849+
"Invalid regex pattern in the 'str.match' function.",
850+
"A regular expression exceeds the limits of the engine's regular-expression library."
847851
],
848852
"retryable": false,
849853
"since": "1.4.0"

‎docker/run_failure_codes_diff.json‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,52 @@
88
"to": {
99
"version": null,
1010
"unreleased": true,
11-
"catalogSha256": "7e903f977be655901c877a3550008aeee19b7f69a9ecfad986ca6f0d9129c3be"
11+
"catalogSha256": "440a8f9899a8bdbdff8a3e0f7e1c236854d469cbb05f7af542b0d392646330ab"
1212
},
1313
"catalogSchema": {
1414
"before": "pineforge-run-failure-catalog/v1",
1515
"after": "pineforge-run-failure-catalog/v1"
1616
},
1717
"metadataChanges": [],
1818
"added": [],
19-
"changed": [],
19+
"changed": [
20+
{
21+
"code": "pine_string_error",
22+
"collection": "codes",
23+
"fields": [
24+
{
25+
"path": "args.reason.values",
26+
"beforePresent": true,
27+
"afterPresent": true,
28+
"before": [
29+
"substring_out_of_range",
30+
"format_index_overflow"
31+
],
32+
"after": [
33+
"substring_out_of_range",
34+
"format_index_overflow",
35+
"invalid_regex_pattern",
36+
"regex_resource_limit"
37+
]
38+
},
39+
{
40+
"path": "english",
41+
"beforePresent": true,
42+
"afterPresent": true,
43+
"before": [
44+
"basic_string::substr: __pos (which is {pos}) > this->size() (which is {size})",
45+
"stoul"
46+
],
47+
"after": [
48+
"basic_string::substr: __pos (which is {pos}) > this->size() (which is {size})",
49+
"stoul",
50+
"Invalid regex pattern in the 'str.match' function.",
51+
"A regular expression exceeds the limits of the engine's regular-expression library."
52+
]
53+
}
54+
]
55+
}
56+
],
2057
"removed": [],
2158
"deprecated": []
2259
}

0 commit comments

Comments
 (0)