feat(vessel): add Handle.OnTerminate lifecycle hook#63
Merged
Conversation
Introduce a synchronous completion-hook API on vessel.Handle so
multiple consumers can observe run termination with consistent
ordering, without each spawning its own <-h.Done() watcher
goroutine (the racy pattern that motivated this).
Contract:
- Hooks fire synchronously, in registration order, BEFORE Wait
returns and BEFORE Done is closed. Any consumer of Wait/Done
is guaranteed to see a state where every hook has executed.
- Hooks must be fast and non-blocking (they delay every Wait
caller by their wall-clock cost).
- Hooks may panic; the panic is recovered per-hook so one buggy
hook cannot block siblings or leave the run hanging.
- Late registration is safe: registering after termination
invokes fn synchronously with the cached terminal state.
This is purely additive — Handle stays backwards compatible. The
intended initial consumer is cmd/vesseld's runRegistry, which
will migrate off its own background goroutine in a follow-up PR
and gain a deterministic "/call returns => registry recorded"
contract for /metrics and /v1/runs scrapes.
Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
Adds a synchronous completion-hook API on `vessel.Handle` so multiple consumers can observe run termination with deterministic ordering — no more racy `<-h.Done()` watcher goroutines per consumer.
Why
PR #62 surfaced a real ordering gap on `/v1/vessels/{id}/call`: `/call` returned when `h.Wait` resolved, but `runRegistry`'s background goroutine watching `h.Done()` had no ordering guarantee against `Wait`. Result: `/metrics` and `/v1/runs` could miss a just-completed run, breaking the scrape contract.
The architectural fix is to give `Handle` a proper lifecycle-event hook API instead of patching one consumer at a time.
Contract
Scope
Backwards compatible — pure addition.
Follow-up
PR #62 will pick up `vessel v0.1.0-rc.2` (this PR + tag) and migrate `runRegistry` off its own goroutine, then revert the test-side polling hack added as a stopgap.
Test plan
Made with Cursor