feat(runner): settled terminal event + idempotent finalizer (§0.1)#5
Merged
Conversation
Introduce a `settled` event on the Runner port that fires exactly once per run, on EVERY terminal path — including cancellation, which today emits neither `done` nor `error` (ProcessRunner.cancel() emitted nothing, so a done/error-only finalizer would leak on cancel). `done`/`error` still fire before `settled` when they occur; `settled` carries a TerminalReason (succeeded | failed | cancelled | timed-out). - ProcessRunner: guarded _settle() wired into spawn-failure, no-stdout, child error, close (reason from cancelled/exit code), timeout, idle, and cancel-before-start. Emits at most once. - AgentTaskExecutor: subscribes `settled` as the idempotent finalizer (evicts the active runner) — the seam where worktree.dispose()/slot-release attach later. Publishes no A2A event on settled (preserves the event stream). Contract-additive to the Runner port; no existing event changed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.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.
Third §0.1 increment — the one Runner-port change from the design (§3.2).
Why
ProcessRunner.cancel()emits neitherdonenorerror, and theclosehandler early-returns when cancelled — so a finalizer subscribed todone/errorwould leak on the cancel path (worktree/slot/span cleanup skipped). Adding a single terminal signal fixes this and gives every terminal path one guaranteed cleanup hook.What
settledevent carrying aTerminalReason(succeeded | failed | cancelled | timed-out). No existing event changed;done/errorstill fire beforesettledwhen they occur._settle()wired into every terminal path: spawn-failure, no-stdout, child error,close(reason from cancelled/exit code), timeout, idle, and cancel-before-start. Emits at most once.settledas the idempotent finalizer (evicts the active runner). The seam whereworktree.dispose()/slot-release attach later. Publishes no A2A event on settled (event stream unchanged).Gates
typecheck✅ ·lint✅ ·test:coverage✅ (372 tests, 100%) ·build✅. New: settled contract tests (succeeded/failed/cancelled/once) + executor finalizer cleanup.🤖 Generated with Claude Code