Skip to content

fix(lsp): keep large symbol results from exhausting the lsp_symbols heap - #393

Merged
fcoury merged 1 commit into
mainfrom
fix/workspace-symbol-cap
Oct 15, 2026
Merged

fcoury merged 1 commit into
mainfrom
fix/workspace-symbol-cap

Conversation

@fcoury

@fcoury fcoury commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Opening the workspace symbol picker (Space w) in a large TypeScript project quarantined the lsp_symbols plugin. After that, Space w did nothing for the rest of the session, which looked like a crash. The reporter's log shows the cause: HUSK-R0001: Husk heap byte limit exceeded (requested 43816023 bytes with 43820382 of 67108864 bytes live).

Fixes #388.

Cause

  • The picker opens with an empty workspace/symbol query. typescript-language-server sends that to tsserver without a result limit, so it returns every symbol in the project. A symbol takes about 2.2 KB of plugin heap, so the reporter's result used about 44 MB of the 64 MB limit.
  • The plugin then passed the array to start_symbol_batch. Husk charges each binding of an array its full size, even though the data is shared rather than copied (#395). That call was charged a second 44 MB and hit the limit.

Fix

The bundled lsp_symbols plugin now cuts results down to the 4096 rows a picker can show before passing them to its batch helpers. So the helpers never hold more than 4096 entries, whatever the server returns. When results are cut, the status line says how many, for example 4096 symbols (results truncated: first 4096 of 20000; type to narrow). The same applies to references.

This PR doesn't change the plugin host API. An earlier version also capped results in the host and added a total field. Review pointed out that this would change the released 0.19 contract for third-party plugins, so it's been dropped.

Limitation

The plugin can only protect itself once a result is already in its heap. A result too large for the 64 MB heap on its own, roughly 25,000 or more symbols, still fails before any plugin code runs. Handling that needs a bound on the host side, which #394 tracks. That work will open host API 0.20.0 and decide what an oversized result means for older plugins.

Testing

  • lsp_symbols_workspace_symbols_survive_results_larger_than_the_picker: runs the real bundled plugin against a 20,000-symbol workspace symbol result, about the reporter's size. On main's plugin it fails with the reporter's exact error (HUSK-R0001, 44 MB requested with 44 MB live). With this change it passes and shows the truncation status.
  • The existing document-symbol and reference batch tests are updated for the new truncation status.
  • Full library suite (2579 tests), clippy --all-targets --all-features -D warnings, fmt --check, and --self-check all pass.
  • Not tested yet: a real typescript-language-server session on a large project. I've asked the reporter on Workspace symbol picker (Space-w) crashes in some files of a TypeScript project #388 to try this branch.

@fcoury-oai

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T15:50:55.011226Z 5766bf8 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5766bf8df2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/editor.rs Resolved
Comment thread src/editor.rs Resolved
The workspace symbol picker opens with an empty query, which
typescript-language-server answers with every symbol in the project.
lsp_symbols then passed that whole result to its batch helper, and the
Husk runtime charges every binding of an array its full size even though
the data is shared, so the call counted as a second full copy. For the
reporter's ~44 MB result that exceeded the 64 MiB plugin heap, and the
plugin was quarantined until Red restarted.

The plugin now slices results to the 4096 rows a picker shows before
handing them to its batch helpers, and its status line says how many
results were left out. Results larger than the plugin heap itself still
need a host-side bound, tracked in #394.

Fixes #388
@fcoury
fcoury force-pushed the fix/workspace-symbol-cap branch from 5766bf8 to 0d5039b Compare October 15, 2026 16:13
@fcoury fcoury changed the title fix(lsp): cap workspace symbol and reference results sent to plugins fix(lsp): keep large symbol results from exhausting the lsp_symbols heap Oct 15, 2026
@fcoury
fcoury merged commit c49c566 into main Oct 15, 2026
21 checks passed
@fcoury
fcoury deleted the fix/workspace-symbol-cap branch October 15, 2026 16:20
fcoury added a commit that referenced this pull request Oct 15, 2026
…eap (#398)

* fix(plugins): trim or drop request results too large for a plugin's heap

A request result that did not fit in the receiving plugin's 64 MiB Husk
heap failed while binding the callback argument, before any plugin code
ran, and the registry quarantined the plugin. A large TypeScript
project's empty workspace-symbol query (about 60,000 symbols, roughly
130 MB once decoded) still stopped lsp_symbols this way after #393.

The runtime now compares each result with the plugin's free heap before
calling back. Results that fit are delivered unchanged. Oversized
DocumentSymbols, WorkspaceSymbols and References results keep the
leading entries that fit in half of the free heap, leaving room for one
more binding of the list, which the runtime charges again. Any other
oversized result is dropped: the plugin stays active and Red shows a
warning attributed to it.

Successful results of those three requests now carry `total`, the entry
count before trimming, which lsp_symbols uses for its truncation status.
That field opens host API 0.20.0, recorded in the change manifest and
documented in PLUGIN_API.md; 0.19.0 packages keep loading.

Fixes #394

* fix(plugins): trim symbol and reference lists past half the plugin heap

A list that fits the heap can still leave the plugin no room to build
picker items from it, which quarantined lsp_symbols at 28,000 symbols.
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.

Workspace symbol picker (Space-w) crashes in some files of a TypeScript project

2 participants