fix: resolve abort listener leak and VAD sparse array initialization#68
fix: resolve abort listener leak and VAD sparse array initialization#68rsagacom wants to merge 1 commit into
Conversation
- agent-loop.ts / code-mode/service.ts: remove spurious removeEventListener calls from timer success callbacks; the once-true listener should only be removed in the abort handler, otherwise shared AbortSignals lose listeners prematurely - vad: replace new Array(n) with Array.from to eliminate sparse arrays and resolve unicorn/no-new-array lint warnings - stepfun-stateless.ts: drop unused catch parameter 'e' Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Hi @rsagacom, thanks for the fixes. This PR looks very similar to #41 from the same author — both address the abort listener leak in agent-loop.ts/code-mode/service.ts, the VAD sparse array fix in cli-handlers.ts/resolver.ts, and the unused catch parameter in stepfun-stateless.ts. Could you confirm if #41 should be closed in favor of this one, or vice versa? |
|
Closes #80
Why
Three independent bug fixes discovered during local testing:
Abort listener leak in
agent-loop.tssleep +code-mode/service.tsdelay — both functions register an"abort"listener on the signal but never remove it when the timer fires normally (only on abort). Over repeated calls this accumulates orphaned listeners on shared AbortController signals, causing unexpected side-effects.VAD sparse arrays in
cli-handlers.tsandresolver.ts—new Array(n)creates a sparse array (holes, no0throughn-1indices). The Levenshtein edit-distance loop readsprev[0]andcurr[0]which areundefinedin a sparse array, producingNaNpropagation. Sparse arrays also defeat V8's optimized array storage.Unused catch parameter in
stepfun-stateless.ts—catch (e)binds an unused variable;catchis clearer and avoids the linter warning.Blast radius
packages/core/src/agent/agent-loop.ts— removes oneremoveEventListenercall that was masking a leak (no API change)packages/core/src/tools/code-mode/service.ts— same pattern, same impactpackages/realtime/src/vad/cli-handlers.ts— changes sparse array to dense initialization (behavioral fix for distance calculation)packages/realtime/src/vad/resolver.ts— same fixpackages/realtime/src/backend/stepfun-stateless.ts— stylistic: drop unusedebindingNo public API changes. No configuration changes. No cross-platform behavior change.
Verification
Manual: verified abort listener count stays stable across 100+ repeated
sleep()calls with a shared AbortController; verified VAD resolver returns correct edit distance for identical strings (wasNaN, now0).Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com