Skip to content

Add ability to customize worker prefix#157

Open
IanButterworth wants to merge 2 commits into
masterfrom
ib/worker_output_customization
Open

Add ability to customize worker prefix#157
IanButterworth wants to merge 2 commits into
masterfrom
ib/worker_output_customization

Conversation

@IanButterworth

Copy link
Copy Markdown
Member

@codecov

codecov Bot commented Dec 12, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 9.09091% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.10%. Comparing base (22641e6) to head (14f8129).

Files with missing lines Patch % Lines
src/cluster.jl 0.00% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #157      +/-   ##
==========================================
- Coverage   79.43%   79.10%   -0.33%     
==========================================
  Files          10       10              
  Lines        1969     1977       +8     
==========================================
  Hits         1564     1564              
- Misses        405      413       +8     

☔ View full report in Codecov by Harness.
📢 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.

@IanButterworth
IanButterworth marked this pull request as ready for review December 18, 2025 03:23
@IanButterworth IanButterworth changed the title WIP: Add ability to customize worker prefix Add ability to customize worker prefix Dec 18, 2025

@JamesWrigley JamesWrigley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread src/cluster.jl
end
```
"""
const worker_output_hook = Ref{Union{Nothing, Function}}(nothing)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think I like that we expect the handler to fully take over the role of printing stuff as well. We may very well change it in the future to better support logging or something, so I would prefer that the callback instead be a transform that takes in the string and returns a (possibly different) string for Distributed to handle in its own way.

In which case we could have:

Suggested change
const worker_output_hook = Ref{Union{Nothing, Function}}(nothing)
worker_output_hook::Function = identity

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good call. I switched it to a transform that just returns the string, so Distributed still owns the println (and a throwing hook now falls back to the default prefix instead of eating output).

Two deliberate tweaks from the exact suggestion:

  • (ident, line) not just line. The test harness needs ident to label a line with which test that worker is running.
  • defaults to nothing, not identity. So unset means "use the normal From worker N: prefix" rather than printing raw un-prefixed lines. Default behavior stays unchanged.

@JamesWrigley

Copy link
Copy Markdown
Member

Regarding the design in JuliaParallel/DistributedNext.jl#17, I'm not sure if we should support per-module callbacks. I could maybe see it being useful if a higher-level tool like Dagger wanted to customize the output a bit more (CC @jpsamaroo).

@JamesWrigley

Copy link
Copy Markdown
Member

I would also be ok with keeping this a strictly internal feature for the Julia tests 🤷

@DilumAluthge

Copy link
Copy Markdown
Member

If we keep it internal and non-public, then we have the added benefit of being able to make breaking changes to it (or even remove it entirely) in the future.

IanButterworth and others added 2 commits July 16, 2026 10:53
`redirect_worker_output` is documented to receive `ident` as an
`AbstractString`, and the `cluster.jl` call site already passes `"$pid"`.
The `connect` path in `managers.jl` passed the raw `Int` pid instead,
so any consumer that treated `ident` as a string (e.g. `tryparse(Int, ident)`)
would misbehave. Pass `"$pid"` here too so the two call sites agree.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add an internal, unstable `worker_output_hook` Ref that, when set, transforms
each line of a worker's output into the string that should be printed for it.
`Distributed` still owns the actual printing, so a hook may return a
`StyledStrings`-styled line and it will render correctly on IOs that do or do
not support color. When the hook is unset (the default) the standard prefix is
used. A hook that throws falls back to the default prefix so worker output is
never swallowed.

The default prefix indent is also reduced from six spaces to a single space.

The hook is deliberately not exported and carries no compatibility guarantees;
it exists so test harnesses can label worker output with richer context (e.g.
which test a worker is running).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@IanButterworth
IanButterworth force-pushed the ib/worker_output_customization branch from 48fc61d to 14f8129 Compare July 16, 2026 15:03
IanButterworth added a commit to IanButterworth/julia that referenced this pull request Jul 16, 2026
Label each line of a test worker's output with the test it is currently
running instead of just its worker id, making it much easier to tell which
suite a stray log line or precompile message came from.

Worker output is routed through Distributed, so an internal
`Distributed.worker_output_hook` is installed that transforms each line into a
de-emphasized `"<test> (<worker>): "` prefix (falling back to the worker id
when the worker is between tests). The node-1 tests run in-process and do not
pass through that redirection, so their stdout/stderr are captured with a
`Pipe` and prefixed the same way via `with_output_prefix`. Prefixes are styled
with `StyledStrings` so they are only colorized on IOs that support it.

The embedding test is updated for the reduced single-space default worker
prefix introduced in the corresponding Distributed change.

Depends on JuliaLang/Distributed.jl#157.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
IanButterworth added a commit to IanButterworth/julia that referenced this pull request Jul 16, 2026
Point the bundled Distributed at JuliaLang/Distributed.jl#157, which adds the
internal `worker_output_hook` used by the test harness.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

3 participants