fix(p2): name the TUI bundle with a sourceURL so stack traces stay small

The sandbox imports the bundle from a data: URL, which put the whole base64
bundle (~1.4 MB) into every stack frame. Chord formats a released reference's
error stack, so /agents -> subagent and /clone exhausted the worker's 96 MB heap.
This commit is contained in:
David Brailovsky 2026-11-04 23:15:05 +01:00
parent 3a7bb6f48c
commit 4bb837c960

View file

@ -65,7 +65,11 @@ port.on("message", async (message) => {
}
});
// Owner-approved dynamic import: the single self-contained server bundle is evaluated only from memory.
const bundle = await import(`data:text/javascript;base64,${Buffer.from(source).toString("base64")}`);
// The sourceURL names its frames: a data: URL would put the whole base64 bundle (megabytes) into every stack frame,
// and formatting one stack (Chord makes a released reference's error stack text at once) exhausts the worker heap.
const bundle = await import(
`data:text/javascript;base64,${Buffer.from(`${source}\n//# sourceURL=p2-tui-bundle.mjs\n`).toString("base64")}`
);
await bundle.default({
input,
send,