Skip to content

feat: update a saved workflow from a finished run - #32352

Merged
bolichen97 merged 1 commit into
mainfrom
fix/27525-update-workflow-from-run
Nov 8, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/27525-update-workflow-from-run

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

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>-2 instead of revision N+1. The only way to add a revision today is to paste the whole script into Customize → Workflows. The workflow.update change 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/-3 copies whose /workflow commands 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

  • The dashboard's Update existing… button and dialog, and gating the chat run card's Save button: a separate frontend PR for the same issue.
  • A run capabilities entry for update: both actions pass the same run checks, so the dialog can gate on the existing save check.
  • Any MCP tool. Agents still cannot write the library (test_workflow_library_mutations_are_human_only).
  • Changing what POST /api/workflows/runs/{run_id}/promote accepts or returns.
  • Raising the workflow.update change 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.

Route (owner-only) What it does
GET /api/workflows/runs/{run_id}/update-definition?workflow= Names the saved workflow an update would revise (id, slug, name, revision, format), the diff from its current source to the run's, and run_source_sha256. Without workflow it suggests one, or returns null.
POST /api/workflows/runs/{run_id}/update-definition {workflow, expected_revision, expected_source_sha256} Appends the run's exact source as that workflow's next revision.

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's expected_revision stops 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 thin WorkflowService methods in src/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 the META.adapted_from parser both need moved from service.py into src/kiro_crew/workflows/library.py as declared_lineage. It now also ignores a revision that is not an ASCII number ("wfd_x@²"): "²".isdigit() is true but int("²") raised, which the new preview would have turned into a 500. The routes are in src/kiro_crew/dashboard/handlers/workflows.py, registered in src/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 META name and the run's name. An edited rerun of a saved Python workflow keeps that workflow as derived_from ancestry, as an adapted TaskRunner plan already does; src/kiro_crew/workflows/runner.py and src/kiro_crew/workflows/registry.py pass that field through. The diff is workflow_source_diff in src/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; the src/kiro_crew/dashboard/change_cards.py facade 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_from parser into library.py, where a non-ASCII digit revision that used to raise is now ignored like any other malformed reference; the change card's _workflow_diff keeps 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's META, from adapted_from (and skips an adapted_from whose 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 integer expected_revision and expected_source_sha256 are 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 places update_from_run below service.

Determinism: the new tests (the whole new service file plus the new handler and owner-gate tests) passed 20 repeats at -n0 and 10 at -n 4 --dist loadgroup --max-worker-restart=2 beside test/test_workflows_service.py and test/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

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 7, 2026 13:30
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision b41b15caaad4a3a920eaeff2abc65c44a077ab1c touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of b41b15caaad4a3a920eaeff2abc65c44a077ab1c — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the run's source is read once and pinned by its digest and by expected_revision, promote and update share one eligibility check, and no reader outside the patch breaks.

Notes

  • workflow_source_diff now escapes hidden characters on added lines too, so the change card's diff changes as well. That is a no-op only while every card script passes the card's character checks; it should be pinned by an existing test_change_card_workflow_save.py case, not just stated in the docstring.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of b41b15caaad4a3a920eaeff2abc65c44a077ab1c — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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 PATCH /definitions/{ref}. Their only callers will be in the declared frontend PR.

Notes

  • Item 3 — zero consumers: no caller in this PR asks for a suggested target, and the frontend PR will make the first. "Without workflow it suggests one" checks four ordered sources (derived_from, adapted_from, META name, run name) before any dialog exists to show which of them is useful. Subtraction: have the preview require workflow and drop _suggest_target, or keep only the derived_from source, until the dialog's PR shows it needs the rest.

What this change ships

Inventory (7 items) — 6 justified

Intent: let the owner save a tested chat run as the next revision of the saved workflow it came from, instead of a -2 copy. This is an ADDITION.

  1. New owner-only POST adds a finished run's exact source as a saved workflow's next revision — justified
  2. New owner-only GET shows the target workflow, an uncapped diff and the source digest for that update — justified
  3. Without workflow, the preview suggests a target from four ordered sources — zero consumers
  4. An edited rerun of a saved workflow now records that workflow as derived_from ancestry, and later reruns carry it forward — justified
  5. An adapted_from reference whose revision uses a non-ASCII digit is now ignored instead of raising — justified
  6. Promotion's run checks are pulled into _reusable_run, which promote and update both call — justified
  7. Two new SEL operations: workflow_definition_update_preview, plus update rows written under the existing workflow_definition_update — justified

[FIRST-PRINCIPLES-REVIEWED] b41b15c

Description read

[DESCRIPTION-READ] 7d4a4925f119f8c05e3d11615f95851c42e4db0e381a24ca9cf1f8e4a4654019

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed b41b15caaad4a3a920eaeff2abc65c44a077ab1c — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] b41b15c

