Skip to content

fix(run): report an engine the run stopped as finished - #277

Merged
T-Crypt merged 2 commits into
nextfrom
T-Crypt/latch-clears-on-berth-stop
Oct 31, 2026
Merged

T-Crypt merged 2 commits into
nextfrom
T-Crypt/latch-clears-on-berth-stop

Conversation

@T-Crypt

@T-Crypt T-Crypt commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Refs #275 (point 3).

What changes for users

When Berth stops an engine itself, berth status and the harbor showed that engine as LATCHED (unresponsive), as if it had crashed. It now shows as offline. An engine that exits non-zero on its own still shows as LATCHED.

Cause

The engine watcher clears a latch when berth run sends finished, and the run sent it only on exit 0 (#266). A stop that Berth carries out ends the engine with a signal, so the exit code is non-zero: 143 or 137 on Linux, and 1 after a kill on Windows. A berth stop, a drain for a higher priority, a park that failed, and llama-swap unloading a model all left the engine latched.

Fix

The run's lease line records when the run sets out to end the engine. finished is sent on exit 0 or when that flag is set. The flag is set in four places:

  • drain, after the park step, where every remaining step ends the engine. A drain that parks the engine does not set it.
  • drain, before it kills a checkpointed engine.
  • stopNow, which a failed or silent wake calls. It is now a method on the lease line.
  • forwardSignals, when a stop signal arrives from llama-swap, systemd or Ctrl-C.

Proof

  • TestACleanExitDoesNotLatchTheEngine gains two cases, berth stop and a SIGTERM to the run. The test-only commit fails both, and the fix commit passes them, 3 runs out of 3. The exit 0 and exit 1 cases keep their results.
  • Mutations: removing the askStop call in drain fails the berth stop case. Removing the asked() call in forwardSignals fails the supervisor case.
  • The stopNow and checkpoint paths have no test of their own. They use the same flag.
  • Build, gofmt, vet, go test ./..., the Windows build and vet, and golangci-lint (0 issues) all pass.

berth stop and a stop signal from a supervisor end the engine on purpose,
but the engine dies from the signal with a non-zero code. berth run reports
only exit 0 as finished, so status keeps the engine LATCHED. The two new
cases fail until the run reports the stops it carries out.

Refs #275
berth run now sends finished when it ended the engine itself, whatever the
exit code: a drain past the park step (berth stop, a higher priority, a
park that failed), a wake that never answered, or a stop signal it
forwarded from llama-swap or systemd. berthd clears the latch, and the
engine shows as offline instead of unresponsive. An engine that exits
non-zero on its own still latches.

Refs #275
@T-Crypt
T-Crypt merged commit ed35aaf into next Oct 31, 2026
4 checks passed
@T-Crypt
T-Crypt deleted the T-Crypt/latch-clears-on-berth-stop branch November 2, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant