Skip to content

Fix the three open bugs from TODO section 4 - #421

Merged
gbmhunter merged 2 commits into
mainfrom
fix/todo-bugs
Sep 5, 2026
Merged

gbmhunter merged 2 commits into
mainfrom
fix/todo-bugs

Conversation

@gbmhunter

@gbmhunter gbmhunter commented Sep 5, 2026 •

Copy link
Copy Markdown
Owner

Closes the three open items in TODO.md §4.

MCP rxstream buffer grew without bound

handleRxData appended every RX chunk to a per-session string that only shrank when a client read the resource. A client that subscribed and never read, or dropped its connection without closing the session, held the entire serial stream in main-process memory for the life of the app.

RxStreamBuffer (new, src/main/) caps it at the last 1,000,000 characters, drop-oldest. The next read after an overflow starts with one line saying how many characters were dropped, so the reader sees a gap rather than a silent mid-line join. Trimming is amortised: it runs when a quarter over the cap, so a saturated stream costs one string copy per ~250k characters rather than one per chunk. The resource description tells clients about the cap.

These are the first unit tests for main-process code (RxStreamBuffer.spec.ts, 5 tests) — TODO.md §6 notes there were none.

stopCpuMonitoring() was a no-op

The method body was a comment saying the loop stops when the window unloads, which is not what App.cleanup() is for. The requestAnimationFrame loop now records its handle and cleanup cancels it, plus any outstanding requestIdleCallback. The handles are excluded from MobX observation (written once per frame, nothing observes them). App.spec asserts cleanup cancels the exact frame that was pending.

Find is regex-capable

Filters and Highlight Rules both took regex; Find used indexOf. A .* toggle in the Find bar (next to Aa) switches the query to a regex compiled with g, plus i unless case-sensitive. findMatches walks every hit in a row with exec, skipping zero-width matches so x* can neither hang nor report empty spans. An invalid pattern yields no matches and the bar shows Invalid, with the compile error on hover. Toggling the mode resets the current match, like the other Find controls. Substring mode is unchanged.

Also: a leaked interval (found by CI on this PR)

The first CI run passed all 493 tests and then failed on an unhandled rejection: tests in ConnController.characterisation.spec.ts that leave a serial port open start the 1 s flow-control setInterval, and nothing stopped it. After vitest tore the file down and reset the mocks, the timer fired against getFlowControlSignals returning undefined. Locally the worker exits before the timer lands, which is why it never showed.

ConnController.cleanup() now stops the poll (it stopped the reconnection poller but not this one, so in the app it ran until the window unloaded), the poll callback logs rather than throws on a bad IPC response, and the spec tears the app down after every test.

Verification

  • Find.spec.ts +5: every match of a pattern, case toggle in regex mode, invalid regex → no matches + error, zero-width matches, mode toggle resets cursor
  • RxStreamBuffer.spec.ts (5): drain semantics, bounded growth, drop notice once, drain never exceeds cap, bad cap rejected
  • App.spec.ts +1: cleanup cancels the pending frame
  • npx tsc clean · npm run lint 0 errors · 493/493 unit · 89/89 e2e

MCP rxstream buffer grew without bound. handleRxData appended every RX
chunk to a per-session string that only shrank when a client read the
resource, so a client that subscribed and never read -- or dropped its
connection without closing the session -- held the entire serial stream in
main-process memory for the life of the app. RxStreamBuffer caps it at the
last 1,000,000 characters, drop-oldest, and prefixes the next read with a
one-line notice of how much was dropped so the reader sees a gap rather than
a silent mid-line join. Trimming is amortised (runs a quarter over the cap)
so a saturated stream costs one copy per 250k characters, not one per chunk.
The resource description tells clients about the cap. First unit tests for
main-process code.

stopCpuMonitoring was an empty method with a comment saying the loop stops
when the window unloads, which is not what App.cleanup is for. The
requestAnimationFrame loop now records its handle and cleanup cancels it,
along with any outstanding requestIdleCallback. The handles are excluded
from MobX observation since they are written once per frame and nothing
observes them. App.spec asserts cleanup cancels the exact frame that was
pending.

Find was substring-only while Filters and Highlight Rules both take regex.
A findUseRegex flag and a `.*` toggle in the Find bar switch the query to a
regex compiled with `g` (plus `i` unless case-sensitive). findMatches walks
every hit in a row with exec, skipping zero-width matches so `x*` can
neither hang nor report empty spans. An invalid pattern yields no matches
and a findRegex.errorMsg the bar shows as "Invalid" with the compile error
on hover. Toggling the mode resets the current match like the other
find controls.
@gbmhunter gbmhunter self-assigned this Sep 5, 2026
CI failed on an unhandled rejection after ConnController.characterisation.spec
finished: tests that leave a serial port open start the 1s flow-control
setInterval, nothing stopped it, and once vitest had torn the file down and
reset the mocks it fired against getFlowControlSignals returning undefined.
Locally the worker exited before the timer landed.

ConnController.cleanup now stops the poll (it stopped the reconnection
poller but not this one, so in the app it ran until the window unloaded).
The poll callback tolerates a bad or rejected IPC response by logging,
since an async interval callback has nobody to catch what it throws. The
spec tears the app down after every test, and jsdom's unimplemented
HTMLMediaElement.pause is stubbed once in the global setup rather than in
one spec.
@gbmhunter
gbmhunter merged commit 12d7501 into main Sep 5, 2026
8 checks passed
@gbmhunter
gbmhunter deleted the fix/todo-bugs branch September 5, 2026 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant