Repository navigation
PTECH-114539: Keep the log view from stalling VM recycling - #93
Merged
Merged
Conversation
Every logged line rebuilt the whole 500-line log string several hundred times on the main actor: `onReceive(log.publisher)` replayed every buffered line, and each replay rebuilt the combined log (one DateFormatter call per line) to scroll to it. SwiftUI then laid out all 500 lines again. VMManager shares the main actor, so once the buffer filled, VM stop, clone and start and each SSH command waited behind the log. On CI hosts this turned a ~40 s recycle between jobs into 60-80 s. Each line is now formatted and ANSI-parsed once when it is logged. `log` is no longer `@Published`: `attributedLog` joins the lines and is published at most once every 250 ms, about 250 ms after the first line since the last publish, so a burst of provisioner output costs one layout instead of one per line. The view scrolls to a fixed bottom anchor when it appears and when `lastPublishedLineID` changes, which happens only with that publish. `flush()` publishes immediately; only tests call it. Colors no longer carry over from one line to the next. The parser also keeps text before the first escape code, which it used to drop, and strips the ESC character. It no longer reads past the end of a truncated 38/48 color code or overflows on a huge one, either of which crashed the app on guest output. Bump the patch version to 2.4.3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The liveness probe's SSH command doesn't observe cancellation. When a
job ended, the runner exited while a probe was in flight, the probe
reported a failure and stopped the VM alongside the normal shutdown.
When both stops succeeded, both paths started a next run; when one
failed ("Invalid virtual machine state transition ... stopping to
stopping"), it skipped starting a run, and if that was the only path
left, the host stopped taking jobs.
A cancelled probe now ignores its result, and recycling is claimed per
run's VM, so the provisioning path, the probe and the VM delegate start
at most one successor per run. A failed stop no longer blocks the next
run once the VM has stopped; if it hasn't after 30 s, the host restarts
instead of starting a second VM on the same disk and MAC address.
`handleStop` can't throw and no longer claims to.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only the first run went through `setupAndRunVM`, which retries on an
error. Every later run was started by `handleStop` in a
`Task { try await ... }` that discarded its error, so a failed clone,
VM start, IP lookup, SSH timeout or preRun ended the cycle: the host
stopped taking jobs with nothing in the log, and after an SSH timeout
the VM kept running untracked. On the first run, an error thrown after
the VM had started made `setupAndRunVM` retry next to the still-running
VM.
A run that fails after its VM was created now logs the error, waits
`retryDelay` and recycles that VM, unless another path already recycled
the run. A failure while preparing the VM (clone, configuration) is
logged and retried after `retryDelay`, for every run.
A run that another path recycled while it waited for the IP or SSH now
stops there. The next run's VM gets the same MAC address and IP, so the
stale run could connect to it, run preRun, replace its liveness probe
and register the runner a second time.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
prgorasiya
approved these changes
Dec 2, 2026
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.
What / Why
On CI hosts, the gap between two jobs on one runner alternates between ~40 s and 60–80 s. The slow mode comes from the log view: every logged line rebuilt and laid out the whole 500-line log on the main actor, which
VMManagershares, so VM stop, clone and start waited behind it once the buffer filled. While measuring this, two lifecycle bugs showed up that can make a host stop taking jobs with nothing in the log.How
The log is formatted once per line and published to the view at most every 250 ms, so main-actor work per line no longer grows with the buffer. Recycling is claimed once per VM run, and every run, not only the first, retries after a failure. Bumps the version to 2.4.3.
Details
onReceive(log.publisher)replayed every buffered line on each update, and each replay rebuilt the combined log to scroll to it. Each line is now formatted and ANSI-parsed once when it's logged.logis no longer@Published;attributedLogis, at most once per 250 ms, and the view scrolls onlastPublishedLineID. The parser keeps text before the first escape code, strips ESC, and no longer crashes on a truncated or huge 38/48 color code.retryDelayand recycles. A run that was recycled while it waited for the IP or SSH stops there instead of connecting to its successor's VM.Canary results
Measured from the Cilicon log on two of our CI hosts once the 500-line buffer was full. Gap = job end → next job start, for jobs that were already queued:
A build of this branch (run 46733726452) has run on one host since 2026-12-01.
🤖 Generated with Claude Code