Verdict parsed from the review's SHA-scoped output markers for commit b41b15caaad4a3a920eaeff2abc65c44a077ab1c.

False positive or not applicable? A repository writer can comment:
/ai-review override fable b41b15caaad4a3a920eaeff2abc65c44a077ab1c false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of b41b15caaad4a3a920eaeff2abc65c44a077ab1c and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] b41b15c

False positive or not applicable? A repository writer can comment:
/ai-review override gpt b41b15caaad4a3a920eaeff2abc65c44a077ab1c false-positive: <reason, 20 to 500 characters>

@bolichen97
bolichen97 enabled auto-merge (squash) November 7, 2026 13:44
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 7, 2026
@bolichen97
bolichen97 force-pushed the fix/27525-update-workflow-from-run branch from efac26a to fc1bd93 Compare November 7, 2026 16:45
@bolichen97

Copy link
Copy Markdown
Contributor Author

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 update_from_run in the workflows layering contract and names workflow_source_diff in the change-cards facade manifest, the two backend reds on the previous head. The frontend red on the previous head was a flake that main fixed in #32345.

[operator: bolichen97]

@github-actions github-actions Bot added readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 7, 2026
@bolichen97
bolichen97 force-pushed the fix/27525-update-workflow-from-run branch from fc1bd93 to b395035 Compare November 7, 2026 20:30
@bolichen97

Copy link
Copy Markdown
Contributor Author

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]

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 7, 2026
@bolichen97
bolichen97 force-pushed the fix/27525-update-workflow-from-run branch from b395035 to 3f8e2a3 Compare November 8, 2026 01:03
@bolichen97

Copy link
Copy Markdown
Contributor Author

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 declared_lineage ignore a non-ASCII digit revision such as @² (it raised in int()), with a regression test, found by local review.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels 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
bolichen97 force-pushed the fix/27525-update-workflow-from-run branch from 3f8e2a3 to b41b15c Compare November 8, 2026 02:05
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in test/test_dashboard_server_composition_contract_reach.py (one new MCP route) after this head went green, which made the PR conflict (666f962 -> 7f11b5c); CI re-running. Only the route-table pin moved: 343 rows and a new digest. The rest of the patch is unchanged.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: passed Eligible automated validation passed for the current revision labels Nov 8, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

This PR edits a design document (docs/feature-map/README.md), so a maintainer must sign off on it before it can merge. A maintainer will post the decision here.

Review result on this head: no blocking findings. The review checked these points:

  • Both new routes are owner-only and refuse app tokens. They use the same gate as promote.
  • The POST body is bounded. The written source comes from the server-side run, never from the request.
  • update() reads the run source once and checks its sha256 against the previewed digest. It then writes those same bytes under the library's expected_revision check. The tests pin both refusals.
  • The change card's _workflow_diff keeps its cap and its output.
  • The moved declared_lineage no longer crashes on an adapted_from such as x@².

Done well: promote and update now share one owner of the run checks (_reusable_run), so the two paths refuse exactly the same runs.

The review lanes have no verdict on this head yet. Their runs ended on an infrastructure error, so they need a re-run.

Optional:

  • src/kiro_crew/dashboard/change_cards_readers.py: workflow_source_diff now escapes hidden characters on every line, not only on removed lines. On this path that escaping is the only hidden-character control, because validate() accepts a bidi override in a string literal. If you put back the old removed-only branch, no test goes red. Add a test that sends an added line and a context line with characters such as U+202E and U+200B, and assert that each one is spelled out.
  • The single commit reuses code from feat(workflows): update a saved workflow from a finished run #27663 by weijian722 but has no Co-authored-by trailer. Credit comes only from commit authors and trailers. Add the trailer, as CONTRIBUTING.md asks for a PR that takes over another one.
  • feat(workflows): update a saved workflow from a finished run #27663 is still open with the same goal and issue. Close it as superseded by this PR, and hand over the claim on Workflows: update a saved workflow from a finished run #27525.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 8, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@bolichen97
bolichen97 merged commit 38a0633 into main Nov 8, 2026
101 of 109 checks passed
@bolichen97
bolichen97 deleted the fix/27525-update-workflow-from-run branch November 8, 2026 04:48
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 8, 2026
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.

2 participants