Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/openclaw/check-stack-visitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python3
"""Pin the live stack visitor to the same call tokens as captured stacks."""
import json
import re
import subprocess
import sys
from pathlib import Path

fixture = Path(__file__).with_name("qualification") / "stack-visitor.js"
expected = [(1, 22), (2, 21), (3, 1)]
for mode, flags in [("default", []), ("interpreter", ["--useJIT=false"])]:
result = subprocess.run([sys.argv[1], *flags, str(fixture)], capture_output=True, text=True, check=True)
actual = [(int(line), int(column)) for line, column in re.findall(r"stack-visitor\.js:(\d+):(\d+)", result.stderr)]
if actual != expected:
raise SystemExit(f"{mode}: expected {expected}, got {actual}\n{result.stderr}")
print(json.dumps({"mode": mode, "positions": actual, "passed": True}))
1,342 changes: 1,342 additions & 0 deletions .github/openclaw/qualification/patches/009-stack-positions.patch

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .github/openclaw/qualification/stack-visitor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function witness() { jscStack(); }
function parent() { witness(); }
parent();
2 changes: 2 additions & 0 deletions .github/openclaw/qualify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ for arm in baseline candidate; do
git apply --exclude=CHANGELOG.md --exclude='docs/*' --exclude='test/js/node/worker_threads/*' "$patch"
done
git apply --exclude=CHANGELOG.md --exclude='docs/*' "$inputs/patches/008-namespace.patch"
git apply --exclude=CHANGELOG.md --exclude='docs/*' "$inputs/patches/009-stack-positions.patch"
cp "$inputs/worker-resource-limits.test.ts" test/js/node/worker_threads/openclaw-resource-limits.test.ts
git diff --check
git diff --binary HEAD > "$QUALIFICATION_DIR/bun-adapters.patch"
Expand Down Expand Up @@ -60,6 +61,7 @@ python3 "$inputs/compare-fork-ci.py" "$QUALIFICATION_DIR/baseline" "$QUALIFICATI
candidate="$QUALIFICATION_DIR/bun/build/qualify-candidate/bun"
unset BUN_WEBKIT_ARTIFACT_MANIFEST BUN_BUILD_CACHE_DIR BUN_BUILD_PREFETCH_DIR
"$candidate" test test/js/bun/resolve/esModule.test.ts test/js/bun/namespace-prototype-pollution.test.ts test/js/bun/resolve/require-esm-evaluating-cycle.test.ts test/js/bun/import-attributes/import-attributes.test.ts test/js/node/module/require-extensions.test.ts > "$QUALIFICATION_DIR/namespace.log" 2>&1
"$candidate" test --expose-internals test/js/node/v8/capture-stack-trace.test.js test/js/bun/sourcemap/internal-sourcemap.test.ts > "$QUALIFICATION_DIR/stack-positions.log" 2>&1
"$candidate" "$inputs/segmenter.js" > "$QUALIFICATION_DIR/segmenter.log" 2>&1
"$candidate" test test/js/node/vm/vm.test.ts -t 'a Proxy in the prototype chain' > "$QUALIFICATION_DIR/proxy.log" 2>&1
"$candidate" test test/js/node/worker_threads/openclaw-resource-limits.test.ts -t 'resourceLimits' > "$QUALIFICATION_DIR/resource-limits.log" 2>&1
Expand Down
41 changes: 41 additions & 0 deletions .github/openclaw/test_verify_jsc_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
import json
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path

SCRIPT = Path(__file__).with_name("verify-jsc-results.py")


class JSCResultTests(unittest.TestCase):
def run_check(self, rows, *args):
with tempfile.TemporaryDirectory() as directory:
(Path(directory) / "results").write_text("\n".join(rows))
return subprocess.run([sys.executable, str(SCRIPT), directory, *args], capture_output=True, text=True)

def test_default_requires_namespace(self):
self.assertNotEqual(self.run_check(["stress/another.js.default: PASS"]).returncode, 0)
result = self.run_check(["stress/module-namespace-esmodule-marker.js.default: PASS"])
self.assertEqual(result.returncode, 0, result.stderr)

def test_all_requested_regressions_must_execute(self):
result = self.run_check(["stress/callsite.js.default: PASS"], "--require", "callsite.js", "--require", "property.js")
self.assertNotEqual(result.returncode, 0)
self.assertIn("property.js", result.stderr)

