feat: surface gate detail in the workflow run/resume --json payload
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:
- The engine records each step's
typein the run state's step results (one added line instep_data— previously the type was not recoverable from state). _workflow_run_payloadadds thegateblock via a_gate_outcomehelper when the run's current step is a gate.choicepopulates when the outcome ends at the gate with a decision recorded (e.g. an interactive rejection withon_reject: abort→ afailedpayload carrying"choice": "reject"; anon_reject: retrypause 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 — nogatekey, payload byte-identical to today.
The issue lists alternatives (a generic paused_step block; a dedicated status value) — happy to rework toward either.
Testing
- [x] Ran existing tests with
uv sync && uv run pytest— full suite 3727 passed - [x] 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 nogatekey — the gate-pause test is red against currentmain, green with the change (verified both directions) - [x]
uvx ruff check src/— clean - [x] 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
- [x] 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.
@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.
Please address Copilot feedback
@mnriem Thanks for the review — addressed the Copilot feedback:
_gate_outcome()now only surfaces thegateblock while the run is actually paused (guards onstatus == paused). SinceRunState.current_step_idisn't cleared on completion, a completed/failed run whose last step was a gate no longer leaks stale gate detail in run/resume/status--json.- Hardened the
_run_jsontest helper to assert CLI success before JSON-parsing, and added direct coverage for the suppression guard.
Full suite green; ruff check src/ clean. Ready for another look.
@mnriem Pushed 5fd0f85 addressing the latest Copilot round:
- Abort path now surfaces the gate block.
_gate_outcome()emits the gate detail forabortedruns too, not onlypaused. Abort is the only path that setsABORTED(gate rejection withon_reject: abort) and it leavescurrent_step_idon that gate, so an orchestrator can read the recordedchoicefor the stop.completed/failedstay suppressed. - Stable JSON schema.
messageis coerced to a string —GateSteponly coerces it for expression interpolation, so a non-string YAML literal could otherwise leak into the payload. - Tests: added a CLI-level aborted-path test (
test_gate_abort_carries_gate_block, assertsstatus == abortedandchoice == reject), a message-coercion test, and extended the suppression test to allowaborted. Shared the run helper via_invoke_jsonto avoid duplicating invoke boilerplate.
Please address Copilot feedback and rebase on upstream/main
@mnriem Pushed 5f60408 for the latest Copilot round:
- The gate-abort test parsed stdout without first asserting the CLI exited cleanly, so an invoke failure would have surfaced as an opaque JSON decode error. It now routes through
_run_json(which assertsexit_code == 0before parsing), and I dropped the now-redundant_invoke_jsonhelper — a gate abort emits the payload and returns, so the run exits cleanly.
Full tests/test_workflows.py green (212 passed).
@mnriem Pushed 3e303fb addressing the latest Copilot round:
- Run-helper assertion message now uses
result.outputinstead ofresult.stdout. Under--json, step output is redirected off stdout, so a failing run's useful diagnostics live onresult.output; the JSON parse still reads stdout. This also brings_run_jsonin line with the other CLI tests in the file. StepContext.stepsdocstring updated from the old 5-key entry shape to the canonical 7-key shape the engine actually persists (type,integration,model,options,input,output,status), so step authors and debuggers see the real record.
Full tests/test_workflows.py green (212 passed); ruff clean.
Heads up: GitHub now shows this branch as conflicting with main — that's from #2959 and #2963 having merged (they touch the same run-command / engine.py / test regions). I've left the branch as-is rather than rebase a public PR unprompted; happy to rebase onto current main and resolve if you'd like, just say the word.
@mnriem Rebased onto current main and resolved the conflict (force-pushed 24d6e85). The branch is now MERGEABLE.
What the rebase touched:
- Conflict was a clean "keep both": #2959 added
TestWorkflowRunExitCodesexactly where this PR addsTestWorkflowRunGateOutcomeJson— both classes are preserved in full._workflow_run_payloadnow (correctly) calls_gate_outcomeand keeps_run_outcome_exit_code; thestep_data["type"]field this PR relies on sits cleanly alongside the rest. - One real semantic interaction with #2959: a gate abort now emits the
--jsonpayload and then exits non-zero (aborted → 1). I gave the test helper anexpected_exitparam (default 0) so the abort test asserts exit 1 while paused/completed stay at 0 — single shared helper, no duplicated invoke boilerplate.
All prior Copilot fixes are intact (paused/aborted guard, message coercion, result.output assert message, 7-key StepContext.steps docstring). Full specify_cli test suite green locally (3879 passed); ruff clean.
@mnriem Pushed d322cf5 for the latest Copilot comment:
- Backward-compatible gate detection. A run paused by an older version has no persisted step
type, so_gate_outcomewould have dropped its gate block on resume. Added_is_gate_step: it prefers thetypefield, and whentypeis absent falls back to the gate's unique output signature (on_reject, which onlyGateStepwrites). A record carrying a different knowntypeis still not treated as a gate. - Options normalized to strings. Mirroring the existing
messagecoercion,optionsis now normalized to a list of strings so an unvalidated workflow with non-string options can't destabilize the JSON schema. - Tests: options coercion, type-less gate detection (resume path), and a type-less non-gate negative case.
Full tests/test_workflows.py green (291 passed); ruff clean.
@mnriem Pushed a97cd18 for the latest Copilot comment:
- Non-list
optionsnow normalized too. The previous pass only mapped alist, returning the raw value for any other shape — so a scalar or tuple leaked through unnormalized, contradicting thelist[str]intent. Extracted_normalize_gate_options:NonestaysNone; a list/tuple maps each element throughstr; any other scalar becomes a single-element list (a bare string is treated as one option, never iterated character-by-character). The emitted schema is now alwayslist[str] | None. - Tests extended to cover list, tuple, bare string, numeric scalar, and
None.
Full tests/test_workflows.py green (291 passed); ruff clean.
@mnriem Pushed c4297a0 for the latest Copilot round:
choicenow normalized too._gate_outcomenormalizedmessageandoptionsbut passedchoicethrough as-is — an unvalidated gate can record a non-stringchoice, contradicting the stable-schema rationale. It is now coerced tostr | None(None still means "no decision yet"), consistent with the other two fields. Added a focused choice-coercion test (None / string / non-string).- Portable plain-gate test. The no-gate test workflow used
run: "true", which fails undercmd.exeon Windows (ShellStep usesshell=True). Switched to the cross-platformrun: "exit 0", matching the exit-code suite's workflows. (Scoped to the one occurrence this PR introduced; two pre-existingrun: "true"lines elsewhere are upstream and left untouched to keep the diff tight.)
Full tests/test_workflows.py green (292 passed); ruff clean.
@mnriem Pushed be970e7 addressing the latest Copilot round (pyproject.toml / CHANGELOG.md).
Both findings traced to a single stray commit on the branch: chore: bump version to 0.11.2 (authored by github-actions[bot]), which had leaked in and bumped pyproject.toml 0.11.2.dev0 → 0.11.2 plus added a full 0.11.2 release-note block to CHANGELOG.md. That's release automation, not part of this feature.
- Rebased onto current
upstream/mainand dropped the bot bump commit. Upstream has since cut 0.11.2 and moved to0.11.3.dev0; the branch now inherits that verbatim. The PR diff no longer touchespyproject.tomlorCHANGELOG.mdat all — it's back to just the gate-JSON feature (4 files:__init__.py,workflows/base.py,workflows/engine.py,tests/test_workflows.py). - All prior Copilot fixes are intact (paused/aborted guard, message/options/choice coercion, backward-compat gate detection,
result.outputassert message, 7-keyStepContext.stepsdocstring, portableexit 0plain-gate test).
Full tests/test_workflows.py green (296 passed).
Thank you!