Skip to content

Fix crash tokenizing a destroyed session via signature help - #4

Open
browniefed wants to merge 1 commit into
mainfrom
jbrown/fix-tokenize-row-null-doc
Open

Fix crash tokenizing a destroyed session via signature help#4
browniefed wants to merge 1 commit into
mainfrom
jbrown/fix-tokenize-row-null-doc

Conversation

@browniefed

@browniefed browniefed commented Jul 14, 2026

Copy link
Copy Markdown

Summary

Fixes the top JS error in /admin/workflows/?/edit/node/?):

TypeError: Cannot read properties of null (reading 'getLine')
  at t.$tokenizeRow (@cortexapps/ace-linters/build/ace-linters.js)
  at e.getTokens / e.getTokenAt
  at SignatureTooltip provideSignatureHelp callback

Root cause

  • addSemanticTokenSupport() replaces bgTokenizer.$tokenizeRow with a version that dereferences bgTokenizer.doc unguarded. When an editor is destroyed (e.g. a React wrapper unmounting), session.destroy() calls bgTokenizer.setDocument(null), so doc is null.
  • SignatureTooltip.update() skips $activateEditor(editor) while the tooltip is open, so $activeEditor can stay pointed at a destroyed editor. Every subsequent selection change in a live editor then requests signature help against the dead session; the response callback calls session.getTokenAt → patched $tokenizeRownull.getLine. Because the throw also prevents the tooltip from ever resetting, this repeats on every cursor move — matching the bursty hundreds-of-errors-per-session pattern in RUM.

Upstream mkslanc/ace-linters has since removed the $tokenizeRow monkey-patch entirely (semantic tokens are applied as markers), so this crash is specific to the fork.

Changes

  • Guard $tokenizeRow when bgTokenizer.doc is null (returns an empty token row).
  • SignatureTooltip.update() re-activates the editor that produced the event even while the tooltip is open.
  • provideSignatureHelp() bails (and hides the tooltip) when the active editor's session is gone or destroyed.
  • New unit suite tests/unit/destroyed-session.tests.ts covering all three (each watched failing first; the first test reproduces the production TypeError verbatim).

Testing

  • npm run test:unit: 78 passing (75 baseline + 3 new).
  • npm run build compiles clean.

Publishing note

main already carries an unpublished 1.8.3 version bump; publishing after merge picks up this fix. brain-app will consume it via a version bump (a pnpm patch with the same guard is going up separately to stop the bleeding immediately).

🤖 Generated with Claude Code

Production RUM shows repeated `TypeError: Cannot read properties of
null (reading 'getLine')` from the `$tokenizeRow` override installed by
`addSemanticTokenSupport`. When an editor is destroyed (e.g. a React
wrapper unmounting), `session.destroy()` nulls `bgTokenizer.doc`, but
the SignatureTooltip can still drive tokenization of that session:
`update()` skips `$activateEditor` while the tooltip is open, so
`$activeEditor` stays pointed at the destroyed editor and every
subsequent selection change in a live editor requests signature help
against the dead session; the response callback then calls
`session.getTokenAt` -> `$tokenizeRow` -> `null.getLine` and throws,
on every cursor move.

- guard `$tokenizeRow` when `bgTokenizer.doc` is null
- make `SignatureTooltip.update` re-activate the editor that produced
  the event even while the tooltip is open
- bail out of `provideSignatureHelp` when the active editor's session
  is gone or destroyed

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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