feat: run_completed/run_failed terminal events in progress.ndjson (#7)#87
Merged
mattleaverton merged 1 commit intoApr 27, 2026
Conversation
danshapiro#7) - Add FinalCanceled FinalStatus = "canceled" to runtime/final.go - Add emitTerminalProgressEvent() method emitted as the final line of progress.ndjson, after final.json is fully written and git push completes - Add isCanceledError() helper to distinguish externally-canceled runs (context.Canceled/DeadlineExceeded) from hard failures - Modify persistFatalOutcome() to set FinalCanceled status on context cancel - Add docs/runs-layout.md documenting run directory layout, progress.ndjson lifecycle events (including terminal events), and final.json contract - Add TestProgressNDJSON_TerminalEvent_RunCompleted (success path) - Add TestProgressNDJSON_TerminalEvent_RunFailed (fan-in all-fail path) Ordering guarantee: terminal event is emitted AFTER final.json is written and AFTER gitPushIfConfigured(), so it is always the last line in the stream.
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
From
docs/plans/2026-04-24-kilroy-fixes-from-feedback.mditem #7.Bug:
progress.ndjsonemitsstage_attempt_*,edge_selected,input_materialization_*,tmux_session_*— but nothing for run completion. The canonical terminal signal today is the appearance offinal.json, and that invariant was undocumented. Skills end up pollingfinal.jsonby hand instead of tailing the stream.Fix:
emitTerminalProgressEvent()ininternal/attractor/engine/engine.go, called as the very last action ofpersistTerminalOutcome()— afterfinal.Save(),run.tgz, andgitPushIfConfigured(). Ordering guarantee: any reader observing the event can immediately openfinal.json.isCanceledError()helper distinguishescontext.Canceled/DeadlineExceededfrom hard failures.persistFatalOutcome()now setsFinalCanceledstatus on context cancel (new status added toruntime/final.go).docs/runs-layout.md(new) documents the run directory layout, progress.ndjson lifecycle events including the terminal event, andfinal.jsonas the public completion contract.Event schema
{"event":"run_completed","status":"success","run_id":"01ABC...","id":"a1b2c3d4","ts":"2026-..."} {"event":"run_failed","status":"fail","run_id":"...","reason":"...","ts":"..."} {"event":"run_failed","status":"canceled","run_id":"...","reason":"context canceled","ts":"..."}Test plan
TestProgressNDJSON_TerminalEvent_RunCompleted— minimalstart → exitgraph, asserts last line ofprogress.ndjsonisrun_completedandfinal.jsonexists on disk.TestProgressNDJSON_TerminalEvent_RunFailed— fan-in with both branches exit-1, assertsrun_failedemitted andfinal.jsonexists.go test ./internal/attractor/engine/...passes (2 pre-existing unrelated failures confirmed on base commit too).Risks / follow-ups
persistTerminalOutcome, so no event emitted — but also nofinal.jsonwritten, so consistent.final.jsondirectly; these are startup errors not lifecycle events.status=fail(notcanceled) because the watchdog usesfmt.Errorfrather thancontext.Canceled. Could be changed if stall timeouts should report ascanceled.FinalCanceledis now a validFinalStatus— consumers offinal.jsonthat branch on status should handle it.Context
Produced by a dogfood quick-launch run against this repo.
🤖 Generated with Claude Code