Skip to content

PTECH-114539: Keep the log view from stalling VM recycling - #93

Merged
HeEAaD merged 3 commits into
mainfrom
feature/PTECH-114539-log-view-main-actor
Dec 2, 2026
Merged

HeEAaD merged 3 commits into
mainfrom
feature/PTECH-114539-log-view-main-actor

Conversation

@HeEAaD

@HeEAaD HeEAaD commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

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 VMManager shares, 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

  • Render the log without stalling the VM lifecycle (1da4d46): 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. log is no longer @Published; attributedLog is, at most once per 250 ms, and the view scrolls on lastPublishedLineID. The parser keeps text before the first escape code, strips ESC, and no longer crashes on a truncated or huge 38/48 color code.
  • Recycle each VM run only once (27da54f): the liveness probe's SSH command ignored cancellation, so a probe in flight when a job ended stopped the VM alongside the normal shutdown ("stopping to stopping"), and either two runs started or none did. A cancelled probe now ignores its result, and the provisioning path, the probe and the VM delegate start at most one successor per run.
  • Recover from failed runs after the first (a811f14): only the first run retried on an error; later runs discarded it, so a failed clone, boot, SSH or preRun ended the cycle silently. A failed run now logs the error, waits retryDelay and 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:

2.4.2 This PR
Log lag behind the runner 40–52 s 0–1 s
Job end → "Starting Up" 36 s 1–2 s
Gap between jobs 60–80 s 34–40 s (median 38 s)

A build of this branch (run 46733726452) has run on one host since 2026-12-01.

🤖 Generated with Claude Code

HeEAaD and others added 3 commits December 2, 2026 12:25
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>
@HeEAaD
HeEAaD marked this pull request as ready for review December 2, 2026 11:30
@HeEAaD
HeEAaD requested a review from a team as a code owner December 2, 2026 11:30
@HeEAaD HeEAaD closed this Dec 2, 2026
@HeEAaD HeEAaD reopened this Dec 2, 2026
@HeEAaD HeEAaD closed this Dec 2, 2026
@HeEAaD HeEAaD reopened this Dec 2, 2026
@HeEAaD
HeEAaD merged commit 5d69469 into main Dec 2, 2026
10 checks passed
@HeEAaD
HeEAaD deleted the feature/PTECH-114539-log-view-main-actor branch December 2, 2026 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants