Skip to content

Fix thread attribution (#222), paths with spaces (#233), Gradle 9.9 configuration (#228) - #248

Merged
jbachorik merged 7 commits into
mainfrom
claude/affectionate-wozniak-r4ds4u
Nov 22, 2026
Merged

jbachorik merged 7 commits into
mainfrom
claude/affectionate-wozniak-r4ds4u

Conversation

@jbachorik

@jbachorik jbachorik commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Three issue fixes (#222, #233, #228), one commit each, plus two commits that finish #222 and #233 after a code review found the same mistakes elsewhere, one that accepts the resulting MCP contract snapshot, and one with the fixes from a second review.

  • jfr_tsa reports every sample as thread 'unknown' (jdk.ExecutionSample has no eventThread field) #222 — jfr_tsa put every sample under thread "unknown". JfrAnalyses.extractThreadId/extractThreadName read only eventThread; jdk.ExecutionSample and jdk.NativeMethodSample carry sampledThread (JDK 25 metadata: Thread sampledThread;, no eventThread). The thread now comes from sampledThread when the event has it, else eventThread, which the other events these helpers read use (verified for jdk.JavaMonitorEnter from JDK metadata and for datadog.ExecutionSample from Jafar's field list; datadog.QueueTime not checked). Id and name are read from the same field. Also affects jfr_diagnose (merges TSA) and jfr_use's active-thread count (same helper, analyzeThreadsResource).
  • jafar-shell show splits paths containing spaces after argument parsing #233 — a recording path with spaces was opened only up to the first space. The one-shot commands, the interactive shell's startup file and the TUI's rebuilt "open " + path and dispatched it; dispatch() splits on whitespace. New CommandDispatcher.open(Path, String) opens from the Path and reports a failure exactly as dispatch() does (io.error("Error: " + message)); the open command calls the same code after parsing. jafar-shell show … forwards to io.jafar.shell.Main, so it is covered by the same change.
  • Build fails on Gradle 9.9: project(':parser-core').sourceSets.test.output is not resolvable inside dependencies {} #228 — the build failed to configure on Gradle 9.9. jafar-processor, parser-codegen and tools read project(':parser-core').sourceSets.test.output inside dependencies {}, where project(...) is a ProjectDependency. Each now resolves it once outside the block. Same expression, same classpath.
  • Review follow-up, threads (jfr_tsa reports every sample as thread 'unknown' (jdk.ExecutionSample has no eventThread field) #222): the same eventThread-only assumption sat in decorateByTime's default thread paths (so the documented events/jdk.ExecutionSample | decorateByTime(jdk.JavaMonitorWait, ...) decorated nothing) and in stack profiles (eventThread and OS name first, so a sample's thread could differ from jfr_tsa's). New EventThreads (shell-core, io.jafar.shell.jfrpath) is the one rule — sampledThread if present else eventThread, Java name else OS name, id and name from one field — used by JfrAnalyses, Profiles and Decorators. MCP query help, JFRPath.md and the tutorial updated; the MCP contract snapshot is re-accepted for the one changed help sentence. Found on the way: a named parameter after fields= in decorateByTime/decorateByKey failed with Expected ')' (the tutorial's explicit-path example); the field list now stops before name=.
  • Review follow-up, open (jafar-shell show splits paths containing spaces after argument parsing #233): the open command itself still read only the path's first word in jfr-shell (so the ask transcript, which writes open <path>, failed on replay), and jafar-shell kept quotes. New OpenArguments (shell-core) reads open's argument for both shells — everything up to --alias, or a leading quoted string — and quote() writes one back; the transcript uses it. jafar-shell's open refuses --alias rather than reading it as part of the path. JdkMetadataEndToEndTest opens through dispatcher.open and quotes the path it types.
  • Second review: OpenArguments.quote() could write a line parse() did not read back (whitespace plus both quote characters); it now returns the first of double-quoted, single-quoted and bare that reads back exactly, else throws, and the transcript then writes a comment instead of a broken open. A leading quote without a complete quoted form is part of the file name again (open 'odd.jfr). jfr-shell's open keeps its old habit of ignoring words after an existing file (open rec.jfr # main) when the whole text names no file, with a printed note. Parse errors are usage messages, not Error: Usage: …. The decorateByTime completer names the new defaults. DecorateByTimeOp's thread-path fields are empty, never null, when not given.
  • doc/agents/DataShapes.md: new case "An event's thread is not always eventThread" (the jfr_tsa reports every sample as thread 'unknown' (jdk.ExecutionSample has no eventThread field) #222 lesson: a "unknown" default hid the miss, and the test recording was a Datadog one whose samples do have eventThread).
  • CHANGELOG: six Fixed entries (the three issues, decorateByTime's default, stack-profile thread names, the fields= parse error; the jafar-shell show splits paths containing spaces after argument parsing #233 entry also covers open and its behaviour changes).

Deliberately not in this PR: no escaping inside quotes in open (the rare path no form reads back — whitespace, both quote characters and a leading/trailing space or --alias word — is refused by quote()); the Opened session #1: … line before the JSON in one-shot output (#234) is unchanged; the one-shot behaviour after a failed open (the command still runs, as before) is unchanged.

Parity: not applicable — no untyped-parser code (parser-core impl/internal_api, go-parser) is touched.
Typed-Parity: not applicable — no typed-generator production code is touched; only the test classpath declaration in jafar-processor/build.gradle and parser-codegen/build.gradle moves.

Validation

#228 (Gradle 9.9.1 distribution, sha256 checked against services.gradle.org):

  • Before: gradle help → Build file '…/jafar-processor/build.gradle' line: 35 … Could not get unknown property 'sourceSets' for project ':parser-core' of type …DefaultProjectDependency.
  • After: gradle help :jafar-processor:compileTestJava :parser-codegen:compileTestJava :tools:compileTestJava :jfr-mcp:shadowJar → BUILD SUCCESSFUL, 46 tasks executed.
  • Pinned wrapper 9.4.1: the same tasks succeed.

#222

  • R5: with the fix reverted, JfrAnalysesThreadAttributionTest fails 3 of 4 (threads ==> expected: <5> but was: <1>; expected: <42> but was: <unknown>; expected: <42> but was: <7>); all 4 pass with it. The TSA test records its own jdk.ExecutionSample from four named workers plus the main thread and compares TSA's per-thread counts with groupBy(sampledThread/javaThreadId).
  • R1: the reporter's Repro.java recorded on JDK 25 (1,062 jdk.ExecutionSample), then jfr_open + jfr_tsa over the built jfr-mcp jar's stdio transport: totalThreads: 5 — main 295, worker-0 217, worker-1 207, worker-2 176, worker-3 165, identical to jfr_query "events/jdk.ExecutionSample | groupBy(sampledThread/javaName)" (which also lists two 1-sample threads that TSA's minSamples=5 drops).

#233

  • R5: with Main.java reverted, PathWithSpacesTest fails: exit 1, Error: /tmp/…/dir / No session open for …/dir with spaces/sample input.jfr; passes with the fix.
  • R1, built jars on JDK 25, fresh user.home, jafar backend via -Djfr.shell.backend.jars (nothing installed): jfr-shell-…-all.jar and jafar-shell-…-all.jar show '<dir with spaces>/sample input.jfr' 'events/jdk.ExecutionSample | count()' --format json → "count": 8000, exit 0, same as the plain path. Interactive jfr-shell '<dir with spaces>/sample input.jfr' with show … on stdin → Opened session #1: dir with spaces/sample input.jfr, count 8000.

Review follow-up

  • R5: with the production changes reverted, the new tests fail: decorateByTimeMatchesASamplesSampledThreadByDefault (row onThread1 ==> expected: <MyLock> but was: <null>), aSampleIsCountedUnderItsSampledThreadsJavaName (expected: <[worker-0]> but was: <[os-7]>, the other thread's OS name), namedParametersMayFollowTheFieldList (Expected ')' [at 96]), PathWithSpacesTest#theOpenCommandTakesAPathWithSpaces (Error: "/tmp/…/dir), both OpenPathWithSpacesTest tests (file not found: "/tmp/…/a b.jfr", file not found: …/plain.jfr --alias x). All pass with the changes, as do all of io.jafar.shell.jfrpath.*.
  • R1, built jars on JDK 25: a script with open "<dir with spaces>/work run.jfr" (as the transcript writes it) gives count 577, exit 0, in both jfr-shell and jafar-shell. decorateByTime(app.Work, fields=label) with default thread paths, on a real recording where two workers commit an app.Work duration event around their busy loops: worker-0 → job-0 on 192 samples, worker-1 → job-1 on 191, main (never inside app.Work) undecorated on its 192.

Second review

  • R5: each fix mutated back fails its test — quoteIsReadBackAsTheSamePath / TranscriptOpenLineTest (unclosed ' in '/tmp/Bob's "prod" run.jfr'), quoteRefusesAPathNoFormReadsBack (nothing thrown), aLeadingQuoteWithoutAQuotedFormIsPartOfThePath (unclosed ' in 'odd.jfr), trailingWordsAfterAnExistingFileStillOpenItWithANote (script fails on plain.jfr # main recording), aMalformedOpenLineIsAUsageMessage (Error: Usage: …), omittedThreadPathsAreEmptyNotNull (expected: <[]> but was: <null>). The completer text has no test.
  • Suites on 58e59e7 (env -u _JAVA_OPTIONS ./gradlew --no-daemon spotlessCheck :arch-tests:test pmdMain :shell-core:test :jfr-shell:test :jfr-shell:jdkMetadataTest :jafar-shell:test :jfr-mcp:test, fresh reports only): spotless, ArchUnit 22, pmdMain pass; shell-core 599, jfr-shell 988, jdkMetadataTest 7, jafar-shell 70, jfr-mcp 415 — no failures.

Suites and gates (./gradlew spotlessCheck :arch-tests:test pmdMain :shell-core:test :jfr-shell:test :jafar-shell:test :jfr-mcp:test :jafar-processor:test :parser-codegen:test :tools:test --continue, wrapper 9.4.1, only reports written by this run counted): spotless, ArchUnit (22) and pmdMain for every module pass. Tests: shell-core 585, jfr-shell 983, jafar-shell 68, jfr-mcp 415, jafar-processor 44, parser-codegen 246, tools 36 — one failure by name, ShellArtifactTest#commandLineScriptRunsInThisShellAcrossFormats. It asserts the child JVM's stderr holds only progress lines, and this sandbox sets _JAVA_OPTIONS, so every JVM prints Picked up _JAVA_OPTIONS: … there (the first line of the failure message). With env -u _JAVA_OPTIONS, ShellArtifactTest passes 40/40. I did not run the same suites on main for an R6 comparison; the only failing name is explained above. Those numbers are for the first three commits.

After the review follow-up (env -u _JAVA_OPTIONS ./gradlew --no-daemon spotlessCheck :arch-tests:test pmdMain :shell-core:test :jfr-shell:test :jfr-shell:jdkMetadataTest :jafar-shell:test :jfr-mcp:test --continue, fresh reports only): spotless, ArchUnit (22) and pmdMain pass; shell-core 596, jfr-shell 984, jfr-shell jdkMetadataTest 7 (incl. the edited JdkMetadataEndToEndTest), jafar-shell 70 (incl. ShellArtifactTest, with the sandbox's _JAVA_OPTIONS unset), all passing. jfr-mcp failed 2, both ToolCatalogSnapshotTest: the MCP contract snapshot pins the jafar://help/jfrpath text, and the follow-up added one sentence to it. The regenerated snapshot differs by exactly that sentence (accepted in 73b8563, no tool name/parameter/response change, so no jafar-perf skill is affected); :jfr-mcp:test then passes, 415 tests. jafar-processor, parser-codegen and tools were not re-run for the follow-ups; they do not touch them.

Not verified

  • The TUI startup path (TuiShell.openIfPresent): changed the same way as Shell.openIfPresent, not driven (needs a terminal).
  • Windows, where jafar-shell show splits paths containing spaces after argument parsing #233 was reported: verified on Linux only. The bug was in whitespace splitting, which is platform-independent, but no Windows run.
  • jfr_use / jfr_diagnose output after the jfr_tsa reports every sample as thread 'unknown' (jdk.ExecutionSample has no eventThread field) #222 change: same helper, not called through MCP.
  • Liberica JDKs (CI): tested on the Gradle-provisioned Temurin 25 and Ubuntu OpenJDK 21.
  • Gradle versions between 9.4.1 and 9.9.1: only those two were run.
  • The ask transcript writer itself: not driven (it runs after an LLM answer); TranscriptOpenLineTest covers the line it writes (CommandDispatcher.transcriptOpenLine), and PathWithSpacesTest that line opening through a script.
  • The decorateByTime completer text: changed, no test.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Qr5KueVCgqpfF1u1vvFMmR

jafar-processor, parser-codegen and tools read
project(':parser-core').sourceSets.test.output inside dependencies {}.
There project(...) is a ProjectDependency, and Gradle 9.9 no longer
delegates project properties to it, so the build failed to configure:
"Could not get unknown property 'sourceSets' for project ':parser-core'
of type ...DefaultProjectDependency". Each file now resolves the same
expression once, outside the block, where project(...) is the Project.

Verified: on Gradle 9.9.1 (distribution checksum-verified) the unchanged
build fails with exactly that error at jafar-processor/build.gradle:35;
with the change, `help`, the three modules' compileTestJava and
:jfr-mcp:shadowJar succeed. The same tasks succeed on the pinned 9.4.1
wrapper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qr5KueVCgqpfF1u1vvFMmR
extractThreadId/extractThreadName read only eventThread. Execution and
native-method samples carry their thread in sampledThread, so every
sample landed in one bucket "unknown": jfr_tsa reported totalThreads=1,
jfr_diagnose merged that, and jfr_use's active-thread count was 1.

The thread is now read from sampledThread when the event has it, else
from eventThread, as for jdk.JavaMonitorEnter, which the same helpers
serve. Id and name come from the same field, so an event with
both cannot get one thread's id and the other's name.

R5: with the fix reverted, JfrAnalysesThreadAttributionTest fails 3 of
4 tests; the TSA test reports "threads ==> expected: <5> but was: <1>"
on a recording it makes of four named workers plus the main thread.
The checked-in TCK recording could not serve: its samples are
datadog.ExecutionSample, which carries eventThread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qr5KueVCgqpfF1u1vvFMmR
)

The one-shot commands (show, metadata, chunks, constants), the
interactive shell's startup file and the TUI's turned the parsed Path
back into "open <path>" and dispatched it. dispatch() splits a line at
whitespace, so a path with a space opened only up to it. jafar-shell
forwards these commands to the same code.

CommandDispatcher.open(Path, String) opens from the Path and reports a
failure as dispatch() does; the `open` command uses the same code after
parsing its arguments.

R5: with Main.java reverted, PathWithSpacesTest fails with exit 1 and
"Error: /tmp/.../dir" / "No session open" for ".../dir with spaces/
sample input.jfr".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qr5KueVCgqpfF1u1vvFMmR
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Combined JUnit Test Report

  • Total: 3368
  • Passed: 3352
  • Failures: 0
  • Errors: 0
  • Skipped: 16

HTML Test Reports

Run artifacts: https://github.com/btraceio/jafar/actions/runs/44954481280

)

The #222 mistake - reading a sample's thread from eventThread, which
jdk.ExecutionSample and jdk.NativeMethodSample do not have - was in two
more places:

- decorateByTime defaulted to eventThread/javaThreadId on both sides,
  so the documented "samples during monitor waits" query decorated no
  sample. Without threadPath/decoratorThreadPath the op now keeps null
  and each event's own thread is used.
- Stack profiles read eventThread before sampledThread and the OS name
  before the Java name, so a sample's thread there could differ from
  jfr_tsa's, or be the other thread's name.

EventThreads (shell-core, io.jafar.shell.jfrpath) is now the one rule:
sampledThread when present, else eventThread; javaName, else osName;
id and name from the same field. JfrAnalyses, Profiles and Decorators
use it. The MCP query help, JFRPath.md and the tutorial now say so.

Found on the way: a named parameter after fields= in decorateByTime
or decorateByKey failed with "Expected ')'" - parseFieldList read
"threadPath" as one more field - which broke the tutorial's explicit
thread-path example. The field list now stops before `name=`.

R5: with the production changes reverted,
decorateByTimeMatchesASamplesSampledThreadByDefault fails ("row
onThread1 ==> expected: <MyLock> but was: <null>"),
aSampleIsCountedUnderItsSampledThreadsJavaName fails ("expected:
<[worker-0]> but was: <[os-7]>") and namedParametersMayFollowTheFieldList
fails ("Expected ')' [at 96]").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qr5KueVCgqpfF1u1vvFMmR
The previous commit fixed callers holding a Path. The open command
itself still could not open such a path: jfr-shell's dispatcher splits
every line at whitespace and open read only the first word, and the
transcript `ask` writes ("open <path>", unquoted) failed when replayed.
jafar-shell kept the rest of the line, quotes included.

OpenArguments (shell-core) reads open's argument for both shells: the
path is everything up to --alias, or the text in a leading pair of
quotes; quote() writes a path back in a form parse() reads. jfr-shell's
open gets its line unsplit; jafar-shell's uses the same parser and
refuses --alias instead of reading it as part of the path; the
transcript quotes a path when it needs it. JdkMetadataEndToEndTest
opens through dispatcher.open and quotes the path it types.

R5: with the two shells' changes reverted,
PathWithSpacesTest#theOpenCommandTakesAPathWithSpaces fails (`Error:
"/tmp/.../dir`) and both OpenPathWithSpacesTest tests fail ("file not
found: \"/tmp/.../a b.jfr\"" and "file not found: .../plain.jfr --alias
x").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qr5KueVCgqpfF1u1vvFMmR
@jbachorik jbachorik changed the title Fix jfr_tsa thread attribution (#222), paths with spaces (#233), Gradle 9.9 configuration (#228) Fix thread attribution (#222), paths with spaces (#233), Gradle 9.9 configuration (#228) Nov 21, 2026
The previous commit added one sentence to the jafar://help/jfrpath
resource ("Without threadPath/decoratorThreadPath, each event's own
thread is matched: sampledThread for samples, else eventThread."), and
ToolCatalogSnapshotTest pins that resource. The snapshot differs by
exactly that sentence; no tool name, parameter or response shape
changed, so no jafar-perf skill in btraceio/agent-plugins needs an
update (doc/agents/Mcp.md).

Regenerated with ./gradlew :jfr-mcp:test --tests ToolCatalogSnapshotTest
-Dmcp.updateSnapshot=true; :jfr-mcp:test then passes, 415 tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qr5KueVCgqpfF1u1vvFMmR
@jbachorik
jbachorik marked this pull request as ready for review November 21, 2026 21:43
…read paths

From a review of the previous commits:

- OpenArguments.quote() could write a line parse() did not read back:
  a path with whitespace and both quote characters was put in single
  quotes, and parse() stopped at the path's own apostrophe. quote() now
  tries the double-quoted, single-quoted and bare forms and returns the
  first that reads back as exactly the path, else throws; the ask
  transcript then writes a comment saying the path must be opened by
  hand instead of a broken open line.
- A leading quote without a complete quoted form (`'odd.jfr`) was an
  "unclosed quote" error; it is again part of the file name.
- jfr-shell's open used to ignore words after the path ("open rec.jfr
  # main"). When the whole unquoted text names no file but its first
  word does, open keeps doing that and prints a note.
- Parse errors in jfr-shell's open went through dispatch's catch and
  read "Error: Usage: ..."; they are reported as usage messages.
- The decorateByTime completer still named the old defaults.
- DecorateByTimeOp's public thread-path fields could be null; they are
  empty when not given, which means "each event's own thread".
CHANGELOG records the open behaviour changes and the field's new value.

R5: with each fix mutated back, its test fails -
quoteIsReadBackAsTheSamePath/TranscriptOpenLineTest ("unclosed ' in
'/tmp/Bob's \"prod\" run.jfr'"), quoteRefusesAPathNoFormReadsBack
(nothing thrown), aLeadingQuoteWithoutAQuotedFormIsPartOfThePath
("unclosed ' in 'odd.jfr"), trailingWordsAfterAnExistingFileStillOpenIt-
WithANote (script fails on "plain.jfr # main recording"),
aMalformedOpenLineIsAUsageMessage ("Error: Usage: ..."),
omittedThreadPathsAreEmptyNotNull ("expected: <[]> but was: <null>").
The completer text has no test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qr5KueVCgqpfF1u1vvFMmR
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