Repository navigation
fix(plugins): trim or drop request results too large for a plugin's heap - #398
Merged
Merged
Conversation
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
Collaborator
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2bb8e60dd5
ℹ️ 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".
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.
This was referenced Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A request result too large for the receiving plugin's 64 MiB Husk heap failed while Red was binding the callback argument, before any plugin code ran, and the plugin was quarantined. #393 fixed the second, accounting-only copy behind #388, but a large TypeScript project's empty workspace-symbol query, about 60,000 symbols or roughly 130 MB once decoded, still stopped
lsp_symbolsthis way.Fixes #394, which also completes the remaining part of #388.
What changes
husk-runtimenow exposes asheap_cell_size,heap_value_sizeandVm::available_heap_bytes. Results other than symbol and reference lists are delivered unchanged whenever they fit, so they behave as today.DocumentSymbols,WorkspaceSymbolsandReferences, a list larger than half the free heap keeps only the leading entries that fit in that half. The plugin needs the other half to work with the list: 28,000 symbols (62 MB) fit the 64 MiB heap, yetlsp_symbolsfailed building picker items from them. Lists between half and all of the free heap were delivered whole before; they now arrive trimmed, withtotalgiving the real count.reader: dropped a GetBufferText result too large for its memory (70.0 MiB needed, 64.0 MiB free). It also logs aWARNline. I chose dropping over delivering{ ok: false }because most of these callbacks read fields that only exist on success, and reading a missing field fails, which would quarantine the plugin anyway.total, the entry count before any trimming.lsp_symbolsuses it, so its status reads "first 4096 of 60000" from the real count.RED_HOST_API_VERSIONis 0.20.0, and 0.19.0 stays in the supported list, so 0.19.0 packages keep loading.docs/plugin_api_changes.jsonrecords the newtotalfields and the oversized-result behavior.docs/PLUGIN_API.mdhas a new "Oversized request results" section.How to Test
Save this plugin as
reader.hk. It reads the whole buffer:Add
reader = "/absolute/path/to/reader.hk"to the[plugins]table of yourconfig.toml.Create a file larger than the plugin heap, such as
python3 -c "open('big.txt','w').write(('x'*1023+'\n')*71680)", which writes 70 MiB. Open it withred big.txt.Run
:ReadAll. The bottom line shows! reader: dropped a GetBufferText result too large for its memory (70.0 MiB needed, 64.0 MiB free), andred.login the config directory has a[WARN] DroppedGetBufferTextresult for pluginreader`` line. Before this change, the same request quarantinedreader.Run
:Ping, then open:messages.reader is still runningis listed, so the plugin is still active.Symbol trimming, optional: in a TypeScript project with tens of thousands of symbols, using typescript-language-server, press
Space w. The picker should fill with aresults truncated: first 4096 of N; type to narrowstatus instead of stoppinglsp_symbols.workspace_symbols_larger_than_the_plugin_heap_are_trimmed_before_deliverycovers this with 60,000 symbols, and fails onmainwithHusk heap byte limit exceeded (requested 132867124 bytes …).Other new tests:
workspace_symbols_that_barely_fit_the_plugin_heap_are_trimmed_before_delivery: 28,000 symbols, which fit the heap but quarantinedlsp_symbolswithout the half-heap limitresult_larger_than_the_plugin_heap_is_dropped_without_failing_the_plugintrimmed_result_keeps_the_longest_prefix_that_fitsavailable_heap_bytes_predicts_whether_an_argument_fits, inhusk-runtimedropped_plugin_result_is_reported_as_a_plugin_warningThe existing 20,000-symbol test (44 MB) is now trimmed before delivery and still shows
first 4096 of 20000.