Repository navigation
✨ Workflow models: versions, diff, confirm-inferred and label regeneration on bind - #17685
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor. @clubanderson this PR is held at Failing checks:
Next: the hive does not push to your branch. Push a new head (or reply here); CI and the review swarm re-run automatically and the PR returns to the normal path. Review findings from Correctness re-review at 1. Still present — unvalidated model label colour halts stage labelling for the bound repo (
with 2. Still present —
--- a/src/pkg/workflowmodel/store/store.go
+++ b/src/pkg/workflowmodel/store/store.go
@@ func (s *Store) NextVersion(name string) (string, error) {
- all, err := s.List()
+ s.mu.Lock()
+ defer s.mu.Unlock()
+ return s.nextVersionLocked(name)
+}
+
+func (s *Store) nextVersionLocked(name string) (string, error) {
+ all, err := s.readIndex()
if err != nil {
return "", err
}
@@
+// SaveNext saves m under the next free integer version, assigned under the
+// store lock so concurrent callers can never collide.
+func (s *Store) SaveNext(m *workflowmodel.Model, by string, now time.Time) (Entry, error) {
+ if m == nil {
+ return Entry{}, errors.New("nil model")
+ }
+ if IsBuiltin(m.Metadata.Name) {
+ return Entry{}, fmt.Errorf("%w: %s", ErrReadOnly, m.Metadata.Name)
+ }
+ s.mu.Lock()
+ defer s.mu.Unlock()
+ v, err := s.nextVersionLocked(m.Metadata.Name)
+ if err != nil {
+ return Entry{}, err
+ }
+ m.Spec.Meta.Version = v
+ return s.saveLocked(m, by, now) // body of Save after its s.mu.Lock()
+}and in 3. New, low — versions literally named
Review findings from Intent-alignment review at a7fccc9 (read the diff plus Model label colours are unvalidated and a bad one can stall built-in stage labelling for the bound repo —
with Minor, non-blocking: Review findings from Read the three commits against the Finding — an unvalidated model label colour halts stage labelling for the whole bound repo
Consequence: one typo in a bound model's Checked and fine
Body and diff agree; no scope beyond the RFC phase 4 backend. I have not approved or requested changes — leaving the colour fix to the author and a maintainer's call on whether it must land in this PR or a follow-up. hive/awaiting-ci: rebased onto v5 (one doc conflict in src/docs/design/workflow-models.md — both sections kept, phase 3b tab then phase 4 backend); author commits and sign-offs preserved. CI pending — sweep will merge when green and the outstanding review is resolved. 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 Review findings from Read the Go changes against the tree at Verified:
Low — Sequencing: this PR and #17688 (phase 3c) both edit
|
There was a problem hiding this comment.
Security perspective (read at head a7fccc9): no blocking issue. Path params and the new fromName/toName query params all go through Store.Get → path() which enforces nameRe/versionRe before any filepath.Join (store.go:108-115), confirm is owner-gated and audited, and only owner-gated routes can save or bind a model. One low advisory:
Low — model label names/colours are unvalidated and can rename/recolour arbitrary pre-existing labels in bound repos (automerge_stage_labels.go, new ensure closure, case !strings.EqualFold(cur.GetColor(), color) → EditLabel(ctx, owner, repo, cur.GetName(), &gh.Label{Name: gh.Ptr(name), ...})). Profile.LabelDefs passes LabelEntry.Name/Color straight through (confirm.go LabelDefs), and nothing in compile.go validates them (LabelSet/LabelEntry in lifecycle.go:270-281). So a model entry named e.g. bug or stage:030 with a different colour renames the repo's existing label to the model's casing and recolours it, in every bound repo; a non-hex colour makes EditLabel 422 and aborts the remaining labels for that repo (the create-path 422 is swallowed, the edit-path one is not). The writer is an owner, so this is an owner-controlled side effect rather than an exploit — but it's a new way for dashboard config to mutate third-party repos' label sets. Suggest validating at compile/save time:
--- a/src/pkg/workflowmodel/confirm.go
+++ b/src/pkg/workflowmodel/confirm.go
@@ func (p *Profile) LabelDefs(defaultColor string) []LabelDef {
d := LabelDef{Name: e.Name, Color: e.Color, Description: e.Description, State: e.State}
- if d.Color == "" {
+ if !hexColorRe.MatchString(d.Color) {
d.Color = defaultColor
}with var hexColorRe = regexp.MustCompile(^[0-9a-fA-F]{6}$), and in ensureStageLabels skip model entries whose lower-cased name collides with the built-in family (stagelabels.LabelDefsFor(kinds) / stage labels) so the model can't silently recolour hive's own labels.
— hive: agent=adjudicator-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
…Defs, store.NextVersion Pure, deterministic model diff (columns/states/transitions/labels/rules/meta), Confirm that clears inferred confidence and localises provenance, the label vocabulary a profile reconciles, and the store's next free integer version. Refs #17620 Signed-off-by: Andrew Anderson <andy@clubanderson.com>
GET /api/workflows/{name}/versions, GET /api/workflows/{name}/diff?from&to
(fromName/toName for cross-model), POST .../{version}/confirm (owner,
audited workflow_confirm, 409 for hive-default) and GET .../{version}/labels.
Documented in dashboard/openapi.json.
Refs #17620
Signed-off-by: Andrew Anderson <andy@clubanderson.com>
… rebind ensureStageLabels asks the stage engine's WorkflowFor lookup for the profile bound to the repository and creates or recolours its LabelDefs after the built-in family, memoised per repo and profile hash so a binding change takes effect on the next pass. Unbound repositories take the pre-existing path unchanged. Design doc section and changelog fragment. Refs #17620 Signed-off-by: Andrew Anderson <andy@clubanderson.com>
a7fccc9 to
5604228
Compare
|
@clubanderson this PR is back in your court (
Once the new head lands, CI and the review swarm re-run automatically and the PR returns to the normal path. Current head: |
There was a problem hiding this comment.
Read the diff against v5 plus the callers it hooks into (stageengine.Options.WorkflowFor at reconciler.go:55, Store.Save / Store.List, the dashboard helpers). The change does what the body says; nothing here looks blocking. Two low-severity edges a maintainer may want to decide on, then what I verified.
Low — confirm can silently overwrite on a race. handleWorkflowConfirm (src/pkg/dashboard/api_workflows_versions.go:97-107) calls st.NextVersion(name) and then st.Save(c, …) as two separate store operations. NextVersion (store.go:422-445) reads List() under its own lock and returns; Save (store.go:234-281) takes the lock afterwards and, when name@version already exists in the index, replaces it in place (store.go:268-275) rather than refusing. Two confirms of the same model landing close together both compute the same next, and the second overwrites the first's file and index entry with no error returned. Owner-only route and a narrow window, so low — but the body's "never a taken one" holds only for a single caller. A SaveNew/O_EXCL-style refusal, or doing the allocation inside Save when Version == "", would close it.
Low — versions and diff are valid version strings and are now shadowed. versionRe (store.go:55) accepts ^[A-Za-z0-9][A-Za-z0-9.-]{0,31}$, so a model can be saved as foo@diff or foo@versions. The new literal routes GET /api/workflows/{name}/versions and GET /api/workflows/{name}/diff (api_workflows_versions.go:19-20) win over GET /api/workflows/{name}/{version} in the Go 1.22 mux, making those two versions unreadable via GET (PUT/DELETE still reach them). Either reserve the two words in checkKey or accept the edge and note it.
What I verified as correct:
ensureStageLabels(automerge_stage_labels.go:1657-1664): the memo key isensured[full] && ensuredWorkflow[full] == modelHash, and unbinding yieldsmodelHash == "", so an unbind re-lists once and then memoises again.workflowProfile(:1751-1760) nil-guardsc,c.stageEngineandWorkflowFor, and excludeshivedefault.Name, so unbound repos take exactly the old path.- The
ensureclosure updatesexistingafter a create (:1712-1715) and after a recolour (:1721), so a model label that duplicates a built-in name in the same pass hits the recolour branch rather than a second create. Diffis deterministic:diffItemssortsAdded/Removed/Changed(diff.go:154-156), andtransitionItemsonly disambiguates with@onwhen afrom>topair repeats (diff.go:217-226), matching the body.Confirm(confirm.go:15-43) clones via JSON before mutating, so the stored source model is untouched;Inferredis computed on the original beforeConfirm(api_workflows_versions.go:96), so the audit count is right.openapi.jsoncarries all four new paths.
Not approving — a human's call. No duplicate of #17688 (that is RFC phase 3c and shares only api_workflows.go registration, openapi.json and the design doc; both will need a rebase after whichever lands first).
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
merged by Hive trusted-author auto-merge: author @clubanderson holds role owner and GitHub permission admin on repo; CI green at 5604228. |
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
Mutation testing⏱️ The 900s mutation budget ran out, so 2 package(s) were not fully mutated and the results below do not cover them:
❌ gremlins did not produce a report for 1 package(s), so no verdict can be derived from this run (see the job log):
Verdict: |
RFC phase 4 (backend) of #17620, on
v5. Go,openapi.json, docs and changelog only — the diagram editor UI lands on a stacked branch.What
pkg/workflowmodelDiff(a, b *Model) ModelDiff— pure, deterministic, JSON-serialisable structural diff. Sets:columns(by id),states(by id, regions flattened; fields label/owner/type/parent/guardRef/pipelines/origin/column/number/kinds/waiting/replies/confidence),transitions(from>to,from>to@onon duplicate pairs),labels(by name),rules(id orrules[i]),meta(version/author/description/license/source/provenance/mode).summarylike+2 states, −1 transition, 3 changed;emptyflag.Confirm(m, by) *Model— deep copy with everyconfidence: inferred(states at any depth, events, gates) confirmed,meta.provenance = local,meta.version = ""(store assigns next),metadata.annotations["workflow.hivecommons.dev/confirmed-by"] = by.meta.sourcekept; input untouched. AlsoClone,Inferred,LabelDef,(*Profile).LabelDefs(defaultColor).store.NextVersion(name)— largest integer version + 1, never a taken one (Save does not auto-assign).API (
pkg/dashboard/api_workflows_versions.go, all inopenapi.json)GET /api/workflows/{name}/versions{versions: []Entry}; hive-default → its one virtual entry; 404 unknownGET /api/workflows/{name}/diff?from&to[&fromName&toName]{from, to, diff}; 400 missing params, 404 unknown versionPOST /api/workflows/{name}/{version}/confirm{entry, confirmed, from}; 409 for hive-default; auditworkflow_confirmGET /api/workflows/{name}/{version}/labels{name, version, hash, prefix, labels[{name,color,description,state}], commands[{state,verbs}], stages[{state,number,label}]}; 400 + diagnostics for a non-compiling draftLabel regeneration on bind (
pkg/github/automerge)ensureStageLabelsnow also provisions the bound model'sLabelDefs(stagelabels.StageColor)after the built-in family, reusing the one list call, whenstageengine.Options.WorkflowForreturns a non-nil, non-hive-default profile.StageTracker.ensuredWorkflow): rebinding / unbinding / a new bound version changes the hash → next pass re-lists and provisions what is missing. No config-reload hook needed (binding edits mutate the live config,WorkflowForreads it each call).Docs
docs/design/workflow-models.md: new section "Versions, diff, confirm and label regeneration (RFC phase 4, backend)".changelog.d/added-workflowmodel-versions-diff-confirm.md.Tests
pkg/workflowmodel/diff_test.go(Diff/Confirm/LabelDefs/Clone/Inferred; package coverage 93%),store/store_test.goTestNextVersion.pkg/dashboard/api_workflows_versions_test.go— happy + error paths for all four routes, owner gating, audit, openapi parity.pkg/github/automerge/automerge_stage_labels_workflow_test.go— unbound identical, bound provisions, rebind re-provisions, unbind leaves labels.Gaps / deviations
cncf-techdocsas shipped has nolabelsblock, so it regenerates nothing; the preview shows its commands and built-in stages.Confirmrecords the confirmer in a metadata annotation rather than wideningMeta.ensuredon binding change (no reload path reaches the automerge tracker).Refs #17620