def test_any_failed_configuration_rejects_results(self):
result = self.run_check(["stress/callsite.js.default: PASS", "stress/callsite.js.ftl-eager: FAIL"], "--require", "callsite.js")
self.assertNotEqual(result.returncode, 0)
self.assertIn("ftl-eager: FAIL", result.stderr)
self.assertNotEqual(self.run_check([], "--require", "callsite.js").returncode, 0)

def test_reports_all_passing_variants(self):
result = self.run_check(["stress/callsite.js.default: PASS", "stress/callsite.js.ftl-eager: PASS", "stress/property.js.default: PASS"], "--require", "callsite.js", "--require", "property.js")
self.assertEqual(result.returncode, 0, result.stderr)
self.assertEqual(json.loads(result.stdout), {"tests": 3, "required_variants": {"callsite.js": 2, "property.js": 1}, "passed": True})


if __name__ == "__main__":
unittest.main()
18 changes: 12 additions & 6 deletions .github/openclaw/verify-jsc-results.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#!/usr/bin/env python3
"""The stress runner's results file, not its exit status, is authoritative."""
import argparse
import json
import sys
from pathlib import Path

root = Path(sys.argv[1])
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("root", type=Path)
parser.add_argument("--require", action="append", dest="required", help="Regression filename that must execute (repeatable)")
args = parser.parse_args()
root = args.root
lines = (root / "results").read_text().splitlines()
if not lines:
raise SystemExit("JSC produced no test results")
namespace = [line for line in lines if "module-namespace-esmodule-marker.js" in line]
if not namespace:
raise SystemExit("The namespace marker regression did not execute")
required = args.required or ["module-namespace-esmodule-marker.js"]
variants = {name: sum(name in line for line in lines) for name in required}
missing = [name for name, count in variants.items() if not count]
if missing:
raise SystemExit("JSC regressions did not execute: " + ", ".join(missing))
failures = [line for line in lines if not line.endswith(": PASS")]
if failures:
raise SystemExit("JSC failures:\n" + "\n".join(failures))
print(json.dumps({"tests": len(lines), "marker_variants": len(namespace), "passed": True}))
print(json.dumps({"tests": len(lines), "required_variants": variants, "passed": True}))
14 changes: 14 additions & 0 deletions .github/workflows/openclaw-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
- name: Verify pipeline integrity and runner support
run: |
python3 .github/openclaw/test_release.py
python3 .github/openclaw/test_verify_jsc_results.py
bash .github/openclaw/preflight.sh
- name: Build native Linux engine with the unchanged lane
env:
Expand All @@ -60,6 +61,17 @@ jobs:
"$RUNNER_TEMP/jsc-artifact/bun-webkit/bin/jsc" --useDollarVM=1 -e 'if (typeof $vm.moduleNamespaceForRequire !== "function") throw new Error("namespace test hook is missing");'
Tools/Scripts/run-jsc-stress-tests JSTests/stress --jsc "$RUNNER_TEMP/jsc-artifact/bun-webkit/bin/jsc" --child-processes 16 --filter 'module-namespace|module-loader-security-thenable-namespace' --output-dir "$RUNNER_TEMP/jsc-results" --no-retry
python3 .github/openclaw/verify-jsc-results.py "$RUNNER_TEMP/jsc-results"
- name: Exercise syntax-selected stack positions
shell: bash
run: |
set -euo pipefail
jsc="$RUNNER_TEMP/jsc-artifact/bun-webkit/bin/jsc"
Tools/Scripts/run-jsc-stress-tests JSTests/stress --jsc "$jsc" --child-processes 16 --filter 'callsite-syntax-positions|stack-position-regressions' --output-dir "$RUNNER_TEMP/stack-results" --no-retry
python3 .github/openclaw/verify-jsc-results.py "$RUNNER_TEMP/stack-results" --require callsite-syntax-positions.js --require stack-position-regressions.js
python3 .github/openclaw/check-stack-visitor.py "$jsc"
"$jsc" -m JSTests/stress/callsite-async-position.mjs
"$jsc" --useJIT=false -m JSTests/stress/callsite-async-position.mjs
"$jsc" --useBytecodeOptimizer=true -m JSTests/stress/callsite-async-position.mjs
- name: Exercise allocation sampling across execution tiers
shell: bash
run: |
Expand Down Expand Up @@ -91,5 +103,7 @@ jobs:
${{ runner.temp }}/qualification/candidate/*.log
${{ runner.temp }}/jsc-results/results
${{ runner.temp }}/jsc-results/*.log
${{ runner.temp }}/stack-results/results
${{ runner.temp }}/stack-results/*.log
if-no-files-found: error
retention-days: 7
12 changes: 12 additions & 0 deletions JSTests/stress/callsite-async-position.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
async function leaf() {
await Promise.resolve();
return new Error().stack;
}
async function parent() {
return await leaf();
}
const trace = await parent();
const parentFrame = trace.split("\n").find(line => /\bparent(?:\s|@|\()/.test(line));
const position = /:(\d+):(\d+)\)?$/.exec(parentFrame);
if (!position || +position[1] !== 6 || +position[2] !== 8)
throw new Error(JSON.stringify({ expected: [6, 8], trace }));
116 changes: 116 additions & 0 deletions JSTests/stress/callsite-syntax-positions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Keep call positions independent of exception-expression divots.
let trace;
function capture() { const stack = new Error().stack; trace = stack; return stack; }
function Capture() { this.stack = new Error().stack; trace = this.stack; }
function factory() { return capture; }
const object = { capture };
const name = "capture";
const cases = [
[function () {
capture()
}, 10, 1, "capture()"],
[function () {
capture /* comment */ ()
}, 13, 1, "capture /* comment */ ()"],
[function () {
capture
()
}, 16, 1, "capture\n()"],
[function () {
factory()()
}, 20, 10, "factory()()"],
[function () {
factory()
()
}, 24, 1, "factory()\n()"],
[function () {
factory() /* comment */ ()
}, 27, 25, "factory() /* comment */ ()"],
[function () {
object.capture()
}, 30, 8, "object.capture()"],
[function () {
object
.capture()
}, 34, 2, "object\n.capture()"],
[function () {
object . capture()
}, 37, 10, "object . capture()"],
[function () {
object. /* comment */ capture()
}, 40, 23, "object. /* comment */ capture()"],
[function () {
object.\u0063apture()
}, 43, 8, "object.\\u0063apture()"],
[function () {
object[name]()
}, 46, 13, "object[name]()"],
[function () {
object["capture"]()
}, 49, 18, "object[\"capture\"]()"],
[function () {
object[
name
]
()
}, 55, 1, "object[\nname\n]\n()"],
[function () {
(capture)()
}, 58, 10, "(capture)()"],
[function () {
((capture))()
}, 61, 12, "((capture))()"],
[function () {
(object.capture)()
}, 64, 17, "(object.capture)()"],
[function () {
(object[name])()
}, 67, 15, "(object[name])()"],
[function () {
(0, capture)()
}, 70, 13, "(0, capture)()"],
[function () {
capture?.()
}, 73, 10, "capture?.()"],
[function () {
object?.capture()
}, 76, 9, "object?.capture()"],
[function () {
object.capture?.()
}, 79, 17, "object.capture?.()"],
[function () {
object?.capture?.()
}, 82, 18, "object?.capture?.()"],
[function () {
this()
}, 85, 5, "this()"],
[function () {
capture`text`
}, 88, 8, "capture`text`"],
[function () {
Reflect.apply(capture, null, [])
}, 91, 9, "Reflect.apply(capture, null, [])"],
[function () {
new Capture().stack
}, 94, 1, "new Capture().stack"],
[function () {
new
Capture().stack
}, 97, 1, "new\nCapture().stack"],
[function () {
new (Capture)().stack
}, 101, 1, "new (Capture)().stack"],
[function () {
Reflect.construct(Capture, []).stack
}, 104, 9, "Reflect.construct(Capture, []).stack"],
];
for (let iteration = 0; iteration < Math.min(typeof testLoopCount === "number" ? testLoopCount : 20, 100); ++iteration) {
for (const [fn, line, column, body] of cases) {
trace = "";
fn.call(capture);
const frames = trace.split("\n").filter(line => /:(\d+):(\d+)\)?$/.test(line));
const position = /:(\d+):(\d+)\)?$/.exec(frames[1]);
if (!position || +position[1] !== line || +position[2] !== column)
throw new Error(JSON.stringify({ body, expected: [line, column], trace }));
}
}
104 changes: 104 additions & 0 deletions JSTests/stress/stack-position-regressions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
"use strict";
const name = "x";
const cases = [
['Error', function () {
const error = new Error("test"); return error;
}, 5, 15],
['TypeError', function () {
const error = new TypeError("test"); return error;
}, 8, 15],
['SyntaxError', function () {
const error = new SyntaxError("test"); return error;
}, 11, 15],
['RangeError', function () {
const error = new RangeError("test"); return error;
}, 14, 15],
['ReferenceError', function () {
const error = new ReferenceError("test"); return error;
}, 17, 15],
['EvalError', function () {
const error = new EvalError("test"); return error;
}, 20, 15],
['URIError', function () {
const error = new URIError("test"); return error;
}, 23, 15],
['AggregateError', function () {
const error = new AggregateError([], "test"); return error;
}, 26, 15],
['arrow-new', () => new Error("arrow"), 28, 25],
['arrow-type', () => new TypeError("arrow"), 29, 26],
['arrow-alias', () => new globalThis.Error("arrow"), 30, 27],
['multiline-new', function () {
const error = new
Error("multiline"); return error;
}, 32, 15],
['constructor-comment', function () {
const error = new /* comment */ Error("comment"); return error;
}, 36, 15],
['null-dot', function () {
try { null.x; } catch (error) { return error; }
}, 39, 12],
['undefined-dot', function () {
try { undefined.x; } catch (error) { return error; }
}, 42, 17],
['null-length', function () {
try { null.length; } catch (error) { return error; }
}, 45, 12],
['null-comment', function () {
try { null . /* comment */ x; } catch (error) { return error; }
}, 48, 28],
['null-escape', function () {
try { null.\u0078; } catch (error) { return error; }
}, 51, 12],
['null-multiline', function () {
try { null
.x; } catch (error) { return error; }
}, 55, 6],
['null-bracket', function () {
try { null["x"]; } catch (error) { return error; }
}, 58, 11],
['null-number', function () {
try { null[1]; } catch (error) { return error; }
}, 61, 11],
['null-computed', function () {
try { null[name]; } catch (error) { return error; }
}, 64, 11],
['null-call', function () {
try { null.x(); } catch (error) { return error; }
}, 67, 12],
['null-parenthesized-call', function () {
try { (null.x)(); } catch (error) { return error; }
}, 70, 13],
['null-bracket-call', function () {
try { null["x"](); } catch (error) { return error; }
}, 73, 11],
['null-call-method', function () {
try { null.call(); } catch (error) { return error; }
}, 76, 12],
['null-apply-method', function () {
try { null.apply(null, []); } catch (error) { return error; }
}, 79, 12],
['null-has-own', function () {
try { null.hasOwnProperty(name); } catch (error) { return error; }
}, 82, 12],
];
function checkPosition(error, line, column, shape, structured) {
const frames = structured ? error.stack : error.stack.split("\n").filter(frame => /:(\d+):(\d+)\)?$/.test(frame));
const actual = structured ? [frames[0].getLineNumber(), frames[0].getColumnNumber()] : /:(\d+):(\d+)\)?$/.exec(frames[0])?.slice(1).map(Number);
if (!actual || actual[0] !== line || actual[1] !== column)
throw new Error(JSON.stringify({ shape, structured, expected: [line, column], actual, trace: structured ? frames.map(String) : error.stack }));
}
for (let iteration = 0; iteration < Math.min(typeof testLoopCount === "number" ? testLoopCount : 20, 100); ++iteration) {
for (const [shape, create, line, column] of cases) {
checkPosition(create(), line, column, shape, false);
if (typeof process !== "undefined") {
const previous = Error.prepareStackTrace;
try {
Error.prepareStackTrace = (_, frames) => frames;
checkPosition(create(), line, column, shape, true);
} finally {
Error.prepareStackTrace = previous;
}
}
}
}
8 changes: 8 additions & 0 deletions OPENCLAW.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,13 @@ entrypoint.

## Unreleased

- Keep syntax-selected stack positions separate from exception ranges for calls, constructors, property reads, and async continuations. Preserve the positions across bytecode rewriting, optimization, and cache replay.

- Add real byte-based JSC heap allocation sampling with weighted allocating-stack profiles and independent major/minor collection inclusion.
- Check allocation sampling across interpreter and JIT tiers before merging engine pull requests.

## Stack positions

`CodeBlock::callSitePositionForBytecodeIndex` returns an optional absolute source offset for an exact instruction or async resume label. Stack readers use this position while exception expression ranges and debugger line tables retain their existing divots. RareData owns the two sparse vectors, including decoded cache entries; the bytecode cache revision prevents older layouts from being reused.

Bun must be rebuilt with its matching stack-reader adapter. It must also preserve built-in error constructor syntax: rewriting `new Error()` as `Error()` changes the position and allows a returning arrow to become a proper tail call. The engine's proper-tail-call behavior is unchanged. The integration continues @robobun’s upstream Bun source-position work in [#35179](https://github.com/oven-sh/bun/pull/35179), [#37396](https://github.com/oven-sh/bun/pull/37396), and [#41580](https://github.com/oven-sh/bun/pull/41580).
Loading