Skip to content

Type progress tokens as Int64, not Int - #1486

Merged
davidanthoff merged 1 commit into
mainfrom
fix/c60-progress-token-int64
Oct 5, 2026
Merged

davidanthoff merged 1 commit into
mainfrom
fix/c60-progress-token-int64

Conversation

@davidanthoff

Copy link
Copy Markdown
Member

Opened by Claude (Claude Code) on David's behalf.

On 32-bit Julia, a request that carries a numeric workDoneToken or partialResultToken crashes the language server. Int is Int32 there, but the JSON parser returns Int64 for every integer, and convert(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_readable only converts Union{X,Missing} fields explicitly (X(dict[k])). Any other union is passed through unconverted, and the struct's own constructor has to convert it. InitializeParams has a handwritten constructor that passes the token through unconverted too.
  • When the conversion throws, JSONRPC.dispatch_msg sends an INVALID_PARAMS response and then rethrows, which takes down the server's message loop.
  • Union{Int,Missing} and Union{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, WorkspaceSymbolParams and WorkDoneProgressCancelParams built from a Dict with an Int64 token all throw a MethodError.

Change

  • 37 ProgressToken fields Int → Int64. Union{Int,String[,Missing]} becomes Union{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.textDocumentSync intentionally stays Int. The server fills it from an Int constant, and on 32-bit convert(Union{Int64,…}, ::Int32) fails in the same way. The same goes for ParameterInformation.label, which only the server sends.
  • No server code stores or compares these tokens. The server only creates String tokens (PhaseBar.token).

Tests

These go in test/test_protocol.jl. LS CI already has ~x86 legs, so the tests run on real 32-bit Julia there:

  • Behaviour test. Builds ReferenceParams, WorkspaceSymbolParams, WorkDoneProgressCancelParams and InitializeParams from a Dict the same way dispatch_msg does, with both an Int64 and a String token.
  • Guard test. Checks every LS struct that has an explicit Dict constructor and fails if any field is a union that holds a non-Int64 signed integer alongside a non-integer type. On 64-bit it passes trivially. On x86 it catches any future Union{Int,String…} field.

Before the fix, both tests fail on julia +1.12~x86. With the fix, the full Pkg.test() passes on 1.12 x64 and 1.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

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>
@davidanthoff
davidanthoff merged commit f9eea5b into main Oct 5, 2026
28 checks passed
@davidanthoff
davidanthoff deleted the fix/c60-progress-token-int64 branch October 5, 2026 00:22
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