Repository navigation
Record where the suite's time goes in every CI test run - #2345
Conversation
The complete suite's test job takes about four hours and its junit report records one total per test, so nothing said how a browser test's ~8.5 s splits between setup, page preparation, waiting on the browser, and the test's own Python. The test job now records three readings beside the junit report and prints a summary of them into the job summary: - `leaf_dev.suite_profile`, a pytest plugin in addopts, gives each test a junit `profile` property: its setup, call and teardown seconds, and its time in Playwright's sync API keyed by method and calling frame. Playwright runs its event loop in a second greenlet, so a sampling profiler sees a browser wait as an idle event loop with the test off the stack; timing each call where it is made keeps the attribution. - py-spy samples every Python process the run starts at 20 Hz, waits included, for the suite's own Python by function. - BSD process accounting gives the run's CPU by command, for Chrome, Node and the servers no Python stack shows. The job is CPU-bound, so this is where the runner's capacity goes. `leaf-dev suite-profile DIR` reads the three from a downloaded `pytest-results-*` artifact. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The PR run's stacks held command lines with newlines and bytes that are not UTF-8, which the line-by-line reader rejected. At 20 Hz py-spy took 16 of the run's 157 CPU minutes; 5 Hz keeps thousands of samples an hour per worker. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The CPU-by-command reading includes work outside the test suite. accton enables system-wide process accounting, while this job starts Python tests with background: true and runs Build website before Wait for Python tests. The resulting sa table therefore includes the overlapping site build's Node and other processes, so its totals cannot identify where the suite's CPU went. Please scope that reading to the pytest process tree, or arrange for the accounting window to contain only suite work.
At 5 Hz py-spy still took 4.5% of the PR run's CPU. The job's PY_SPY_RATE now sets both py-spy's rate and the rate leaf-dev suite-profile turns samples into minutes with. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ild processes The wrapper's frame sat between Playwright and the caller, so Playwright's traces and protocol metadata named the profiler as each call's site; its code is now filed under Playwright's package, which that attribution skips. A call failure with a teardown error is two junit cases, the profile on the second; the summary now reads them as one test. The summary also lists the Python processes tests start, whose work a test's own stack shows only as a wait. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The CPU attribution concern from the draft review still prevents approval on this head.
Process accounting is machine-wide, and a pull request's job builds the website beside the suite, so its table mixed the two. Main, the schedule and a dispatch run nothing else meanwhile. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
left a comment
There was a problem hiding this comment.
The Python stack reading can silently disappear from a green test job when py-spy fails.
A py-spy that could not attach or sample left the job green with no stacks, and the summary skips a missing stacks.txt, so the reading would vanish unnoticed. The job now fails, keeping pytest's own failure status where it has one. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Main's vulture hook, which arrived beside #2345, flags it; pluggy passes a hook implementation only the arguments it names. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Main's vulture hook, which arrived beside #2345, flags it; pluggy passes a hook implementation only the arguments it names. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Main's vulture hook, which arrived beside #2345, flags it; pluggy passes a hook implementation only the arguments it names. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Main's vulture hook, which arrived beside #2345, flags it; pluggy passes a hook implementation only the arguments it names. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… module once (#2395) `javascript_imports` walked every node of a module's syntax tree in Python. The 5 MB vendored mermaid bundle is composed into every page that selects the diagram package, and for it that walk added about 0.9 s to a 0.9 s parse. On #2345's profiled PR-gate run, `javascript_imports` took 21% of all test time, nearly all of it inside page inits. - **Query instead of walk.** A tree-sitter query matches the import, export, `import()` and JSX nodes in the parser's own code. The same checks then run on what the query returns, in document order, so the first problem in a file is still the one reported. Over the 3,468 JavaScript files in the checkout and `node_modules`, it returns the same imports and errors as the walk. On mermaid it takes 1.3 s of CPU instead of 1.8 s. - **Parse each module once per process.** The result is memoized per (bytes, path). A layer's modules are the same bytes in every page that selects them, so a test worker or a server that composes many pages parses each module only once. The function now returns a tuple instead of yielding. #2327 lends pooled pages again, which already cuts most per-test inits. This change covers the inits that remain: tests that initialize a page themselves, layer-registry pages, and the first page of each shape in each worker. It also shortens a user's own `leaf page init` and export. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
…weep (#5291) A sweep on 2026-11-03 found 39 capabilities implemented more than once in Leaf. Tend's review had approved all 10 of the introducing pull requests checked, and 15 nightly surveys that carried the instruction to look for "several implementations of one capability" reported none. This changes the instructions behind both, and adds a weekly sweep for what review still misses. - **Review loads `/developing-leaf`.** running-tend's Review threshold named that skill's "Weigh what a change adds" without saying to load it, and none of 11 production reviews on 2026-11-03 did. The section now opens "Load `/developing-leaf`"; 16 of 16 replayed reviews then loaded it. - **"What it repeats"** joins "Weigh what a change adds": search for the question each new helper, constant, selector, style rule or inline check answers rather than its name, count a copy whose comment names its source as a copy, and export, move or generate the owner rather than copy it. "Regular maintenance" points its "Several implementations of one capability" bullet at it, since the nightly survey reads one file at a time. - **Weekly: duplicate implementations** sweeps one area a week, chosen by ISO week number modulo 4, searching the whole tree by question. Each copy's introducing pull request goes in the sweep's description, so the copies added since the area's last sweep show what review let through. Replaying four pull requests that each introduced a copy (#3832, #5196, #2345, #3137), reviewers caught the copy 2 of 9 times with the old text, 3 of 8 when told to load the skill, and 5 of 8 with "What it repeats", whose wording was revised after the replay. That difference is within noise at this size, and no arm caught a one-line copy inside a new helper; the weekly sweep is there for those. This changes agent instructions, so it lands with the control-plane owner's approval (running-tend, "Landing"). > _This was written by Claude Code on behalf of max-sixty_
The complete suite's
testjob runs for about four hours, but its junit report records only one total per test. Nothing said how a browser test's ~8.5 s divides between setup, page preparation, waiting on the browser, and the test's own Python. This PR adds that reading to every run of the job. It's the first step in cutting the suite's cost.The job records three readings beside the junit report, and
leaf-dev suite-profilewrites a summary of them to the job summary:leaf_dev.suite_profileis a pytest plugin, loaded inaddopts. It gives each test aprofileproperty: setup, call and teardown seconds, plus time spent in Playwright's sync API, keyed by method and calling frame. Playwright runs its event loop in a second greenlet, so a sampling profiler sees a browser wait as an idle event loop, with the waiting test off the stack. Timing each call where the test makes it keeps the attribution. The wrapper's code is filed under Playwright's package, so Playwright's own traces still name the caller.stacks.txt) that speedscope and flamegraph.pl also read. The summary lists the suite's own functions under the test protocol, and separately the Python processes the tests start, whose work a test's stack shows only as a wait. The job'sPY_SPY_RATE(2 Hz) sets the rate for both py-spy and the summary. py-spy's own CPU cost scales with the rate: on the PR gate, 20 Hz took 10% of the run's CPU and 5 Hz took 4.5%.cpu-by-command.txt). This covers Chrome, Node and the servers that no Python stack shows. The job is CPU-bound, so this is where the runner's capacity goes. Accounting is machine-wide, so it runs only on main, scheduled and dispatched runs, where the suite is the only work during the pytest step; a pull request builds the website alongside it.py-spy attaches to
uv run's process tree by pid instead of wrapping the command, because as a wrapper it drops pytest's exit status. Yama'sptrace_scopeis set to 0 on the runner so py-spy can read processes it did not start.On this PR's gate run (3,027 tests, before #2327 restores the page pool), 46% of test time was spent in Playwright. Most of that was
Page.gotoat about 1.1 s a call and the runtime readiness wait. Page init took 27% of test time, and parsing the 5 MB vendored mermaid bundle for its imports (javascript_imports) took 21% by itself.