Repository navigation
Type progress tokens as Int64, not Int - #1486
Merged
Merged
Conversation
On 32-bit Julia, a request carrying a numeric `workDoneToken` or
`partialResultToken` killed the server. `Int` is Int32 there, but the JSON
parser returns Int64 for every integer, and `convert(Union{Int32,String,Missing},
::Int64)` has no method. `@dict_readable` passes a three-member union through
unconverted, so the struct constructor threw, and `JSONRPC.dispatch_msg`
rethrows a params error. `Union{Int,Missing}` and `Union{Int,Nothing}` fields
are not affected; Julia converts those through the non-missing type.
All 37 ProgressToken fields now use Int64, like the request ids in
JSONRPC.jl#127. `ServerCapabilities.textDocumentSync` stays `Int`: the server
fills it from an `Int` constant, and `Union{Int64,...}` would refuse an Int32
on 32-bit in the same way.
VS Code sends string tokens, so this has not been seen in practice.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Opened by Claude (Claude Code) on David's behalf.
On 32-bit Julia, a request that carries a numeric
workDoneTokenorpartialResultTokencrashes the language server.IntisInt32there, but the JSON parser returnsInt64for every integer, andconvert(Union{Int32,String,Missing}, ::Int64)has no method. This is the same failure that JSONRPC.jl#127 fixed for request ids (julia-vscode/julia-vscode#4260).VS Code always sends string tokens, so this has not shown up in crash telemetry. The LSP spec allows integer tokens, though, and other clients may send them.
Why it crashes
@dict_readableonly convertsUnion{X,Missing}fields explicitly (X(dict[k])). Any other union is passed through unconverted, and the struct's own constructor has toconvertit.InitializeParamshas a handwritten constructor that passes the token through unconverted too.JSONRPC.dispatch_msgsends an INVALID_PARAMS response and then rethrows, which takes down the server's message loop.Union{Int,Missing}andUnion{Int,Nothing}fields (version,processId, …) are fine, because Julia converts those through the non-missing type.I confirmed this on
julia +1.12~x86. Before the fix,ReferenceParams,WorkspaceSymbolParamsandWorkDoneProgressCancelParamsbuilt from a Dict with anInt64token all throw aMethodError.Change
Int→Int64.Union{Int,String[,Missing]}becomesUnion{Int64,String[,Missing]}. I found every field with reflection over all LS structs, not by grep. Ten of these types have live handlers: references, rename, documentSymbol, documentHighlight, selectionRange, documentLink, inlayHint, executeCommand, workspace/symbol and initialize.ServerCapabilities.textDocumentSyncintentionally staysInt. The server fills it from anIntconstant, and on 32-bitconvert(Union{Int64,…}, ::Int32)fails in the same way. The same goes forParameterInformation.label, which only the server sends.Stringtokens (PhaseBar.token).Tests
These go in
test/test_protocol.jl. LS CI already has~x86legs, so the tests run on real 32-bit Julia there:ReferenceParams,WorkspaceSymbolParams,WorkDoneProgressCancelParamsandInitializeParamsfrom aDictthe same waydispatch_msgdoes, with both anInt64and aStringtoken.Dictconstructor and fails if any field is a union that holds a non-Int64signed integer alongside a non-integer type. On 64-bit it passes trivially. On x86 it catches any futureUnion{Int,String…}field.Before the fix, both tests fail on
julia +1.12~x86. With the fix, the fullPkg.test()passes on1.12x64 and1.12~x86: 213240 pass, plus the one existing@test_broken.JSONRPC compat
This doesn't need anything new from JSONRPC, so I left the compat bound alone. Note, though, that LS on 32-bit also needs JSONRPC ≥ 3.1.1 (#127, not registered yet) before it can handle requests at all.
🤖 Generated with Claude Code