Repository navigation
feat(#504): typed workflow event system for decoupled progress + MCP streaming - #643
Merged
admarble merged 2 commits intoMay 14, 2026
Conversation
…streaming
Add `WorkflowEventEmitter` (`src/lib/workflow/event-emitter.ts`): a Node
`EventEmitter` wrapper with a compile-time-typed event map covering 8
lifecycle events — `run_started`, `run_completed`, `phase_started`,
`phase_completed`, `phase_failed`, `issue_status_changed`, `qa_verdict`,
`progress`. Payloads are JSON-serializable (`{ issueNumber, phase?,
timestamp, duration?, verdict?, error?, ... }`) so MCP / webhook
consumers can serialize them directly. `emit()` is wrapped in
`Promise.allSettled` so a slow or throwing listener cannot crash the run.
Wire into `RunOrchestrator`: instantiate per run, expose via
`getEmitter()`, emit at the lifecycle points already plumbed through
`applyProgressEvent` (phase start/complete/failed/progress, issue status
transitions) plus a run/qa-verdict bracket in `executeOneIssue`.
`markDone()` drains all subscribers so repeated `run()` invocations in
the same process (MCP server) don't leak listeners.
Per the 2026-04-09 descope, existing consumers (LogWriter, MetricsWriter,
CLI spinners) remain as direct calls; the emitter is opt-in for new
subscribers (TUI, MCP server, future webhooks).
Tests: 10 unit cases in `event-emitter.test.ts` covering all 8 events,
JSON roundtrip, and listener isolation; 9 integration cases in
`__tests__/run-orchestrator-events.test.ts` covering run/qa-verdict
bracket, phase-event propagation, status transitions, and slow / throwing
listener safety. All 907 existing workflow tests continue to pass.
9 tasks
… fields Closes three non-blocking gaps surfaced by /qa on PR #643: 1. run_completed asymmetry — executeOneIssue emitted run_started before awaiting runIssueWithLogging but emitted run_completed only on the success path. If a future code path causes the awaited call to throw, subscribers would see an unbalanced start without a matching completion. The body is now wrapped in try { ... } finally { emit } so the bracket events stay symmetric; success is reported from the captured result, defaulting to false when the await rejects. 2. Dead emitter fields on BatchExecutionContext / IssueExecutionContext — threaded through but never read by batch-executor or phase-executor. Removed the optional fields (and the matching assignments inside the orchestrator). The orchestrator continues to emit lifecycle events from its own this.emitter; the WorkflowEventEmitter type-barrel re-exports stay so external getEmitter() consumers can still import from the workflow types module. When a real consumer needs to emit from inside phase-executor (e.g., MCP wiring picks up qa_verdict at the source), the field can return with a real motivating use case. 3. snake_case event-name nit — added a one-line note to the WorkflowEvents doc block clarifying that snake_case is the public MCP / webhook contract and should not be "normalized" to camelCase. Added one integration test: when runIssueWithLogging rejects, the orchestrator still emits run_completed with success:false, and the synthetic failure IssueResult surfaces in the parallel-execute path. Verified: build + lint clean, 20/20 targeted event tests, full suite 3357/3357 pass.
admarble
added a commit
that referenced
this pull request
Sep 9, 2026
… fields Closes three non-blocking gaps surfaced by /qa on PR #643: 1. run_completed asymmetry — executeOneIssue emitted run_started before awaiting runIssueWithLogging but emitted run_completed only on the success path. If a future code path causes the awaited call to throw, subscribers would see an unbalanced start without a matching completion. The body is now wrapped in try { ... } finally { emit } so the bracket events stay symmetric; success is reported from the captured result, defaulting to false when the await rejects. 2. Dead emitter fields on BatchExecutionContext / IssueExecutionContext — threaded through but never read by batch-executor or phase-executor. Removed the optional fields (and the matching assignments inside the orchestrator). The orchestrator continues to emit lifecycle events from its own this.emitter; the WorkflowEventEmitter type-barrel re-exports stay so external getEmitter() consumers can still import from the workflow types module. When a real consumer needs to emit from inside phase-executor (e.g., MCP wiring picks up qa_verdict at the source), the field can return with a real motivating use case. 3. snake_case event-name nit — added a one-line note to the WorkflowEvents doc block clarifying that snake_case is the public MCP / webhook contract and should not be "normalized" to camelCase. Added one integration test: when runIssueWithLogging rejects, the orchestrator still emits run_completed with success:false, and the synthetic failure IssueResult surfaces in the parallel-execute path. Verified: build + lint clean, 20/20 targeted event tests, full suite 3357/3357 pass.
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
WorkflowEventEmitter(src/lib/workflow/event-emitter.ts) — a NodeEventEmitterwrapper with a compile-time-typed event map covering 8 lifecycle events (run_started,run_completed,phase_started,phase_completed,phase_failed,issue_status_changed,qa_verdict,progress).emit()is wrapped inPromise.allSettledso a slow or throwing listener cannot crash the run.RunOrchestrator: instantiate per run, expose viagetEmitter(), emit at lifecycle points already plumbed throughapplyProgressEventplus a run/qa-verdict bracket inexecuteOneIssue.markDone()drains subscribers to prevent leaks across repeatedrun()invocations (MCP server use case).Pre-PR AC Verification
Operating on the post-descope AC list (renumbered AC-1 through AC-5 per the 2026-05-14 spec comment).
WorkflowEventEmitterclass with 8 typed eventsevent-emitter.tsWorkflowEventsinterface; 10 unit testsnode:events(no deps); compile-time safety enforced viakeyof WorkflowEventsoverloads onon/off/emitrun-orchestrator.ts:applyProgressEvent(phase start/complete/failed/progress, status transitions) +executeOneIssue(run_started/run_completed/qa_verdict). All emits usevoid emitter.emit(...)— orchestrator does not awaitevent-emitter.ts; JSON-roundtrip test in both unit + integration suitesPromise.allSettledwrapperWorkflowEventEmitter.emit()wraps every listener inPromise.resolve().then(listener)and resolves throughPromise.allSettled; rejections routed toonListenerErrorand never propagatedTest plan
npm run buildpassesnpm run lintpasses (no warnings)npx vitest run src/lib/workflow/event-emitter.test.ts— 10/10 passnpx vitest run __tests__/run-orchestrator-events.test.ts— 9/9 passnpx vitest run src/lib/workflow/ __tests__/run-orchestrator.test.ts __tests__/run-orchestrator-resolve.test.ts __tests__/integration/run-orchestrator.integration.test.ts— 907/907 pass (no regressions)npx vitest run __tests__/mcp-progress-notifications.test.ts __tests__/mcp— 47/47 passQuality Plan Alignment
Promise.allSettled+onListenerError(which itself swallows throws)onProgresslogNonFatalWarningfor listener errors, mirroring orchestrator conventionNotes
onProgress: per the spec's open-question 1, the existingonProgresscallback (synchronous TUI render hook) remains in place. The emitter is the async multi-subscriber surface. Consolidating them is an intentional non-goal per the descope.executeBatchnot wired:batch-executor.ts:executeBatchis unused in src/ (the orchestrator callsrunIssueWithLoggingdirectly). The emitter is threaded throughBatchExecutionContextregardless so existing call shape is preserved.orchestrator.getEmitter().on(...)works today.Closes #504