Repository navigation
feat: update a saved workflow from a finished run - #32352
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the run's source is read once and pinned by its digest and by Notes
[DESIGN-REVIEWED] b41b15c Description read[DESCRIPTION-READ] 794b4659a8ab807a50e1efc5bf3ad549d790156895b8186bca2997706080e13c That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. Both routes take the source from the run on the server, which a client cannot do safely by sending it back through the existing Notes
What this change shipsInventory (7 items) — 6 justifiedIntent: let the owner save a tested chat run as the next revision of the saved workflow it came from, instead of a
[FIRST-PRINCIPLES-REVIEWED] b41b15c Description read[DESCRIPTION-READ] 7d4a4925f119f8c05e3d11615f95851c42e4db0e381a24ca9cf1f8e4a4654019 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
efac26a to
fc1bd93
Compare
|
Rebased: main moved in docs/feature-map/README.md and test/test_json_object_body_guard.py (same files), plus files this PR imports or sits beside, since this head was built (f58c3cf -> 759bb96); CI re-running. The new head also registers [operator: bolichen97] |
fc1bd93 to
b395035
Compare
|
Rebased: main moved in docs/feature-map/README.md, test/test_dashboard_server_composition_contract.py, test/test_dashboard_server_composition_contract_reach.py and test/test_json_object_body_guard.py since this head went green (759bb96 -> 03016b6); CI re-running. The two pins this PR moves were conflicts and are re-derived on the merged tree: the lazy-import count (this PR adds two handler names to main's count) and the MCP route table's row count and digest (this PR adds three rows). The code is unchanged from the previous head. [operator: bolichen97] |
b395035 to
3f8e2a3
Compare
|
Rebased: main moved in test/test_dashboard_server_composition_contract.py (lazy-import count) and docs/feature-map/README.md since this head was built (03016b6 -> 666f962); CI re-running. The Backend shard 5 reds on b395035 were main's, fixed by #32606. The new head also makes |
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
3f8e2a3 to
b41b15c
Compare
|
This PR edits a design document ( Review result on this head: no blocking findings. The review checked these points:
Done well: promote and update now share one owner of the run checks ( The review lanes have no verdict on this head yet. Their runs ended on an infrastructure error, so they need a re-run. Optional:
|
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved at a maintainer's direction: the README change in this PR was agreed by a maintainer. PR Readiness passed on b41b15c, and all five review lanes report no blocking finding and no missing evidence on this head. No open change request, and no linked issue is T3 or T4.
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.
Builds on #27663 by @weijian722.
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 cannot help with larger scripts: it caps a script at 10,000 bytes and refuses non-ASCII outside comments, on purpose.This PR is the backend half: the two routes the dashboard's update dialog will call.
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 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
capabilitiesentry for update: both actions pass the same run checks, so the dialog can gate on the existing save check.test_workflow_library_mutations_are_human_only).POST /api/workflows/runs/{run_id}/promoteaccepts or returns.workflow.updatechange card's size or character limits.What changed (motivation → approach → change)
A run whose script you edited and tested can become the next revision of the saved workflow it came from, so the library keeps one workflow with its history instead of a new copy each time.
GET /api/workflows/runs/{run_id}/update-definition?workflow=id,slug,name,revision,format), the diff from its current source to the run's, andrun_source_sha256. Withoutworkflowit suggests one, or returnsnull.POST /api/workflows/runs/{run_id}/update-definition{workflow, expected_revision, expected_source_sha256}The update trusts what promotion already trusts: an ad-hoc run, finished or a paused TaskRunner plan, still holding its original source. Those checks are one helper,
_reusable_run, that both paths call. Two pins keep Apply honest. The library'sexpected_revisionstops a stale write to the workflow, and the digest the preview returned stops an Apply of a run source the owner never saw, since a paused plan can be replanned while the dialog is open. A run whose format differs from the workflow's, and a source identical to the pinned revision, are refused too. Each refusal has its own code: 404 for an unknown run or workflow, 409 for a run that cannot be saved, a changed run source or a stale revision, 400 for an unchanged source, a format mismatch or an invalid script.The logic lives in a new module,
src/kiro_crew/workflows/update_from_run.py, reached through two thinWorkflowServicemethods insrc/kiro_crew/workflows/service.py. The module sits below the service in the workflows layering contract (test/test_workflows_architecture.py): it is handed the service and never imports it, so theMETA.adapted_fromparser both need moved fromservice.pyintosrc/kiro_crew/workflows/library.pyasdeclared_lineage. It now also ignores a revision that is not an ASCII number ("wfd_x@²"):"²".isdigit()is true butint("²")raised, which the new preview would have turned into a 500. The routes are insrc/kiro_crew/dashboard/handlers/workflows.py, registered insrc/kiro_crew/dashboard/server_runtime/mcp_routes.py, behind the same two owner gates as promote, and each call writes its SEL row (workflow_definition_update,workflow_definition_update_preview).The suggested target comes from the run's lineage first, then the script's
METAname and the run's name. An edited rerun of a saved Python workflow keeps that workflow asderived_fromancestry, as an adapted TaskRunner plan already does;src/kiro_crew/workflows/runner.pyandsrc/kiro_crew/workflows/registry.pypass that field through. The diff isworkflow_source_diffinsrc/kiro_crew/dashboard/change_cards_readers.py, the change card's diff without the card's size cap, because it goes to the owner's own dialog and is never stored in a card; thesrc/kiro_crew/dashboard/change_cards.pyfacade names it in its manifest. The workflows spec and the feature map name both routes.Backwards compatibility
Compatible: two new routes and one new optional run field; promote, the change card's capped diff and every existing route answer as before.
Removes nothing: the diff only adds routes, a module, two service methods and run ancestry, and moves the private
META.adapted_fromparser intolibrary.py, where a non-ASCII digit revision that used to raise is now ignored like any other malformed reference; the change card's_workflow_diffkeeps its cap and its output.Tests
test/test_workflows_service_update_from_run.py: an update appends revision N+1 and keeps earlier revisions; a stale revision, an unchanged source, a format mismatch, an unknown workflow, an unknown run and a run source changed since the preview are each refused and write nothing; a saved invocation is refused; the preview returns only the target's summary fields and suggests the workflow from the script'sMETA, fromadapted_from(and skips anadapted_fromwhose revision is²), from an edited rerun's ancestry (carried into a later rerun) and from a TaskRunner plan's lineage.test/test_workflow_definition_handlers.py: each refusal maps to its status and code;workflow, an integerexpected_revisionandexpected_source_sha256are required; the preview never returns either source; its diff is not capped at the card's limit; app and unauthenticated callers get 403 with an SEL row.test/test_r7_owner_gate_refusals.py/test/test_r7_owner_gate_positive_controls.py: a non-owner gets 403 on both routes, and the owner gets through.test/test_json_object_body_guard.py,test/test_dashboard_server_composition_contract.py,test/test_dashboard_server_composition_contract_reach.py: the new body cap, lazy imports and route rows are registered.test/test_workflows_architecture.py: the layering contract placesupdate_from_runbelowservice.Determinism: the new tests (the whole new service file plus the new handler and owner-gate tests) passed 20 repeats at
-n0and 10 at-n 4 --dist loadgroup --max-worker-restart=2besidetest/test_workflows_service.pyandtest/test_change_card_workflow_save.py; 110 node ids of the changed files passed in a shuffled order (seed 3256).Manual verification
N/A — backend-only; the routes are covered end to end through aiohttp test clients, and no UI calls them yet.
Related Issues
Part of #27525
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.