Repository navigation
End held test processes with their test, and shorten Claude Code title requests - #1774
Merged
Merged
Conversation
Thread titles on Claude Code pages took 2–3 s until 2026-10-04 08:31 PT, then climbed to 15–22 s by 13:55 with unchanged token counts. `claude -p` reported about 1.6 s of model time per request; the rest was the CLI starting and exiting on a machine at load average 200 with no idle CPU. The load came from 154 orphaned shells, each forking `sleep` every 10 ms in `under_codex`'s hold loop, the first of them started at 08:32. A test that failed before releasing its held host left that loop behind: `spawn`'s teardown terminated the fake Codex runner, which shared the worker's process group, and its shell child carried on polling for a release file nobody would write. Failures under load left more loops, which added more load. - `spawn` starts every child in a session of its own, and `_retire` ends the whole group, so a launcher's descendants end with the test. - A held host now waits on its stdin, which the worker holds, instead of polling a file. A release closes the pipe, `_retire` closes it at teardown, and the pipe closes if the worker dies, so no path leaves the shell running. - `_retire` tolerates a leader exiting between its check and the signal, which macOS answers with EPERM. - The carrier-start and three-start waits get hang-bound deadlines. At load 250 they failed on main within the default 10 s, and those two tests had left most of the orphans. - The title request turns off Claude Code's nonessential traffic: 8.4 s rather than 15.8 s at load 200, median of four interleaved pairs. The titles log now records `apiDurationMs` beside `durationMs`, so a slow title shows whether the model or the host spent the time. Behavior covered by the new test: a spawned process's child no longer outlives the process's teardown. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # tests/interact_support.py # tests/test_interact_session.py
A crashed lease holder is now ended with SIGTERM, whose default disposition ends a Python process just as abruptly, so the test still proves that process death releases the lease. Two failure paths that killed a spawned process before failing now leave it to `spawn`'s teardown, or terminate it to read its stderr. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
reviewed
Oct 4, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
spawn still leaves descendants running when the launcher exits before fixture teardown. _retire signals the group only while process.poll() is None; a session leader can exit after starting a child, leaving that child in its group. I reproduced this with /bin/sh -c 'sleep 30 & echo $!': after the shell exited, the fixture's condition skipped killpg and sleep stayed alive. The new test holds its launcher in wait, so it cannot catch this case. The fixture now promises that every process it starts ends with the test; that guarantee needs to cover an exited launcher too, with a test that lets the launcher exit first.
…ithout closing its stdin Review of #1774 found two gaps. A launcher that exits before its child left the child running, because `_retire` signalled the group only while its leader was unreaped; it now also signals a reaped leader's group while no process holds that pid, which POSIX guarantees still names the same group. Closing a held harness's stdin before `communicate()` raises on Python 3.12, so a release now writes the line the shell waits for and leaves the pipe to `communicate`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
approved these changes
Oct 4, 2026
max-sixty
added a commit
that referenced
this pull request
Oct 5, 2026
…#1798) #1774 removed the polling loop that held `under_codex`'s fake Codex task, and every SIGKILL in `tests/`. This change tells the next author the rule that loop broke, and adds a test so the suite rejects SIGKILL again. The loop came from a `tend-ci-fix` run that opened #1104. The section "A process the suite starts ends with the run" in `tests/AGENTS.md` only said which fixture owns each resource. The change did take its process from `spawn`, and two reviews read that as proof of cleanup: "the fixture closes surviving processes on failure". `spawn` only ended the runner, though, so its shell survived. - **`tests/AGENTS.md`** now states the property itself, as checks you can run: - Many suite runs share one machine, so a process a test starts ends on every way out of the test. `spawn`'s teardown ends a child and its group on a pass, failure or interrupt. A worker that dies runs no teardown, so a process that would otherwise run on carries its own link to the worker: the session claim for a page server, the worker's pipe for a held process. - A held process blocks on a pipe the worker holds, as `session_process` does. It never polls for a file the test body has yet to write. - A test ends a process with SIGTERM or by closing that pipe, never SIGKILL. - To check a new held process: make the test fail right after starting it, then run `pgrep -fl <tmp_path>`. On the pre-#1774 tree that finds the leaked shell; on #1774 it finds nothing. - **`test_no_test_ends_a_process_with_sigkill`** reads `tests/*.py` and fails on `Popen.kill()`, `signal.SIGKILL`, signal 9 passed to `kill`, `killpg` or `send_signal`, or a shell `kill -9` / `kill -KILL`. Each form planted in a scratch test made it fail, naming the line, and `os.kill(pid, 0)` still passes. I scored the guidance with and without the new text: | Scenario | Without | With | |---|---|---| | Codex reviewing #1104 in a checkout at its base: flags the leak | 4/6 | 4/6 | | Those reviews: ask for a pipe hold that ends with the worker (instead of a `finally` that keeps the poll) | 0/4 | 4/4 | | Writing a crashed-lease-holder test: avoids SIGKILL | 0/3 | 3/3 | | Writing a session stand-in: blocks on a worker-held pipe | 1/3 | 3/3 | | Reviewing a correct pipe-held test: no false process findings | clean | clean | The guidance doesn't make a reviewer notice the leak more often. What stops it now is #1774's change to `spawn`; the guidance shapes how the fix is written. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
leaf-agent
added a commit
that referenced
this pull request
Nov 22, 2026
This week's duplicate sweep of `dev/`, `build/`, `tests/` and `worker/` (week 47) moves six duplicated helpers onto one home each and moves every caller. Behavior stays the same. The touched model tests, the dev js_facts tests and the Worker's routing, storage and index tests pass. A script compared the old and new outputs of the consolidated `leaf_dev` functions and the seeded-log reads across the corpus, and they match. | Question | Home | Copies removed (introducing PR) | |---|---|---| | Which stylesheets do the core and the bundled packages ship, leaving out vendored files? | new `interact_support.shipped_sheets` | `sheets()` in `test_interface_fonts.py` (#4804) and `test_theme_tokens.py` (#6025). Five inline loops in `test_interact_layer.py` (#3138, #3886) | | Run `tests/js_facts.mjs` | `interact_support.js_facts` (#2666) | its own subprocess call in `dev/tests/test_js_facts.py` (#5118) | | Lowercase hex of bytes in the Worker | `routing.hex`, which is `newSessionId` (#313) renamed, plus a `sha256Hex` in `storage.ts` | the publication-identity and chunk-digest copies in `storage.ts` (#2652) | | Is this pid alive? | `leaf.machine.pid_alive` | `_alive` in `tests/process/test_codex_tool.py` (#3331). `running()` in `test_interact_layer.py` (#1774) | | Read an example's seeded log | `read_event_lines(seed_log(source))` (#4484) | inline parsers in `test_render_pages.py`, `test_interact_product.py` (#924) and `test_render_gate.py` (#509). The last one split lines with `splitlines()`, which also breaks at U+2028 | | Paths of the bundled registries and packages; which registry keys name elements | `leaf.schema.ASSETS` / `BUNDLED_PACKAGES` / `DEFAULT_PACKAGE`, `leaf.registry.contract.is_element_name`, `docs.registries()` | `docs.py`'s own `ASSETS`/`PACKAGES` (#3593) and its `startswith("lf-")` checks (#2660). `logs usage`'s hand-written regex and registry list (#5970). `ROOT / "packages" / "default"` in `stills.py` (#3927) and `test_product_page.py` (#3593) | `is_element_name` and the two checks it replaces give the same answer for every key in the bundled registries today. A selector key such as `lf-options.selected` would have passed the `lf-` prefix test. <details><summary>Sets found and left alone</summary> - **Sets an open PR is changing.** Nothing in this diff overlaps another open PR's hunks. #6732 moves tests out of `test_render_gate.py`, `test_render_pages.py` and `test_interact_layer.py`, but none of the tests changed here. - **Changes to browser tests with nothing run to check them.** The WCAG contrast computation exists as about 11 copies across browser, journey and model tests. Other copies: about 9 `EDITOR_ROOTS` shadow-root keepers, the `/api/interaction` batch predicates, CDP `touch()` closures, one-line patch templates, reply-holding route handlers, and the `data-lf-entry` runtime-module import snippet in `dev/leaf_dev/states.py` and in tests. Each would mean editing browser tests that this sweep can't run on a shared host. They suit a sweep that can run those tests. - **Vendor bundling.** `build/browser/build.mjs` builds signals-core and Lit with esbuild calls that repeat `build/vendor.mjs`'s `bundle()`. Merging them changes build options and needs a full `check:browser` byte comparison, so it was left for a change that runs that. - **Copies that are near but not the same.** `_build.py`'s `check_links` repeats `leaf_website.released_path`, but it also needs the matched page's root and kind. The list of API-key variables an eval drops is repeated across Python and the Promptfoo configs, as subsets and supersets of one another. The Codex token-expiry check has different thresholds, 1 h and 60 s. - **Too small to be worth it.** Picking a free loopback port (`eval_user.py`, `interact_support.available_loopback_port`). The XDG state root in `leaf_dev.state_home` and `leaf.state.state_home`. The `settled` helper in two `tests/runtime` files. </details> Co-authored-by: leaf-agent <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thread titles on Claude Code pages went from 2–3 s to 15–22 s over 2026-10-04, though
claude -preported about 1.6 s of model time per title. The rest was the CLI starting and exiting on a machine at load average 200+ with no idle CPU. Most of that load came from 154 orphaned shells left byunder_codex, each forkingsleepevery 10 ms while it polled for a release file. A test that failed before releasing its held fake Codex process left one behind, because teardown ended only the fake Codex runner and not the shell under it. Failures under load left more shells, which added more load.spawnstarts every child in a session of its own, and_retireends the whole process group, so a launcher's descendants end with the test, including when the launcher itself has already exited.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1. At load 200 that took the median request from 15.8 s to 8.4 s, over four interleaved pairs. The titles log also recordsapiDurationMs, so a slow title shows whether the model or the CLI process spent the time.test_a_spawned_process_ends_with_what_it_startedcovers the teardown and fails against the oldspawn.