Skip to content

fix(javascript): yield during per-file projection and graph construction - #1525

Merged
kaoru0822-kitauji merged 3 commits into
mainfrom
fix/javascript-graph-construction-steps
Oct 10, 2026
Merged

kaoru0822-kitauji merged 3 commits into
mainfrom
fix/javascript-graph-construction-steps

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Refs #1462 (T2 responsiveness under #1065). This removes the long event-loop blocks after the per-file stage and splits the per-file stage itself. A residual remains and is described below.

Where the pauses were

Measured in-process with a 1 ms interval timer recording event-loop gaps, plus the issue's SDK stdio probe. On the issue's 1,200-function fixture (SHA-256 1c6cafca…7711) on main:

phase longest block
per-file stage for index.js (parse 13, receivers 11, static 16, semantic 71, projection ~130 ms) ~250 ms
buildImmutableJavaScriptArtifactGraphSteps: all add* phases plus the factory's synchronous parse, content check and digest run before the first step ~270–290 ms
finishImmutableSteps: the semantic factory's synchronous whole-graph schema parse and normalization ~275 ms (≈1.5–3 s on Obsidian)

Change

  • Per file (analyzeAndProjectJavaScriptArtifactFiles): parse, receivers/static analysis, semantic analysis and each of the ~17 semantic projection passes are now steps. They are driven by the existing time-sliced completeJavaScriptAnalysisSteps (8 ms slices, abort checks). projectFileSteps is new on JavaScriptSemanticGraphProjection; the synchronous projectFile and analyzeJavaScriptArtifactFiles drain the same steps, so their results are unchanged.
  • Application graph input: buildImmutableJavaScriptArtifactGraphSteps is a generator. It yields between phases, per module link (addJavaScriptModuleRelationshipsSteps) and per file of findings (addJavaScriptStaticFindingsSteps). buildJavaScriptArtifactGraph drains it synchronously.
  • Sealing: new sealTransferredJavaScriptApplicationGraphSteps and sealTransferredJavaScriptSemanticGraphSteps are for inputs the caller transfers, meaning it neither retains nor mutates them. They validate the graph's own fields and container constraints (such as nodes.min(1)) synchronously. Elements are then validated (and cloned) in steps through the new src/domain/zodCollectionSteps.ts, followed by the content checks (checkGraphContentSteps, now stepwise) and the canonical digest. Only the analysis pipeline uses them, because it builds those inputs privately. It now passes a copy of fingerprints, which it clears afterwards.
  • Unchanged: the public createImmutable…GraphSteps factories keep their synchronous deep capture. That capture is pinned by captures nested input before yielding…, which still passes. A content-check failure in the transfer path re-runs the content schema, so the error is the exact ZodError the copying path reports.

Results are identical

reconstructJavaScriptArtifact on main and on this branch gives the same application graph ID, semantic graph ID and SHA-256 of the complete serialized result for:

Measured effect

1,200-function fixture, in-process: the longest event-loop block goes from about 290 ms to about 90 ms.

The issue's MCP probe (warmed SDK stdio client, abort, then ping), swept over abort times of 50–600 ms on an M-series Mac:

worst ping after abort
main 286 ms (abort at 250 ms)
this branch 56 ms

The client wait ended within about 2 ms of each abort, as before.

Obsidian obsidian.asar (36 files), full in-process analysis:

longest block total
main 10.9 s (app.js analysis plus projection) 41.1 s
this branch 5.4 s 41.7 s

The post-file graph phases no longer appear among the longest blocks.

Residual (not fixed here)

The remaining multi-second blocks are single analyzer stages on very large single files: analyzeParsedJavaScriptSemantics or static analysis of Obsidian's 3.7 MB app.js (about 5.4 s) and lib/mermaid.min.js (about 4.4 s). Splitting those needs either steps inside the domain analyzers or an owned execution boundary such as a worker. Both are larger design changes, so I left #1462 open.

