Repository navigation
A command's last output is awaited instead of polled, and the LLM runner's tests answer in-process - #280
Merged
Conversation
…ner's tests answer in-process ProcessRunner waited for a command's pipes to close after it exited by sleeping 50 ms at a time. In a full test run 457 of 665 commands (69%) had a pipe still open at the exit, and those waits added up to 55 s; each also cost a trip back through the cooperative pool. The buffers now resume a continuation at the pipe's end, abandon it after the same two seconds, and return at once when the task is cancelled, as before. The same run now spends 10.5 s there. Two tests cover it: output a child writes after the exit is kept, and a child that holds the pipes is not waited for. LLMRunner takes an `execute` closure for its commands (detection checks and calls), `LLMRunner.process` by default. Its tests answer through an in-process `FakeAgent`: the queue tests hold calls on a continuation and count what is answering and waiting, so they no longer depend on shell scripts starting within ten seconds on a loaded machine, and the concurrency test counts the most calls at once instead of timing them. Four tests keep the shell-script agent to prove the process path: the login check, stderr as the reason, the timeout, and the call log row. The host's `heed` test awaits its process instead of `waitUntilExit`, which hung indefinitely after the test resumed on another thread, and waits as long as the script allows rather than ten seconds. The repo scanner test scans a folder of its own instead of the shared temporary directory (71,000 entries on this machine). Co-Authored-By: Claude Opus 5.5 <[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.
Fixes
LLMRunnerTests.interactiveCallsGoFirstfailing in full-suite runs and cuts the suite's wall time.Diagnosis (measured on this machine, load average 125–235 throughout)
Task.sleep. Its first sleep came back after 16.4 s. After that, sleeps mostly overshot by 5–10 ms. Swift Testing starts every test at once, so for about the first 16 s each continuation waits behind the whole backlog. That is why nearly every test reports 16–17 s in the xunit file. Every await costs seconds during that window.interactiveCallsGoFirstneeds a dozen or more of them before its shell-script agent records the first call, which is how it ran past its 10 s deadline (failed 4 of 4 baseline runs here).sampleduring runs showed all 8 cooperative threads busy in CPU-bound synchronous tests. The largest was TurnEnd's regex: one thread for 30–58 s. Reading a turn's last words is fast on long messages #272 fixed that, and the baseline below already includes it. There were a fewwaitUntilExitcalls (TempRepo and others), about 1% of pool samples. No test was sleeping or spinning on the pool.HostCallTests.theHostsHeedWritesItsCallAndPrintsTheAnswerhung for more than 10 minutes inwaitUntilExitafter the test resumed on another thread, with no child process left (seen in a--no-parallelrun). In parallel runs it failed once when its script's 20 s timeout fired first.scannerFindsMainCheckoutsOnlystats every entry of$TMPDIR, which has 71,242 entries here: tests leak folders, 14,207 of them from the LLM runner's FakeCLI.Changes
ProcessRunner: each pipe buffer resumes a continuation when its pipe ends. Collection gives up after the same 2 s, and returns at once when the task is cancelled, as the old loop did. New tests cover both cases: output written after the exit is kept, and a child that holds the pipes is not waited for.LLMRunner: a newexecute: Executeparameter, defaulting toLLMRunner.process, runs detection checks and calls. It is built the same way as the existingresolve. Production behaviour is unchanged.LLMRunnerTests: an in-processFakeAgentnow answers 26 of the 30 tests. The queue tests hold calls on a continuation.noMoreThanTheConcurrencyRunAtOncecounts the most calls running at once instead of asserting that at least 2 s passed. Four tests keep the shell-script FakeCLI to prove the process path: the login check, stderr as the reason, the timeout, and the call log row.HostCallTests: the test awaits its process throughterminationHandler. It waits as long as the script allows, under a 2-minute time limit.scannerFindsMainCheckoutsOnly: the test scans a folder of its own.Timings (
swift test --skip-build, full suite, 3 runs each)The machine was less loaded during the after runs, so part of the drop comes from that. The probe numbers above (time spent waiting for pipes, process count) do not depend on load. Rebased onto #274/#275, the full suite passed in 34.0 s.
Slowest tests, median, before → after. These times include the start-of-run queue wait: RunGit aRunPushes… 34.7 → 20.2 s, scannerFindsMainCheckoutsOnly 32.9 s → out of the top 12, ArchiveGit removingSavesUncommitted… 32.7 → 18.3 s, OriginWorld everyRecordedCall… 31.5 → 18.1 s, ArchiveGit pushedWork… 31.5 → 17.2 s, pruningDrops… 31.5 → 17.6 s, removingSavesUnpushed… 31.1 → 17.0 s, gitDiffScopes 28.7 → 15.5 s, everyLineReachesTheAgent… 28.1 s → out of the top 12, LedgerGit readsAWorktree… 28.0 → 15.1 s.
Tests of the tests
Each mutation was built and run against the changed tests:
ended()returns at once:outputAfterTheExitIsKeptfails, and so do the FakeCLI process-path tests.aChildHoldingThePipesIsNotWaitedForfails at its time limit.releaseignores priority:interactiveCallsGoFirstfails for both arguments.noMoreThanTheConcurrencyRunAtOncefails (mostAtOnce == 2), and so doesinteractiveCallsGoFirst. Both fail fast: the first version of these tests hung the run under this mutation, so the waits now count calls answering plus calls queued, and each held fake is released on the way out.Not done / untested
LLMRunnerTests(Scratch.folderfor FakeCLI).waitUntilExithelpers (TempRepo, RunIsolation, Telemetry, HookCommand) are unchanged. They run in sync tests with no thread hop, and took about 1% of pool samples.theSameCallAskedTwiceAtOnceRunsOncestill cannot tell joining a running call from a cache hit, as before this PR. Its mutation was not run.ProcessRunnerhas no test. Telling it apart from the 2 s give-up would mean asserting a duration.outputAfterTheExitIsKeptrelies on a 0.1 s background write landing inside the 2 s window. That is the same window production uses.🤖 Generated with Claude Code