Skip to content

Declare cluster_manager as a global non-constant variable with a type declaration (albeit an abstract type)#177

Draft
DilumAluthge wants to merge 1 commit intomasterfrom
dpa/global-cluster_manager
Draft

Declare cluster_manager as a global non-constant variable with a type declaration (albeit an abstract type)#177
DilumAluthge wants to merge 1 commit intomasterfrom
dpa/global-cluster_manager

Conversation

@DilumAluthge
Copy link
Member

No description provided.

@DilumAluthge
Copy link
Member Author

DilumAluthge commented Feb 13, 2026

@JamesWrigley It looks like this isn't sufficient to fix the JET error. Example CI log:

═════ 2 possible errors found ═════
┌ start_worker(cookie::AbstractString; kwargs...) @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/cluster.jl:241
│┌ start_worker(out::IO, cookie::AbstractString) @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/cluster.jl:242
││┌ start_worker(out::IO, cookie::AbstractString; close_stdin::Bool, stderr_to_stdout::Bool) @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/cluster.jl:260
│││┌ Task(f::Distributed.var"#26#27") @ Base ./task.jl:5
││││┌ (::Distributed.var"#26#27")() @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/cluster.jl:262
│││││┌ process_messages(r_stream::Base.PipeEndpoint, w_stream::Base.PipeEndpoint, incoming::Bool) @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/process_messages.jl:151
││││││┌ Task(f::Distributed.var"#process_messages##2#process_messages##3"{Base.PipeEndpoint, Base.PipeEndpoint, Bool}) @ Base ./task.jl:5
│││││││┌ (::Distributed.var"#process_messages##2#process_messages##3"{Base.PipeEndpoint, Base.PipeEndpoint, Bool})() @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/process_messages.jl:151
││││││││┌ message_handler_loop(r_stream::Base.PipeEndpoint, w_stream::Base.PipeEndpoint, incoming::Bool) @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/process_messages.jl:164
│││││││││┌  @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/process_messages.jl:319
││││││││││ `Distributed.cluster_manager` may be undefined: Distributed.cluster_manager
│││││││││└────────────────────
│││││││││┌  @ Distributed /home/runner/work/Distributed.jl/Distributed.jl/src/process_messages.jl:332
││││││││││ `Distributed.cluster_manager` may be undefined: Distributed.cluster_manager
│││││││││└────────────────────

Test Summary: | Fail  Total   Time
JET           |    1      1  11.0s

@DilumAluthge
Copy link
Member Author

That being said, this might still be a good change to make, because it makes it a bit more explicit that the global exists, and isa ClusterManager.

@DilumAluthge DilumAluthge marked this pull request as ready for review February 13, 2026 00:10
@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.34%. Comparing base (871e3d7) to head (1ba667e).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #177   +/-   ##
=======================================
  Coverage   79.34%   79.34%           
=======================================
  Files          10       10           
  Lines        1951     1951           
=======================================
  Hits         1548     1548           
  Misses        403      403           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aviatesk
Copy link
Member

aviatesk commented Feb 14, 2026

JET reports whenever a global variable that might be uninitialized is used.
For local variables, as you mentioned on Slack, you can avoid reporting by adding statements like @assert @isdefined(target_var) "assertion to help the compiler and JET". However, this approach does not work for global variables due to various reasons. The two options to consider are:

  1. Review the code architecture and eliminate uninitialized global variable references: In this case, passing cluster_manager as an argument to each subroutine is a better approach, leading to a more functional and good coding pattern.
  2. Always initialize the global variable: If the above approach is not feasible due to issues like API compatibility, you can use Ref or similar containers to always initialize the global variable, avoiding the problem. For example:
const cluster_manager = Ref{ClusterManager}()

function subroutine()
    isassigned(cluster_manager) || error("cluster manager uninitialized")
    manager = cluster_manager[]
    # use `manager`
end

This approach does not fundamentally solve the code design issue but exploits JET's permissive reporting approach though.

@DilumAluthge
Copy link
Member Author

@JamesWrigley What do you think? Should we go with the Ref approach?

@DilumAluthge DilumAluthge marked this pull request as draft February 15, 2026 03:06
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.

2 participants