Verification

  • A new test in JavaScriptApplicationCancellation.test.ts ([Bug] JavaScript analysis blocks MCP ping and cancellation during synchronous computation #1462) aborts three event-loop turns after the one large file starts, and checks that cancellation lands before build_javascript_application_graph. On main it fails because the phase list includes that phase.
  • New tests in javascriptApplicationAnalysisSteps.test.ts: the transfer factories seal graphs equal to the copying factories, and those graphs are validated and immutable. For a malformed semantic node and a stale application node ID, they report the same issues as the whole-graph parse.
  • npx vitest run src/domain src/application passes (169 files, 2,131 tests).
  • npm run test:focused passes on tests/composition/javascript-applications, tests/acceptance/applications/{javascript,application}*, tests/boundary/mcp/{application,analysisView}* and tests/boundary/cli/analysisView* (20 files, 111 tests).
  • npm run check:fast and npm run docs:check pass. One new non-blocking warning: max-lines on javascriptApplicationGraph.ts, where the ownership WeakSet and the new sealing steps must share a module. JavaScriptSemanticGraphBuilder.ts and javascriptSemanticGraph.ts already carry max-lines warnings on main.
  • Not run: Linux, Node 22/24, two-CPU constrained hosts, or the Notion ASAR from the issue.

🤖 Generated with Claude Code

analyze_javascript_application ran several long phases with no event-loop
turn, so MCP ping and cancellation waited: each file's parse, analysis and
semantic projection; building every application node and relationship
before the application graph's first sealing step; and whole-graph schema
parses inside both immutable graph factories.

- Each file runs as steps (parse, static analysis, semantic analysis, then
  each projection pass), driven by the existing time-sliced checkpoint.
- Application graph input construction yields between phases, per module
  link and per file of findings.
- The pipeline transfers its privately built graph inputs to new sealing
  steps that validate the graph's own fields synchronously and elements,
  content checks and the digest in steps. The public copying factories
  keep their synchronous capture.

Results are unchanged: graph IDs and the complete result digest match main
on five inputs including Obsidian's 23 MB obsidian.asar. On the issue's
1,200-function fixture the longest event-loop block falls from about
290 ms to 90 ms, and ping after abort from up to 286 ms to at most 56 ms.
On obsidian.asar it falls from 10.9 s to 5.4 s; the rest is one analyzer
stage of a single very large file.

Refs #1462

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator Author

The red CI here doesn't come from this PR. Shard 3/4 fails only on the #1495 wall-time test from #1517 (3.6 s against a 2 s bound under v8 coverage), and main at 46c9cba fails the same way (3.2 s). #1529 replaces that bound with a growth-ratio check. This PR's own tests passed in that shard, including the new in-file cancellation test. I'll rerun CI here once #1529 is merged.

@N0zoM1z0

Copy link
Copy Markdown
Collaborator

Independent Linux x64 review of 9f68c82d integrated with main 46c9cba0 (then the test-only #1526 merge): Node 24.18.0, two CPUs, one heavy lane, 2,304 MiB family-RSS guard. The source keeps the copying factories intact and moves only privately built graph inputs to the transferred sealing path.

The real ASAR (SHA-256 97c41bc1…63069d4) retained exactly the same complete Evidence ID (ev_fbe07b5de34746c9191fadb98a2bf6a33d00c9073baa690c75db5c4df3618d98). Full SDK analysis, retained summary/page/trace, self-comparison rejection, close/expiry/ping and unchanged input all passed. In this single pair, analysis was 104,791.9 → 116,486.0 ms; max ping was 30,822.4 → 9,703.8 ms; sampled peak family RSS was 1,728,884,736 → 1,639,112,704 bytes. This supports a control-responsiveness improvement with a wall-time tradeoff, not a throughput or percentile claim.

On the issue's exact 1,200-function source SHA 1c6cafca…83ad7711, a warmed actual SDK stdio client aborted at ~200 ms. Client waits ended at 201.4 / 203.9 ms; ping after abort changed from 1,175.4 → 131.4 ms. Both runs retained zero Evidence, completed a new small analysis and close/ping, and preserved the source.

37 focused tests across application cancellation/service, graph validation/ownership, and compiled CLI/stdio-MCP return/iteration workflows passed. Strict typecheck/lint pass. A final public retained-view and #1526 regression pass has also been run. No Hopper/Ghidra claim or lane applies to this JavaScript change.

The CI shard failure is the existing main #1517 timing assertion, observed at 3,610.3 ms versus its 2,000 ms threshold (Test shard (3/4), job 114183425881). #1526 has now fixed it on main f9ce32b4; the cooperative-phase implementation was not the failing assertion. I will advance this branch with the tested main integration while preserving the original contribution, then wait for final-head CI. #1462 remains open: the ASAR still has multi-second file blocks, and a ping attributed to the last semantic-sealing progress note waited ~1.43 s; that attribution is observational, not a CPU-profile proof of its exact owner.

@kaoru0822-kitauji
kaoru0822-kitauji merged commit 5fdb063 into main Oct 10, 2026
20 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/javascript-graph-construction-steps branch October 10, 2026 10:14
kaoru0822-kitauji added a commit that referenced this pull request Oct 10, 2026
…passes (#1542)

* fix(javascript): yield inside semantic analysis and large projection passes

After #1525 the longest event-loop blocks were single stages on very large
files: semantic analysis of Obsidian's 3.7 MB app.js ran 5.8 s in one piece,
and its object projection 1.8 s.

- analyzeParsedJavaScriptSemanticsSteps yields between the analysis phases
  and between the eight derived collectors; the synchronous function drains
  it, so results are unchanged.
- Per-file analysis yields between open-receiver classification and static
  analysis and drives the semantic steps.
- Semantic node creation, definitions and references, and the object and
  frontier passes yield every 64 items. Node creation keeps source order,
  which the per-file node budget depends on.

On obsidian.asar the longest block falls from 5,355 ms to 907 ms with the
same total time (40.6 s to 39.5 s). Graph IDs and complete result digests
match main on five inputs. Remaining blocks up to about 0.9 s are single
AST traversal passes inside the analyzers.

Refs #1462

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* refactor(javascript): drop the unused synchronous derived-semantics wrapper

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…ion (morluto#1525)

analyze_javascript_application ran several long phases with no event-loop
turn, so MCP ping and cancellation waited: each file's parse, analysis and
semantic projection; building every application node and relationship
before the application graph's first sealing step; and whole-graph schema
parses inside both immutable graph factories.

- Each file runs as steps (parse, static analysis, semantic analysis, then
  each projection pass), driven by the existing time-sliced checkpoint.
- Application graph input construction yields between phases, per module
  link and per file of findings.
- The pipeline transfers its privately built graph inputs to new sealing
  steps that validate the graph's own fields synchronously and elements,
  content checks and the digest in steps. The public copying factories
  keep their synchronous capture.

Results are unchanged: graph IDs and the complete result digest match main
on five inputs including Obsidian's 23 MB obsidian.asar. On the issue's
1,200-function fixture the longest event-loop block falls from about
290 ms to 90 ms, and ping after abort from up to 286 ms to at most 56 ms.
On obsidian.asar it falls from 10.9 s to 5.4 s; the rest is one analyzer
stage of a single very large file.

Refs morluto#1462

Co-authored-by: N0zoM1z0 <[email protected]>
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…passes (morluto#1542)

* fix(javascript): yield inside semantic analysis and large projection passes

After morluto#1525 the longest event-loop blocks were single stages on very large
files: semantic analysis of Obsidian's 3.7 MB app.js ran 5.8 s in one piece,
and its object projection 1.8 s.

- analyzeParsedJavaScriptSemanticsSteps yields between the analysis phases
  and between the eight derived collectors; the synchronous function drains
  it, so results are unchanged.
- Per-file analysis yields between open-receiver classification and static
  analysis and drives the semantic steps.
- Semantic node creation, definitions and references, and the object and
  frontier passes yield every 64 items. Node creation keeps source order,
  which the per-file node budget depends on.

On obsidian.asar the longest block falls from 5,355 ms to 907 ms with the
same total time (40.6 s to 39.5 s). Graph IDs and complete result digests
match main on five inputs. Remaining blocks up to about 0.9 s are single
AST traversal passes inside the analyzers.

Refs morluto#1462


* refactor(javascript): drop the unused synchronous derived-semantics wrapper


---------
@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: This merged while I tested, and the squash 5fdb0636 has the same code as the head I tested. On Node 24, the worst app pause drops from 4.1 s to 1.6 s, and the worst ping after a cancel from 554 ms to 169 ms. Results match main byte for byte, and the pause left is one analysis step on one big file.

I tested main 72b3209f against your head b88d8f85 on Node 22, 24 and 26. The merge base has the same code as main. The two open-source apps are the Beyond All Reason launcher (MIT) and a vendor chunk from Hermes Desktop (MIT). The launcher's Flathub build is out under GPL-2.0-or-later, as its own metadata file says. My copy of the issue's 1,200-function file has the same SHA-256 as yours, 1c6cafca…7711.

Ping wait after the abort at 200 ms, in ms. Each cell is the median of 3 runs.

Functions Tree Node 22 Node 24 Node 26
300 main 101 154 139
300 #1525 29 5 3
1,200 main 599 387 352
1,200 #1525 127 39 19
2,400 main 1,136 837 800
2,400 #1525 6 203 194

Longest ping wait in one full app run, in seconds. Each cell shows two runs, with a ping every 250 ms.

App Tree Node 22 Node 24 Node 26
Launcher main 5.0 / 5.0 4.2 / 4.1 4.0 / 4.1
Launcher #1525 1.8 / 1.8 1.6 / 1.6 1.7 / 2.0
Hermes chunk main 4.3 / 4.3 3.6 / 3.5 3.2 / 3.3
Hermes chunk #1525 1.6 / 1.6 1.1 / 1.1 1.1 / 1.1

Where the event loop stops, on Node 24, longest block in ms. A timer in the server logs each gap, and a CPU profile shows what runs in it.

Block Launcher main Launcher #1525 Hermes main Hermes #1525
Parse and project one file 2,526 1,870 3,897 1,279
Build the app graph 4,338 412 under 50 under 50
Build the semantic graph 1,505 288 347 68
Seal, check and hash 125 131 under 50 under 50

Main and #1525 gave the same app graph ID, semantic graph ID and Evidence SHA-256 on all four targets. All 126 cancels worked on both trees, and both changed test files pass on Node 22, 24 and 26. The IDs and details are in the folds below.

Not run

  • The closed-source app from the issue. It is not on this box.
  • The other apps from your post.
  • Profiles on Node 22 and 26.
  • More runs to settle the Hermes gap on Node 26.
  • The squash 5fdb0636 itself. I only checked that its code matches the head.
  • Windows and macOS.

Thanks, kaoru0822-kitauji, for the step split and for the test that cancels inside one large file.

More notes on the tables
Same results, cancels and tests

Main and #1525 gave the same results, byte for byte:

Target App graph Semantic graph Evidence SHA-256
1,200 file jag_7954b291… jsrg_5bf209a5… 02c2552e…
#1495, N = 2,000 jag_08064206… jsrg_cf6d6cd0… b8321413…
Hermes chunk jag_d6d7e759… jsrg_9bbda37e… 98e03aba…
Launcher jag_d14a032b… jsrg_6107e0c5… 98910b36…
Abort sweep, Node 24, 1,200 functions

Ping wait after the abort, ms, median [min–max] of 3:

Abort at main #1525
50 538.8 [537.8–547.6] 38.3 [35.2–38.6]
100 481.8 [475.6–491.7] 141.4 [138.0–148.6]
150 440.9 [432.5–457.7] 91.0 [85.8–100.0]
200 391.9 [386.3–440.4] 39.1 [38.8–39.2]
250 341.5 [332.4–357.9] 168.5 [167.2–168.6]
300 286.6 [281.6–287.4] 119.7 [109.2–121.0]
350 236.8 [230.9–253.6] 65.6 [56.3–66.4]
400 202.9 [185.5–207.9] 12.8 [10.2–26.9]
450 138.3 [127.7–149.5] 60.8 [52.4–66.3]
500 83.1 [82.7–88.8] 14.0 [12.1–30.9]
550 32.6 [22.6–35.3] 14.6 [5.1–39.9]
600 545.1 [542.1–553.7] 2.6 [2.2–7.4]
  • This is a second set of 3 runs, so the 200 ms row reads 391.9 and 39.1 here. The table above has 386.8 and 39.4 from the first set.
  • On main, the file block ends near 590 ms. At 600 ms the abort lands in the app graph block of about 575 ms.
  • With fix(javascript): yield during per-file projection and graph construction #1525, the worst spot is 250 ms. In the profile, the two longest stops on this file are 173 ms of semantic analysis and 182 ms of projection setup. The profiler slows the run a little, so I can't say which of the two the 250 ms abort hit.
Raw numbers

Abort at 200 ms, ms, median [min–max] of 3:

Case Ping after abort Server stop
main, 300, Node 22 100.8 [95.7–107.2] 303.8 [299.0–310.3]
main, 300, Node 24 153.9 [146.3–155.6] 357.0 [350.1–357.5]
main, 300, Node 26 138.8 [134.6–157.0] 340.1 [337.2–357.9]
#1525, 300, Node 22 29.0 [20.1–34.3] 231.2 [221.9–235.6]
#1525, 300, Node 24 5.4 [4.3–5.8] 207.6 [206.2–207.8]
#1525, 300, Node 26 3.1 [3.0–4.0] 204.2 [204.0–214.1]
main, 1,200, Node 22 599.0 [584.9–626.7] 801.3 [787.2–829.3]
main, 1,200, Node 24 386.8 [377.5–416.8] 587.7 [579.9–618.6]
main, 1,200, Node 26 352.2 [347.2–356.2] 553.4 [548.1–557.3]
#1525, 1,200, Node 22 127.0 [118.9–140.9] 329.9 [320.5–344.3]
#1525, 1,200, Node 24 39.4 [39.2–39.8] 241.3 [240.9–242.5]
#1525, 1,200, Node 26 18.8 [17.1–26.9] 222.3 [218.0–228.9]
main, 2,400, Node 22 1,136.1 [1,131.8–1,159.2] 1,338.0 [1,334.0–1,365.2]
main, 2,400, Node 24 837.3 [823.9–862.4] 1,040.9 [1,028.9–1,064.3]
main, 2,400, Node 26 800.0 [766.7–806.1] 1,003.3 [969.2–1,007.7]
#1525, 2,400, Node 22 5.5 [5.0–8.8] 210.4 [208.4–211.8]
#1525, 2,400, Node 24 202.6 [197.3–209.6] 405.1 [399.4–411.9]
#1525, 2,400, Node 26 193.7 [191.1–194.2] 395.3 [392.8–395.6]

"Server stop" is REA's own tool-done log line, in ms from the call.

Full analysis time, s, as REA logs it, two runs:

App Tree Node 22 Node 24 Node 26
Launcher main 45.0 / 45.7 38.9 / 39.0 38.3 / 38.7
Launcher #1525 45.3 / 45.5 38.6 / 38.9 38.1 / 39.1
Hermes chunk main 7.37 / 7.20 6.23 / 6.19 5.68 / 5.77
Hermes chunk #1525 7.35 / 7.35 6.24 / 6.22 5.91 / 5.94
How I measured
  • Each run used one stdio MCP session, with the SDK 2.3.1 client from the tree under test. It is the same harness as in my [Bug] JavaScript analysis blocks MCP ping and cancellation during synchronous computation #1462 posts.
  • Server: node --max-old-space-size=3072 scripts/rea.mjs mcp, or 4,096 for the apps.
  • Abort runs sent one ping right after abort(), as in the issue's repro, and no other pings.
  • App runs sent a ping every 250 ms. Then came an Evidence export, a small call and close.
  • Each run used env -i, its own HOME and temp folder, taskset -c 2,3 and nice -n 10.
  • Main and fix(javascript): yield during per-file projection and graph construction #1525 ran mixed together in every set.
  • Profile runs added --cpu-prof at 1 ms. A preload ran a 10 ms timer and logged each gap over 50 ms. I split the profile samples in each gap by the REA step on the stack. Matching a function name to a step is my reading of the code.
  • The CLI runs used rea analyze-javascript-application <input> --artifact-format <format> --json. I hashed its full output.
  • Load is the count of programs that run on, or wait for, one of this box's 24 CPU threads. Linux takes the average over one minute.
  • Before each set, I waited for load to drop under 2. It never had to wait. Load was 0.3 to 1.9 at the start of every run.
Commands
git -C rea.git archive b88d8f859b031763f708c8a018ddd50c0e04dfe6 | tar -x -C pr
cd pr && npm ci && npm run build
# abort runs, and the sweep with --cancel-ms 50 … 600
node client.mjs --root pr --fixture f1200 --mode at-offset --cancel-ms 200 \
  --ping-ms 0 --retained-check --next-small f3 \
  --server-node-args --max-old-space-size=3072
# app runs
node client.mjs --root pr --fixture app.asar --format asar --mode none \
  --ping-ms 250 --ping-timeout-ms 45000 --call-timeout-ms 210000 \
  --export-evidence "$TMPDIR/ev.json" --next-small f3 \
  --server-node-args --max-old-space-size=4096
# identity
node scripts/rea.mjs analyze-javascript-application <input> \
  --artifact-format <directory|asar> --json | sha256sum
# tests
npm run test:focused -- \
  src/application/javascript/JavaScriptApplicationCancellation.test.ts \
  src/domain/javascript/javascriptApplicationAnalysisSteps.test.ts
npm run check:fast
Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads (runs pinned to 2)
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1 (built on 24.18.0)
  • Head / base: b88d8f85 / 72b3209f
  • Other: MCP SDK 2.3.1
  • Other: the Beyond All Reason launcher (MIT)
  • Other: the launcher's Flathub build, which is out under GPL-2.0-or-later
  • Other: Hermes Desktop (MIT)

🤖 Generated with Claude Code (Opus 5.5) 🦊

@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants