Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: stop the shared callback parser stepping over a parenthesized arrow body

[._.]/ Adam Eivy5a12e5eaa06a
diff --git a/server/lib/sourceScan.js b/server/lib/sourceScan.js
index 16da1ec833..7f793a61b9 100644
--- a/server/lib/sourceScan.js
+++ b/server/lib/sourceScan.js
@@ -195,6 +195,13 @@ export function parseCallbackAt(blanked, from, limit) {
// Optional name.
while (i < limit && /[\w$]/.test(blanked[i])) i += 1;
skipSpace();
+ // Parameter list. Only the `function` spelling reaches this — an arrow's
+ // params are consumed below, and skipping a second `(` after its `=>` would
+ // step straight over a parenthesized concise body (`async () => (await f())`),
+ // hiding every await in it.
+ if (blanked[i] === '(') i = matchBracket(blanked, i);
+ if (i === -1) return null;
+ skipSpace();
} else {
// Arrow: parenthesized params, or a single bare identifier.
if (blanked[i] === '(') i = matchBracket(blanked, i);
@@ -203,13 +210,8 @@ export function parseCallbackAt(blanked, from, limit) {
skipSpace();
if (!blanked.startsWith('=>', i)) return null;
i += 2;
+ skipSpace();
}
- skipSpace();
-
- // `function` params, or an arrow's parenthesized concise body.
- if (blanked[i] === '(') i = matchBracket(blanked, i);
- if (i === -1) return null;
- skipSpace();
if (blanked[i] === '{') {
const end = matchBracket(blanked, i);
diff --git a/server/sockets/asyncHandlerGuard.test.js b/server/sockets/asyncHandlerGuard.test.js
index 9f5951c061..74116bd88a 100644
--- a/server/sockets/asyncHandlerGuard.test.js
+++ b/server/sockets/asyncHandlerGuard.test.js
@@ -44,7 +44,10 @@ import { blankLiterals, matchBracket, parseCallbackAt, unguardedAwaits } from '.
const HERE = dirname(fileURLToPath(import.meta.url));
-const REGISTRATION = /(?<![\w$.])[\w$]+(?:\.[\w$]+)*\.on\(/g;
+// `.once` as well as `.on`: a one-shot listener returns its promise to nobody
+// exactly the same way, so leaving it out would be a silent hole rather than a
+// narrower rule.
+const REGISTRATION = /(?<![\w$.])[\w$]+(?:\.[\w$]+)*\.(?:on|once)\s*\(/g;
/** Index of the `,` separating a call's first two arguments, or -1. */
function firstArgumentEnd(blanked, from, limit) {
@@ -219,12 +222,23 @@ describe('the socket-handler recognizer', () => {
expect(socketHandlers('socket.on(EVENT, async () => { await boom(); });')).toEqual([]);
});
- it('reads a non-socket emitter in this directory too', () => {
+ it('reads a non-socket emitter, and a one-shot listener, in this directory too', () => {
// `ns.on('connection', …)` and the pm2-logs child's `.on('data', …)` are in
// the same blast radius; scoping the scan to the literal `socket.` would let
- // the next one in unnoticed.
+ // the next one in unnoticed. `.once` returns its promise to nobody the same
+ // way `.on` does.
expect(findUnguardedHandlerAwaits("logProcess.stdout.on('data', async (chunk) => { await flush(chunk); });"))
.toEqual(["line 1 'data': await flush(chunk)"]);
+ expect(findUnguardedHandlerAwaits("socket.once('shell:attach', async () => { await attach(); });"))
+ .toEqual(["line 1 'shell:attach': await attach()"]);
+ });
+
+ it('sees a parenthesized concise body rather than stepping over it', () => {
+ // `parseCallbackAt` used to skip a second `(` after the `=>`, reading it as
+ // a parameter list and jumping the whole body — so every await inside was
+ // invisible and the handler passed green.
+ expect(findUnguardedHandlerAwaits("socket.on('x', async () => (await boom()));"))
+ .toEqual(["line 1 'x': await boom()"]);
});
it('reports the voice call handlers as guarded', () => {
diff --git a/server/timerCallbackConventions.test.js b/server/timerCallbackConventions.test.js
index 07f3be1eb1..53b590fa49 100644
--- a/server/timerCallbackConventions.test.js
+++ b/server/timerCallbackConventions.test.js
@@ -183,6 +183,11 @@ describe('the timer-callback recognizer', () => {
// A concise body has no braces to walk, but still owns its await.
expect(findUnguardedTimerAwaits('setTimeout(async () => await f(), 100);'))
.toEqual(['line 1: await f()']);
+ // Parenthesized concise body. The parser used to read the `(` after the `=>`
+ // as a parameter list and jump the whole body, so the await inside was
+ // invisible and this passed green.
+ expect(findUnguardedTimerAwaits('setTimeout(async () => (await f()), 100);'))
+ .toEqual(['line 1: await f()']);
});
it('accepts a try-wrapped body', () => {