The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
fix(relay): parse Hermes stack frames in linear time (#39498)
Julius Marminge committed
Nov 19, 2026 at 19:47 UTC
badd5f6d1841e5b76fa29a2274dedf861d39029b
1 file changed
+37
-11
infra/relay/src/mobileTelemetry/sourceMap.ts
+37
-11
@@ -225,7 +225,34 @@ function originalPositionFor(
225
* the composed map's generated column. On iOS the path is absolute, and an OTA bundle's
226
* contains a space (`Application Support`).
227
*/
228
-const BUNDLE_FRAME = /address at (.+?):(\d+):(\d+)(?=\)?$)/u;
228
+const FRAME_MARKER = "address at ";
229
+const FRAME_POSITION = /:(\d+):(\d+)\)?$/u;
230
+
231
+/**
232
+ * One anchored match and a few scans instead of `/address at (.+?):(\d+):(\d+)(?=\)?$)/`, which
233
+ * retries from every marker and is quadratic on a line of them. Telemetry is unauthenticated.
234
+ */
235
+function bundleFrame(line: string) {
236
+ const position = FRAME_POSITION.exec(line);
237
+ if (!position) return null;
238
+ // `.` stops at these, so a path never spans one.
239
+ const lineBreak = Math.max(
240
+ line.lastIndexOf("\r", position.index),
241
+ line.lastIndexOf("\u2028", position.index),
242
+ line.lastIndexOf("\u2029", position.index),
243
+ );
244
+ const index = line.indexOf(FRAME_MARKER, lineBreak + 1);
245
+ const pathStart = index + FRAME_MARKER.length;
246
+ if (index === -1 || pathStart >= position.index) return null;
247
+ return {
248
+ index,
249
+ path: line.slice(pathStart, position.index),
250
+ line: Number(position[1]),
251
+ column: Number(position[2]),
252
+ /** After the column, before a closing parenthesis. */
253
+ end: line.length - (line.endsWith(")") ? 1 : 0),
254
+ };
255
+}
256
/** Hermes's own runtime, not in the map. */
257
const HERMES_RUNTIME = "InternalBytecode.js";
258
@@ -236,10 +263,10 @@ export function stripBundlePaths(stack: string): string {
263
return stack
264
.split("\n")
265
.map((line) => {
239
- const match = BUNDLE_FRAME.exec(line);
240
- if (!match || !match[1]!.includes("/")) return line;
241
- const start = match.index + "address at ".length;
242
- return line.slice(0, start) + baseName(match[1]!) + line.slice(start + match[1]!.length);
266
+ const frame = bundleFrame(line);
267
+ if (!frame || !frame.path.includes("/")) return line;
268
+ const start = frame.index + FRAME_MARKER.length;
269
+ return line.slice(0, start) + baseName(frame.path) + line.slice(start + frame.path.length);
270
})
271
.join("\n");
272
}
@@ -265,14 +292,14 @@ export function symbolicateStack(
292
let growth = 0;
293
let exhausted = false;
294
const lines = stack.split("\n").map((line) => {
268
- const match = BUNDLE_FRAME.exec(line);
269
- if (!match || baseName(match[1]!) === HERMES_RUNTIME) return line;
295
+ const frame = bundleFrame(line);
296
+ if (!frame || baseName(frame.path) === HERMES_RUNTIME) return line;
297
bundleFrames += 1;
298
if (exhausted) return line;
272
- const position = originalPositionFor(map, Number(match[2]), Number(match[3]));
299
+ const position = originalPositionFor(map, frame.line, frame.column);
300
if (!position) return line;
301
const lineAndColumn = `:${position.line}:${position.column + 1}`;
275
- const added = position.source.length + lineAndColumn.length - match[0].length;
302
+ const added = position.source.length + lineAndColumn.length - (frame.end - frame.index);
303
if (growth + added > maxGrowth) {
304
exhausted = true;
305
return line;
@@ -280,8 +307,7 @@ export function symbolicateStack(
307
growth += added;
308
mappedFrames += 1;
309
// Spliced, not `replace`d: a replacement string would expand `$&` and `$'` in the path.
283
- const end = match.index + match[0].length;
284
- return line.slice(0, match.index) + position.source + lineAndColumn + line.slice(end);
310
+ return line.slice(0, frame.index) + position.source + lineAndColumn + line.slice(frame.end);
311
});
312
return { stack: lines.join("\n"), bundleFrames, mappedFrames, growth };
313
}