Skip to content

feat: surface gate detail in the workflow run/resume --json payload#2965

Open
doquanghuy wants to merge 1 commit into
github:mainfrom
doquanghuy:feat/2964-gate-outcome-json
Open

feat: surface gate detail in the workflow run/resume --json payload#2965
doquanghuy wants to merge 1 commit into
github:mainfrom
doquanghuy:feat/2964-gate-outcome-json

Conversation

@doquanghuy

@doquanghuy doquanghuy commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Description

Reference implementation for #2964 — for discussion, direction welcome.

When a run pauses at a gate, the --json outcome now carries a gate block (step_id / message / options / choice) so orchestrators can detect "human review needed" and present the options without parsing the human-facing stream. Two small pieces:

  1. The engine records each step's type in the run state's step results (one added line in step_data — previously the type was not recoverable from state).
  2. _workflow_run_payload adds the gate block via a _gate_outcome helper when the run's current step is a gate. choice populates when the outcome ends at the gate with a decision recorded (e.g. an interactive rejection with on_reject: abort → a failed payload carrying "choice": "reject"; an on_reject: retry pause likewise). A mid-flow approval proceeds past the gate, so the block clears — by design. Non-gate runs and runs that end elsewhere are unchanged — no gate key, payload byte-identical to today.

The issue lists alternatives (a generic paused_step block; a dedicated status value) — happy to rework toward either.

Testing

  • Ran existing tests with uv sync && uv run pytest — full suite 3727 passed
  • Two new CLI-level tests (TestWorkflowRunGateOutcomeJson): a gate pause carries the exact block (CliRunner stdin is non-TTY, so the gate pauses); a completed run has no gate key — the gate-pause test is red against current main, green with the change (verified both directions)
  • uvx ruff check src/ — clean
  • Tested locally with uv run specify --help
  • Tested with a sample project (covered by the CLI-level tests, which drive a real gate workflow through workflow run --json)

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (describe below)

Code, tests, and this description were authored with AI assistance (Claude); verified by running the repo's test suite and ruff locally in both red and green directions.

A paused run was indistinguishable from any other pause in the
machine-readable outcome, and the gate's prompt/options/choice never
left the human-facing stream. Record each step's type in the run
state's step results (one engine line) and, when the run sits at a
gate, add a gate block (step_id/message/options/choice) to the payload
so orchestrators can drive review gates without parsing stdout.

Reference implementation for the proposal in github#2964.

Addresses github#2964
@doquanghuy doquanghuy requested a review from mnriem as a code owner June 12, 2026 17:37
@doquanghuy

Copy link
Copy Markdown
Contributor Author

@mnriem when you have a moment, would appreciate your thoughts on the direction here — the issue lists the alternatives considered, and I'm happy to rework toward whichever shape fits Spec Kit best.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the workflow CLI’s --json run/resume outcome payload to include structured details when the run is paused at a gate step, enabling external orchestrators to detect “human review needed” without parsing stdout.

Changes:

  • Record each executed step’s type into persisted step_results so step types are recoverable from run state.
  • Add an optional gate block to the workflow run --json / workflow resume --json payload when the current step is a gate.
  • Add CLI-level tests covering a non-interactive gate pause (includes gate block) and a non-gate completed run (no gate key).
Show a summary per file
File Description
tests/test_workflows.py Adds CLI-level tests asserting --json includes a structured gate block on gate pauses and omits it for a normal completed run.
src/specify_cli/workflows/engine.py Persists type in each step’s recorded step_results entry so step-type introspection is possible from run state.
src/specify_cli/__init__.py Builds the --json outcome payload and conditionally injects gate details via a helper when the current step is a gate.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 2

Comment on lines +2771 to +2773
step = (getattr(state, "step_results", None) or {}).get(state.current_step_id)
if not isinstance(step, dict) or step.get("type") != "gate":
return None
Comment thread tests/test_workflows.py
Comment on lines +3985 to +3987
runner = CliRunner()
result = runner.invoke(app, ["workflow", "run", str(path), "--json"])
return _json.loads(result.stdout)
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.

3 participants