Repository navigation
feat(workflows): update a saved workflow from a finished run - #27663
Closed
weijian722 wants to merge 1 commit into
Closed
weijian722 wants to merge 1 commit into
weijian722 wants to merge 1 commit into
Conversation
weijian722
marked this pull request as ready for review
November 2, 2026 04:02
A finished ad-hoc run could only be promoted into a new definition, so
saving an edited script under an existing slug produced `<slug>-2`
instead of a new revision. The only way to append one was pasting the
script into Customize -> Workflows.
Add an owner-only `POST /api/workflows/runs/{run_id}/update-definition`
that appends the run's exact source as a chosen definition's next
revision, pinned by `expected_revision`. The run passes promotion's
checks (now shared as `_reusable_run`), must match the definition's
format, and an unchanged source is refused. Its `GET` preview suggests
the target from the run's lineage or the script's META name and returns
an uncapped diff, `workflow_source_diff`, split out of the change
card's capped `_workflow_diff`.
An edited rerun of a saved Python workflow now keeps that workflow as
`derived_from` ancestry, as an adapted TaskRunner plan already does, so
the preview suggests the workflow it came from.
Part of kirodotdev#27525
weijian722
force-pushed
the
feat/workflow-update-from-run
branch
from
November 2, 2026 20:11
3ce8c2a to
d8b420f
Compare
5 tasks done
Contributor
|
[operator: bolichen97] Continuing this in #32352; thanks for the start. |
bolichen97
added a commit
that referenced
this pull request
Nov 7, 2026
A finished ad-hoc run could only be promoted into a new definition, so
saving an edited script under an existing slug produced `<slug>-2`
instead of a new revision. The only way to append one was pasting the
script into Customize -> Workflows.
Add an owner-only `POST /api/workflows/runs/{run_id}/update-definition`
that appends the run's exact source as a chosen definition's next
revision, pinned by `expected_revision` and by the run source's SHA-256
its `GET` preview returned, so a paused plan replanned while the owner
reads the diff is refused rather than saved unseen. The run passes
promotion's checks (now shared as `_reusable_run`), must match the
definition's format, and an unchanged source is refused. The preview
suggests the target from the run's lineage or the script's META name
and returns an uncapped diff, `workflow_source_diff`, split out of the
change card's capped `_workflow_diff`. The logic lives in the new
`workflows/update_from_run.py`, below the service in the workflows
layering contract: it is handed the service and never imports it, so
the `META.adapted_from` parser both need moves to `library.py`.
An edited rerun of a saved Python workflow keeps that workflow as
`derived_from` ancestry, as an adapted TaskRunner plan already does, so
the preview suggests the workflow it came from.
Builds on #27663.
Part of #27525
bolichen97
added a commit
that referenced
this pull request
Nov 7, 2026
A finished ad-hoc run could only be promoted into a new definition, so
saving an edited script under an existing slug produced `<slug>-2`
instead of a new revision. The only way to append one was pasting the
script into Customize -> Workflows.
Add an owner-only `POST /api/workflows/runs/{run_id}/update-definition`
that appends the run's exact source as a chosen definition's next
revision, pinned by `expected_revision` and by the run source's SHA-256
its `GET` preview returned, so a paused plan replanned while the owner
reads the diff is refused rather than saved unseen. The run passes
promotion's checks (now shared as `_reusable_run`), must match the
definition's format, and an unchanged source is refused. The preview
suggests the target from the run's lineage or the script's META name
and returns an uncapped diff, `workflow_source_diff`, split out of the
change card's capped `_workflow_diff`. The logic lives in the new
`workflows/update_from_run.py`, below the service in the workflows
layering contract: it is handed the service and never imports it, so
the `META.adapted_from` parser both need moves to `library.py`.
An edited rerun of a saved Python workflow keeps that workflow as
`derived_from` ancestry, as an adapted TaskRunner plan already does, so
the preview suggests the workflow it came from.
Builds on #27663.
Part of #27525
1 task done
bolichen97
added a commit
that referenced
this pull request
Nov 8, 2026
A finished ad-hoc run could only be promoted into a new definition, so
saving an edited script under an existing slug produced `<slug>-2`
instead of a new revision. The only way to append one was pasting the
script into Customize -> Workflows.
Add an owner-only `POST /api/workflows/runs/{run_id}/update-definition`
that appends the run's exact source as a chosen definition's next
revision, pinned by `expected_revision` and by the run source's SHA-256
its `GET` preview returned, so a paused plan replanned while the owner
reads the diff is refused rather than saved unseen. The run passes
promotion's checks (now shared as `_reusable_run`), must match the
definition's format, and an unchanged source is refused. The preview
suggests the target from the run's lineage or the script's META name
and returns an uncapped diff, `workflow_source_diff`, split out of the
change card's capped `_workflow_diff`. The logic lives in the new
`workflows/update_from_run.py`, below the service in the workflows
layering contract: it is handed the service and never imports it, so
the `META.adapted_from` parser both need moves to `library.py`.
An edited rerun of a saved Python workflow keeps that workflow as
`derived_from` ancestry, as an adapted TaskRunner plan already does, so
the preview suggests the workflow it came from.
Builds on #27663.
Part of #27525
bolichen97
added a commit
that referenced
this pull request
Nov 8, 2026
A finished ad-hoc run could only be promoted into a new definition, so
saving an edited script under an existing slug produced `<slug>-2`
instead of a new revision. The only way to append one was pasting the
script into Customize -> Workflows.
Add an owner-only `POST /api/workflows/runs/{run_id}/update-definition`
that appends the run's exact source as a chosen definition's next
revision, pinned by `expected_revision` and by the run source's SHA-256
its `GET` preview returned, so a paused plan replanned while the owner
reads the diff is refused rather than saved unseen. The run passes
promotion's checks (now shared as `_reusable_run`), must match the
definition's format, and an unchanged source is refused. The preview
suggests the target from the run's lineage or the script's META name
and returns an uncapped diff, `workflow_source_diff`, split out of the
change card's capped `_workflow_diff`. The logic lives in the new
`workflows/update_from_run.py`, below the service in the workflows
layering contract: it is handed the service and never imports it, so
the `META.adapted_from` parser both need moves to `library.py`.
An edited rerun of a saved Python workflow keeps that workflow as
`derived_from` ancestry, as an adapted TaskRunner plan already does, so
the preview suggests the workflow it came from.
Builds on #27663.
Part of #27525
bolichen97
added a commit
that referenced
this pull request
Nov 8, 2026
A finished ad-hoc run could only be promoted into a new definition, so
saving an edited script under an existing slug produced `<slug>-2`
instead of a new revision. The only way to append one was pasting the
script into Customize -> Workflows.
Add an owner-only `POST /api/workflows/runs/{run_id}/update-definition`
that appends the run's exact source as a chosen definition's next
revision, pinned by `expected_revision` and by the run source's SHA-256
its `GET` preview returned, so a paused plan replanned while the owner
reads the diff is refused rather than saved unseen. The run passes
promotion's checks (now shared as `_reusable_run`), must match the
definition's format, and an unchanged source is refused. The preview
suggests the target from the run's lineage or the script's META name
and returns an uncapped diff, `workflow_source_diff`, split out of the
change card's capped `_workflow_diff`. The logic lives in the new
`workflows/update_from_run.py`, below the service in the workflows
layering contract: it is handed the service and never imports it, so
the `META.adapted_from` parser both need moves to `library.py`.
An edited rerun of a saved Python workflow keeps that workflow as
`derived_from` ancestry, as an adapted TaskRunner plan already does, so
the preview suggests the workflow it came from.
Builds on #27663.
Part of #27525
5 tasks done
Contributor
|
Thanks @weijian722! This change landed on main through #32352 (#32352, merge commit 38a0633, merged 2026-11-08), which builds on this PR and adds update-from-run to the workflow service and dashboard handlers. Closing this one as landed. Thank you for the groundwork. |
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.
Problem / Motivation
Goal: The dashboard owner can append a finished workflow run's script to a saved workflow as that workflow's next revision, instead of only saving it as a new copy.
A finished run's Save workflow button always creates a new library entry. When someone edits a saved workflow's script in chat, runs it, and saves it under the same slug, they get
<slug>-2instead of revision N+1. The only way to add a revision today is to paste the whole script into Customize → Workflows. Theworkflow.updatechange card from #25708 can't help with larger scripts: it caps a script at 10,000 bytes and refuses non-ASCII outside comments.This PR adds the backend half. The Update button and dialog come in a follow-up PR for the same issue.
Why it matters
Iterating on a saved workflow in chat (run it, ask for a change, run again) is the normal way people build one. Without an update path, the library either fills with
-2/-3copies whose/workflowcommands nobody remembers, or the owner hand-pastes scripts and can paste the wrong file. Both leave the saved copy out of step with the one actually tested.Not a goal
test_workflow_library_mutations_are_human_only).POST /api/workflows/runs/{run_id}/promotereturns.What changed (motivation → approach → change)
A run whose script you edited and tested can now become the next revision of the saved workflow it came from, so the library keeps one workflow with its history instead of a new
<slug>-2copy each time. This PR adds the two routes the coming Update dialog will call:GET /api/workflows/runs/{run_id}/update-definition?workflow=id,slug,name,revision,format) and returns the diff from its current source to the run's. Withoutworkflowit suggests one, or returnsnull.POST /api/workflows/runs/{run_id}/update-definition{workflow, expected_revision}The update reuses what promotion already trusts. The run must pass promote's checks: an ad-hoc run (not a saved invocation), finished or a paused TaskRunner plan, still holding its original source. Those checks are now one helper,
_reusable_run, which both paths call. The library's ownexpected_revisionlock still catches a stale writer. Two refusals are new: a run whose format differs from the workflow's, and a source identical to the pinned revision, which would otherwise append an empty revision. Every refusal has its own code (404, 409 or 400). The service half is insrc/kiro_crew/workflows/service.py. The routes are insrc/kiro_crew/dashboard/handlers/workflows.py, registered insrc/kiro_crew/dashboard/server_runtime/mcp_routes.py, behind the same owner gates as promote and audited in SEL.The preview suggests a target, in order: the run's
derived_from, the script'sMETA["adapted_from"], the slug of itsMETAname, then the slug of the run's name. An edited rerun of a saved Python workflow now keeps that workflow asderived_from, as an adapted TaskRunner plan already does (passed throughsrc/kiro_crew/workflows/runner.pyandregistry.py). Without it the most common case, editing a saved workflow and rerunning it, fell through to theMETAname and could suggest a same-named copy. Its diff isworkflow_source_diffinsrc/kiro_crew/dashboard/change_cards_readers.py: the change card's diff withoutWORKFLOW_DIFF_MAX, because this diff is never stored in a card. It also spells out hidden characters on every line, since a run's script never went through the card's character checks. On a card the new script already passed those checks, so card diffs are unchanged.docs/system-specs/modules/workflows.mddocuments both routes and the update rules.Backwards compatibility
Compatible: two new routes and one new service method. Promotion keeps the same checks, refusals and responses, and a card diff renders exactly as before. An edited Python rerun's snapshot now carries a
derived_fromit used to leavenull; Python promotion still takes lineage only fromMETA["adapted_from"].Removes nothing: no route, field, key or behaviour is removed or narrowed.
Tests
test/test_workflows_service_update_from_run.py(new;test_workflows_service.pyis at its line cap):METAname,adapted_fromand a TaskRunner run'sderived_from, and an explicitworkflowwins;derived_fromhand-off removed, this test fails.test/test_workflow_definition_handlers.py: the preview returns only the target summary plus the diff; each refusal maps to its status and code;workflowand an integerexpected_revisionare required; app-token and anonymous callers get 403, with their SEL rows.test/test_r7_owner_gate_positive_controls.py/test_r7_owner_gate_refusals.py: the owner reaches both routes; a non-owner getsowner_onlyon both, and nothing runs.test_update_run_definition_refuses_without_writingred.-n0and 10× at-n 4 --dist loadgroup --max-worker-restart=2besidetest_workflows_service.pyandtest_change_card_workflow_save.py, then in a shuffled order (seed 25822). All green.Manual verification
N/A for this PR: unit tests cover both routes end to end through aiohttp. The click-through path (run, edit, Update, revision N → N+1) is verified in the follow-up PR that adds the dialog.
Related Issues
Part of #27525
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
I contribute this under the project's Apache-2.0 license.