Skip to content

Fixes #35456: Approval task preview lists every change since its approval cycle began - #38857

Open
Vamsi-klu wants to merge 21 commits into
open-metadata:mainfrom
Vamsi-klu:fix/35456-approval-preview-from-history
Open

Vamsi-klu wants to merge 21 commits into
open-metadata:mainfrom
Vamsi-klu:fix/35456-approval-preview-from-history

Conversation

@Vamsi-klu

@Vamsi-klu Vamsi-klu commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #35456

The Proposed Changes card on an approval task now lists what the entity changed since its approval cycle began, recomputed from the version history every time the workflow writes the task.

The two exact repros in the issue already pass on main. Three changes fixed them on the way: #35972 strips the workflow's own status move from the preview, #37010 previews the edit that opened the cycle, and #32335 writes workflow fields with optimistic locking, so the status write is stored as its own version and no longer folded into the user's version (that folding is what the metric report on 2.0.5 shows). ITs 1 and 2 below pin both repros so they stay fixed.

What was still wrong is the shape of the preview itself. It was a running merge: each new task copied the map stored on the open task it superseded and added one change read off the entity when the task was created. Nothing ever recomputed it, so three things still went wrong on main:

  1. A wrong map carried from an earlier task, for example one stored before an upgrade, was copied into every later task of the cycle. A task whose only new change was the status move came out identical to the task before it, which is the first symptom in the issue.
  2. An edit that started no run never showed up. Bot edits start no run, and neither do edits the trigger filter skips, yet approving still accepts them and rejecting still rolls them back. Example: the ingestion bot edits a term's description while it is In Review, and the next task still shows the old description.
  3. With two open tasks to supersede, the map carried forward was whichever one the list returned first.

ITs 4 and 5 reproduce 1 and 2 and fail on main. RED run on the unfixed code:

ApprovalTaskPreviewIT on main (1971feb202 plus the test commit only)
Tests run: 6, Failures: 0, Errors: 2, Skipped: 0

aBotEditDuringTheCycleIsInTheNextPreview: ConditionTimeout after 3 minutes
  expected: {synonyms={removed=[], added=[Alias]}, description={removed=[Original definition], added=[Ingested definition]}}
  but was:  {synonyms={added=[Alias], removed=[]}, description={added=[Edited definition], removed=[Original definition]}}

aStalePreviewOnTheOpenTaskIsNotCarriedIntoTheNextTask: ConditionTimeout after 3 minutes
  expected: {synonyms={removed=[], added=[Alias]}, description={removed=[Original definition], added=[Edited definition]}}
  but was:  {synonyms={added=[Alias], removed=[]}}

Behavior after this change:

  • An approval task that is not a change request review or a lifecycle move previews the fold, oldest first, of the stored change of every version newer than the cycle's base version. It uses the same set cancellation as before, so an edit taken back within the cycle still cancels out, and the status is still left out (the record "An approval preview omits the workflow's own status move" still holds).
  • A successful rebuild replaces the stored preview. If the history read fails, the task opens with any carried entries and marks them as incomplete.
  • Edits that start no run appear in the next preview when they are newer than its baseline. This includes bot edits made before the workflow opens a task and fields the trigger excludes, with the workflow status omitted.
  • proposedChangesBaseVersion records where the cycle began. The opening task uses the earlier of the triggering edit's previous version and the latest approved version found in history. A task that supersedes or reenters uses the earliest triggering or carried base.
  • proposedChangesIncomplete marks failed reads and snapshot fallbacks. The Proposed Changes card and the default task-created notification both warn when the flag is set, even when there are no entries.
  • Change request reviews and lifecycle approvals are unchanged, with one edge: a change request run whose revision has no open changes left now keeps the preview it has, where before it fell back to the entity's latest change.

This supersedes the decision record "An approval preview opens with the edit that started the cycle" and adds a new record, "An approval preview lists the change since its cycle began". The direction still needs agreement from the decider of the record being superseded, who has been working in this same code recently (#38708, and #37901 is still open). The proposal is on the issue; I built the full change anyway so there is something concrete to look at, and I will rework it if the answer is no.

Type of change:

  • Bug fix

High level design:

New pieces, all in governance/workflows/util unless noted:

  • ApprovalCycleHistory reads the stored versions of the cycle. It starts from a fresh read of the entity and follows each change's recorded previous version, one stored row at a time, and stops at the base. It does not page listVersionsWithOffset, which the plan suggested: that query orders rows by their extension name as a string, so once an entity passes version 10.0 a page of "newest" rows starts at 9.9 and a walk that stops at the base would stop too early. Following the recorded previous version is the same link the server already relies on when it consolidates a session (getPreviousVersion). The walk reads up to 200 versions. If a row is missing or the cap prevents reaching the base, it compares the base and current versions when both are available and marks the result incomplete. This keeps the visible edits while warning that nested changes, such as a column's description, can be missing.
  • ApprovalCycle.baseVersion takes the earliest triggering or carried base. An opening task also considers the approved baseline using the same predicate as rollback.
  • ApprovedBaseline is the approved version predicate moved out of RollbackEntityImpl unchanged, so the preview and rollback agree on what counts as the last approval. RollbackEntityImpl now calls it; its tests pass unchanged.
  • TriggeringChange.baseVersion gives the version the triggering edit was made from.
  • ChangePreviewUtils gets foldChanges, withCyclePreview and cycleBaseOf. buildProposedChangesPayload is narrowed to the change request revision, and the old hop logic (pickIncrementalOrFull, the 2 and 4 argument overloads) is gone. preserveProposedChanges becomes preservePreviewState and carries the base key too.
  • CreateTask wires it in: the preview is computed lazily and only for the two approval task types, inside a FreshReadScope, and the prior open approvals are sorted oldest first instead of taking an arbitrary one.

Fallbacks for state from before the upgrade:

  • A carried task without the key, or a run without a triggering version, starts from the newest version a reviewer accepted (the rollback rule), else from the version before the latest change.
  • A task's own payload without the key, on the reentry path, starts from the version before the latest change.

Why a stored pointer and not a rule derived from the history alone: some workflows never write Approved (the custom table workflows in the ITs end without a status write), and when the requester's own approval write is consolidated the approval transition disappears from the history.

Alternatives I rejected: fixing which hop the running merge picks (still carries stale maps and still misses edits that started no run), recomputing on every task read (every GET and list would walk history, and notifications carry the stored payload), using snapshot diffs for every task (top-level list changes can hide edits within a column), and a migration to rewrite open tasks.

Rollout:

  • No migration. An open task stored before this change keeps its preview until the next task write on it, which recomputes it through the fallback above. A task that is never written again keeps its stored preview until it is decided, as with the status record.
  • No SQL or search changes. Tasks are not indexed. Each approval task write now does one indexed row lookup per version in the cycle.
  • The 2.0.x line needs its own PR: that code has neither the optimistic locking status write nor the status strip.
  • feat(governance): request a lifecycle exit such as Deprecated from the asset's status #37901 also edits CreateTask near the prior task lookup, so whichever lands second will need a rebase.
  • Public methods removed or renamed in ChangePreviewUtils: the 2 and 4 argument buildProposedChangesPayload overloads, and preserveProposedChanges (now preservePreviewState). A code search across the open source repository found no other callers; I could not search the Collate repository, so someone with access should check it before merge.

Tests:

Use cases covered

  1. A glossary term goes through three approval cycles; each task shows only its own edit (the issue's first repro).
  2. An approved metric edited by someone who isn't a reviewer shows the description change and no status change (the issue's second repro).
  3. Three edits while a task is open, by two users, each supersede the task; the last one shows the whole cycle.
  4. The open task's stored preview is replaced with a status only map; the next task still lists the whole cycle.
  5. The ingestion bot edits the description while the term is In Review; the next task shows the bot's description.
  6. A reviewer edits an approved term (approved on the spot), then someone else edits it; the task starts from the reviewer's version.
  7. The ingestion bot edits an approved term before someone else opens a cycle. The first task previews both edits, and rejection restores the approved term.
  8. A missing version triggers a snapshot comparison that retains visible edits and warns about incomplete history.
  9. A missing version and a missing base leave the changes after the gap with the same warning.

Unit tests

  • I added unit tests for the new/changed logic.
  • New: ApprovalCycleHistoryTest, ApprovalCycleTest, TriggeringChangeTest.
  • Updated: ChangePreviewUtilsTest (fold semantics replace the hop tests), CreateTaskLifecycleMoveTest, CreateTaskTest (oldest first priors).
  • RollbackEntityImplTest is unchanged and passes, which covers the predicate move.
  • Local run: 196 tests in 9 classes, 0 failures (ChangePreviewUtilsTest 56, CreateTaskTest 96, ApprovalCycleHistoryTest 10, RdfOntologyContractTest 10, RollbackEntityImplTest 7, ApprovalCycleTest 6, TriggeringChangeTest 5, CreateTaskLifecycleMoveTest 3, CreateTaskPostCommitPersistTest 3).
  • ApprovedBaseline has no test of its own; it is the predicate moved verbatim and is covered by RollbackEntityImplTest and the baseline cases in ApprovalCycleHistoryTest.

Backend integration tests

  • I added integration tests for the changed behavior.
  • ApprovalTaskPreviewIT covers the nine use cases above.

Local results at 5f77e8a, MySQL and Elasticsearch, each lane run the way CI runs it:

  • Parallel lane: 23 run, 0 failures. ApprovalTaskPreviewIT 6 of 6 (including the two that fail on main), GlossaryTermInheritedReviewerApprovalIT 7, GlossaryTermMoveApprovalIT 5, and the five approval methods of MetricResourceIT.
  • Global state lane: 14 run, 0 failures. ChangeRequestApplyIT 11, and three WorkflowDefinitionResourceIT methods: the two existing preview tests (test_approvalPreviewShowsTheChainOfEditsNotTheWorkflowsStatusWrite, test_approvalPreviewShowsTheNetOfEditsTakenBackWithinTheCycle) and test_tagAnotherChangePublishedLeavesTheRequestAndTheRestStaysUnderReview, which covers the change request preview refresh.

Not run locally: the rest of WorkflowDefinitionResourceIT and MetricResourceIT, and the nightly suites the planner lists as impacted but not local.

Review follow-up at 7cfe7c130ac

  • All 205 focused Java unit tests passed. They cover history-read exceptions, missing history, the 200-version cap, same-name column edits, and the default task-created notification.
  • All nine ApprovalTaskPreviewIT cases passed against MySQL and Elasticsearch. The new workflow regression checks that the opening preview includes the bot's edit and that rejection restores the approved term. The local retry gave Elasticsearch a longer startup window and limited its JVM to four processors.
  • All three targeted task-page Jest tests and both Java modules' Spotless checks passed.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Verified the warning with the three focused TaskTabNew Jest tests, including a task with only the incomplete flag.

Manual testing performed

Ran all five approval and rollback scenarios end to end against live MySQL, Elasticsearch, compiled UI, and local SMTP builds for both main (df1fdcdc27e) and this branch (28f17d3fe48). Results are captured side by side below.

UI screen recording:

Side-by-side screenshots captured against live builds of main (df1fdcdc27e, Before) and this branch (28f17d3fe48, After) running the same five scenarios end to end against MySQL, Elasticsearch, the compiled UI, and local SMTP delivery.

1. Second approval cycle on a glossary term with a stale prior preview

BusinessGlossary.CustomerLTV is approved with "Original definition", updated to "Accepted definition" and approved in cycle 1, then updated to "Edited definition" in cycle 2. After seeding the open task with the stale cycle 1 preview (Original -> Accepted definition) and adding synonym CLV, main carries the stale description diff forward into the superseding task, while this branch recomputes from version history (Accepted -> Edited definition plus CLV).

Before (main at df1fdcdc27e) After (this branch at 28f17d3fe48)
Cycle 2 task preview on main showing stale description diff Cycle 2 task preview on branch showing recomputed description diff

2. Bot edit outside review (ingestion-bot), preview and entity after reject

BusinessGlossary.MonthlyActiveUsers is approved with "Original definition". ingestion-bot (not in triggeringBots) updates the description to "Ingested from warehouse pipeline" outside review. A human then adds synonym MAU, opening an approval task, and the reviewer rejects it. Both previews show only the reviewed synonym MAU, while on reject main reverts ingestion-bot's description back to "Original definition" and this branch reverts only MAU and keeps "Ingested from warehouse pipeline".

Task preview:

Before (main at df1fdcdc27e) After (this branch at 28f17d3fe48)
Task preview on main with bot edit outside review Task preview on branch with bot edit outside review

Entity after reject:

Before (main at df1fdcdc27e) After (this branch at 28f17d3fe48)
Term after reject on main with bot description reverted Term after reject on branch preserving bot description

3. Bot listed in triggeringBots (catalog-sync-bot), preview and entity after reject

A workflow with triggeringBots: ["catalog-sync-bot"] governs BusinessGlossary.NetRetentionRate. catalog-sync-bot edits the description to "Synced by catalog-sync-bot", opening an approval task, and unlisted ingestion-bot adds synonym NRR while the task is open. The task preview shows catalog-sync-bot's description change (and excludes NRR). On reject, main reverts the description and also removes unlisted ingestion-bot's synonym NRR, while this branch reverts catalog-sync-bot's description and keeps NRR.

Task preview:

Before (main at df1fdcdc27e) After (this branch at 28f17d3fe48)
Task preview on main for triggering bot edit Task preview on branch for triggering bot edit

Entity after reject:

Before (main at df1fdcdc27e) After (this branch at 28f17d3fe48)
Term after reject on main wiping unlisted bot synonym Term after reject on branch reverting listed bot edit and keeping unlisted bot synonym

4. Table workflow with rollback (no entity reviewers)

A table approval workflow with rollbackEntityTask and an explicit reviewer governs analytics_postgres.warehouse.public.customer_orders (which has no entity reviewers). Cycle 1 approves "Approved table description". Cycle 2 edits the description to "Unreviewed draft description" and the reviewer rejects it. On main, the table remains Approved with "Unreviewed draft description" left in place; on this branch, rollback restores "Approved table description".

Before (main at df1fdcdc27e) After (this branch at 28f17d3fe48)
Table after reject on main leaving unreviewed draft description Table after reject on branch restoring approved table description

5. Incomplete history warning on the task card and task-created notification

BusinessGlossary.GrossMargin is approved with "Original definition", edited to "Edited definition" (opening task 1), and its intermediate version row (glossaryTerm.version.0.4) is removed from entity_extension before adding synonym GM (opening task 2 and dispatching the task-created email notification). On main, neither the Proposed Changes card nor the email notification warns about missing history; on this branch, both display the incomplete-history warning above the remaining changes.

Task card:

Before (main at df1fdcdc27e) After (this branch at 28f17d3fe48)
Task card on main with no incomplete history warning Task card on branch showing amber incomplete history warning

Task-created email notification:

Before (main at df1fdcdc27e) After (this branch at 28f17d3fe48)
Task created email on main with no incomplete history warning Task created email on branch showing incomplete history warning

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes #35456: <short explanation>
  • My PR is linked to the issue via Fixes #35456 above.
  • I have commented on my code, particularly in hard to understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed. The new key is optional and open tasks heal at their next write, so no migration.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self review: I reviewed the final diff against REVIEW.md and fixed every finding.
  • Decision check: adds "An approval preview lists the change since its cycle began" under docs/decisions/ and marks the record it supersedes.
  • I have added a test that covers the exact scenario we are fixing.

@Vamsi-klu
Vamsi-klu requested a review from a team as a code owner November 26, 2026 13:04
@Vamsi-klu
Vamsi-klu requested a review from yan-3005 November 26, 2026 13:04
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@Vamsi-klu

Copy link
Copy Markdown
Contributor Author

Local test results for this branch. PR CI runs only the Java unit tests, so here is what I ran on my machine against MySQL and Elasticsearch.

RED, the new IT on main (1971feb plus only the test commit)

ApprovalTaskPreviewIT: 6 run, 4 passed, 2 failed.

  • Passed, as expected, because main already handles the issue's exact repros: aSecondApprovalCycleOnAGlossaryTermPreviewsOnlyItsOwnEdit, anApprovedMetricEditedByANonReviewerPreviewsTheEditedDescription, anEditWhileTheTaskIsOpenSupersedesItWithTheWholeCycle, aReviewerEditBetweenCyclesBecomesTheNextBase.
  • aBotEditDuringTheCycleIsInTheNextPreview failed: the next task still showed description: added [Edited definition] after the ingestion bot had changed it to Ingested definition.
  • aStalePreviewOnTheOpenTaskIsNotCarriedIntoTheNextTask failed: the next task showed only synonyms: added [Alias]; the description change from earlier in the cycle was gone.

Unit tests with the fix

196 tests in 9 classes, 0 failures: ChangePreviewUtilsTest (56), CreateTaskTest (96), ApprovalCycleHistoryTest (10), RdfOntologyContractTest (10), RollbackEntityImplTest (7, unchanged), ApprovalCycleTest (6), TriggeringChangeTest (5), CreateTaskLifecycleMoveTest (3), CreateTaskPostCommitPersistTest (3).

GREEN, integration tests with the fix

  • Parallel lane, 23 run, 0 failures: ApprovalTaskPreviewIT 6 of 6 (the two that failed on main now pass), GlossaryTermInheritedReviewerApprovalIT 7, GlossaryTermMoveApprovalIT 5, and the five approval methods of MetricResourceIT (post_metricWithoutReviewers_isApproved, post_metricWithReviewersButIncompleteMetadataRemainsDraft, post_metricWithReviewersCreatesApprovalTaskAndReviewerCanApprove, rejectNewMetricWithoutCommentSetsRejected, rejectMetricUpdateRollsBackPreviousApprovedVersion).
  • Global state lane, 14 run, 0 failures: ChangeRequestApplyIT 11, plus WorkflowDefinitionResourceIT#test_approvalPreviewShowsTheChainOfEditsNotTheWorkflowsStatusWrite, #test_approvalPreviewShowsTheNetOfEditsTakenBackWithinTheCycle and #test_tagAnotherChangePublishedLeavesTheRequestAndTheRestStaysUnderReview (the last one covers the change request preview refresh, which this PR narrowed).

Not run locally: the rest of WorkflowDefinitionResourceIT and MetricResourceIT (only the approval preview and approval methods ran), and the nightly suites the planner lists as impacted but not local (IncidentGroupTrendScaleIT, ReindexBenchmarkIT, EntityLoaderSmokeUIIT). Line coverage on the changed classes was not measured.

@pmbrull pmbrull left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

❌ Changes needed · 2 🔴 · 0 🟡

Blockers ❌ 2 🔴
Nits ✅ none
Tests ❌ gaps in history-read failure and incomplete-cycle coverage
Cross-repo ✅ checked the task payload consumer and available Collate callers
Trade-off ❌ reading history is bounded, and the preview needs to surface partial results
Auto-approved ➖ changes needed and a maintainer decision on the superseding ADR

Thanks for covering edits that happen between approval tasks and for providing main and branch test results.

  • 🔴 CreateTask.java:1342 — A failed history read can abort task creation. Move the read inside the guarded preview path and test that the task still opens after a history read fails. Existing inline finding
  • 🔴 ApprovalCycleHistory.java:78 — A missing version or the 200-version cap can leave the preview showing only the most recent part of the cycle. Compute the complete diff or show reviewers explicitly that the preview is incomplete. Add coverage for both a missing version and the cap.

The PR adds an ADR that supersedes the accepted approval-preview rule. Confirm the new rule with the original decider. The linked issue also needs a maintainer to add it to Shipping and rerun the metadata check. Metadata check details

What I checked

Traced workflow task creation, the history walk, and the Proposed Changes consumer. The original two issue scenarios already pass on main. The new integration tests cover residual cases involving older or skipped edits. The author reports 196 unit tests and 37 MySQL and Elasticsearch integration tests passed. Backend CI passed. Metadata and Collate Compatibility are red. The Compatibility status did not provide a job log.

claude-verdict {"sha":"5f77e8a900098650061f1f9dcc44661a42d1d579","recommendation":"request_changes","blocking":2,"nits_to_fix":0,"human_decision":true,"tradeoff":"does_not_hold","cross_repo":"checked","tests_ok":false}

@Vamsi-klu
Vamsi-klu requested a review from a team as a code owner November 26, 2026 21:41
@Vamsi-klu

Copy link
Copy Markdown
Contributor Author

@pmbrull thanks for the review. Both blockers are fixed in 9c09aa4 through 2894227, and I replied in each thread with the details.

@yan-3005 this PR adds ADR:2026-11-26-an-approval-preview-lists-the-change-since-its-cycle-began, which supersedes your 2026-11-03 record about the preview opening with the edit that started the cycle. Instead of carrying the preview forward and folding in each hop, every task write now rebuilds it from the version history since the cycle's base. Could you take a look and let me know if you're OK with that rule? The record shows your agreement as pending until then.

What I ran locally on the new head: 190 unit tests across the 7 preview classes (including the new VersionDiffTest), ApprovalTaskPreviewIT 8/8 and GlossaryTermInheritedReviewerApprovalIT 7/7 on MySQL and Elasticsearch, and the TaskTabNew Jest file 52/52. I haven't run the Postgres/OpenSearch lane or the rest of the workflow ITs. yarn i18n hung on my machine, so I added the new locale key to all 21 files directly. The i18n check in CI will be the real confirmation for that part.

The linked issue still needs a maintainer to add it to Shipping and rerun the metadata check. Nothing to change in the code for that one.

VersionDiff delegates list comparisons to MutationPlanner, which filters inherited references. Exercise a historical snapshot with inherited owners, reviewers and domains alongside a real edit.

@pmbrull pmbrull left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

❌ Changes needed · 2 🔴 · 0 🟡

Blockers ❌ 2 🔴
Nits ✅ none
Tests ❌ gaps in the history-exception fallback and nested field diffs
Cross-repo ✅ checked the task payload, approval UI and notification consumer
Trade-off ❌ the snapshot fallback can hide edits while reporting a complete preview
Auto-approved ➖ changes needed and maintainer agreement on the superseding ADR

Thanks for fixing task creation when history is unavailable and adding the incomplete-preview warning. Two paths can still present an incomplete preview as complete.

  • 🔴 ChangePreviewUtils.java:334 — When the history lookup throws, the task opens with the existing payload. A superseded task can supply a stale preview, and a first task can have no preview at all. Set the incomplete flag in this path and show the warning in the task-created notification as well as the task page. Cover a failed fresh read with a carried preview.
  • 🔴 VersionDiff.java:50 — With a missing history hop, a table column’s description or tag can change without changing its name. The snapshot diff emits a whole-list change that the preview reduces to the same column names. Show the nested edit or mark this result incomplete. Add a regression with a missing hop and an edit to a field on an existing column.

The superseding ADR still needs agreement from the original decider. The linked issue needs to go into Shipping, and the Compatibility check is red. Metadata check

What I checked

Read the guarded history lookup, snapshot comparison, task payload, task page and notification template. The new tests cover a missing history row, but the failure test accepts the original payload without a warning and the snapshot tests do not exercise changed values inside a column. Backend, UI checks and generated types pass. The author reports 190 unit tests, 15 MySQL and Elasticsearch integration tests, and 52 task UI tests passed. PostgreSQL and OpenSearch are outstanding.

claude-verdict {"sha":"b489552bc0c4dbaf93952176f6d1bc368a37377b","recommendation":"request_changes","blocking":2,"nits_to_fix":0,"human_decision":true,"tradeoff":"does_not_hold","cross_repo":"checked","tests_ok":false}

@pmbrull pmbrull assigned yan-3005 and unassigned pmbrull Nov 27, 2026
@yan-3005

Copy link
Copy Markdown
Contributor

@Vamsi-klu reviewed at b489552 and ran the tests locally (MySQL + ES).

Tests

  • ApprovalTaskPreviewIT on this head: 8/8 pass.
  • Same IT on main + only your test commit: 4 pass, 2 fail (aBotEditDuringTheCycleIsInTheNextPreview, aStalePreviewOnTheOpenTaskIsNotCarriedIntoTheNextTask). Matches what you reported.
  • Unit tests (8 preview/task classes): 198/198 pass.

Still open before merge

  1. History read fails → task keeps the carried preview with no incomplete flag (pmbrull's thread). Also the task-created notification never reads proposedChangesIncomplete. Details in that thread.
  2. Missing version row → a column's description/tag edit is invisible in the comparison fallback, and the preview still counts as complete (pmbrull's thread). Simplest fix: mark every comparison-fallback result incomplete.
  3. A bot edit made before the cycle opens is not previewed but reject still reverts it. Repro and suggested fix inline on CreateTask.java.

Not run: Postgres + OpenSearch lane, full WorkflowDefinitionResourceIT / MetricResourceIT.

@yan-3005

Copy link
Copy Markdown
Contributor

@Vamsi-klu I ran scenario tests on main and on 7cfe7c1 (MySQL + ES): the seeded glossary workflow, glossary and table workflows with other shapes, and the consolidation cases. Edits merged into one version and edits taken back inside a cycle both preview correctly. Three things still need fixing in this PR.

1. Starting from the last Approved version breaks other workflow shapes

ApprovalCycle.baseVersion now goes back to the last ApprovedBaseline. That only works when a workflow writes Approved on approval and rolls back on reject, which is the seeded glossary workflow. A workflow definition can follow a different flow: reject can set Rejected instead of rolling back, and a workflow may never write Approved at all.

Repro: a glossary workflow whose reject edge sets status Rejected, with no rollback.

v0.4 Approved (reviewer)            ← walk stops here
v0.5 admin edit1 → task1 → rejected (status Rejected, content kept)
v0.8 admin adds synonym → task2
PR:   task2 preview = {description: Approved→Edit1, synonyms: +Alias}   base=0.4
main: task2 preview = {synonyms: +Alias}

Task 2 lists edit 1 again, even though it was already rejected.

Bot edits also come out differently depending on the workflow, because the result depends on where an Approved status happens to sit:

Workflow Bot edit in preview
Seeded glossary shown
Glossary workflow with no status writes hidden
Table workflow (no reviewers, so every Approved version counts) hidden

2. Bot edits stay out of the preview

Bot edits skip governance on purpose (isBotChange). The reviewer decides only on edits that started a run.

3. Rollback (pre-existing on main; fix it here so the preview and reject agree)

a. Reject does nothing on entities without reviewers (tables).

  • When reviewers is empty, ApprovedBaseline counts any version with status Approved, so the rejected edit's own version (status Approved carried over) becomes the rollback target.
  • Run: table Approved at v0.4, admin adds a tag (v0.6, status still Approved), reject → the tag stays and status is Approved.

b. Rejecting an edit on a term that was already Rejected keeps the edit.

  • Rollback looks only for Approved versions. It finds none, sets Rejected and keeps the content.
  • Run: new term rejected (v0.3, "Original definition"), admin edits it to "Edited definition", reject → status Rejected, "Edited definition" kept.

c. Rollback wipes bot edits.

  • It restores the whole entity to the last approved version, so bot edits that skipped review get reverted too.
  • Run: term Approved, ingestion bot edits the description, admin adds a synonym, reject → the description goes back to the pre-bot value.

Changes needed

Preview:

  • The starting point is the triggering edit's previous version, or the starting point stored on an open task it supersedes. No ApprovedBaseline and no status reads anywhere in the preview: not for opening a cycle, not as the fallback.
  • Tasks stored before this change, which have no stored starting point, fall back to the version before the latest change.
  • Leave out of the fold any version written by a bot that does not trigger this workflow.
  • Keep the rest: rebuilding from history at every task write, picking the oldest of several open prior tasks, the incomplete flag, and the notification warning.

Rollback:

  • A version counts as approved only when it records the approval itself: a status change to Approved, or the reviewer's own edit. An Approved status carried over from an earlier version never counts, whether or not the entity has reviewers.
  • Roll back to the last decision, approved or rejected, whichever is newer.
  • Revert only the fields the preview lists (governed changes since the starting point) to their starting values. Leave fields that only bots changed. If a bot and a user changed the same field, say how you handle it and test it.
  • With these, the card shows exactly what reject undoes, whatever the workflow's shape.

Tests (ITs, MySQL and Postgres):

  • Flip aBotEditDuringTheCycleIsInTheNextPreview and aBotEditBeforeTheCycleIsPreviewedAndRevertedOnRejection: the bot edit is not shown, and reject keeps it.
  • A workflow whose reject sets Rejected: task 2 does not list edit 1.
  • A table workflow with rollback: reject reverts the edit.
  • A term rejected, edited, then rejected again: rolls back to the rejected version.
  • A bot edit plus a user edit, then reject: the bot edit stays.
  • A bot and a user changing the same field.

Vamsi-klu commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for running through these workflows, Yan. The preview now starts from the triggering edit’s previous version or the oldest open task it replaces. Rejection uses that same history to restore the previous decision and undo the reviewed changes.

Bot-only edits stay in place. If both write the same field, rejection restores an earlier bot value and preserves a later bot write. If a history row is missing, the preview warns about the gap and shows the changes it can still undo.

All 209 focused unit tests passed. All 14 integration cases passed on both MySQL and PostgreSQL, including the custom Rejected workflow and the table without reviewers.

…eview-from-history

# Conflicts:
#	openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/WorkflowEventConsumer.java
@yan-3005

yan-3005 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

@Vamsi-klu thanks for the update. I reran everything on d07beaf.

Tests

  1. ApprovalTaskPreviewIT passes 14 of 14 on MySQL with ES and 14 of 14 on Postgres with OpenSearch.
  2. My 12 scenario probes pass. They cover the seeded glossary workflow, a workflow whose reject sets Rejected, a workflow with no status writes, table workflows with and without rollback, and consolidated edits.
  3. The existing approval ITs pass 31 of 31. That is ChangeRequestApplyIT, the three preview tests in WorkflowDefinitionResourceIT, GlossaryTermInheritedReviewerApprovalIT, GlossaryTermMoveApprovalIT and the five approval tests in MetricResourceIT.
  4. Unit tests pass 209 of 209.
  5. On a live server the second cycle no longer lists a rejected edit, reject on a table reverts the edit, a bot edit outside review survives a reject, and a term rejected twice goes back to its rejected version.

1. Bots listed in triggeringBots (blocking)

#38797 is merged on main and is already in this branch. A workflow can now list bots in triggeringBots, and an edit by such a bot starts that workflow. This PR still uses isHistoricalBotChange, which treats every bot as outside review. So when a listed bot edits the entity, the task opens with nothing in the preview and reject keeps the edit.

Live repro on d07beaf with a glossary workflow that lists a bot created by an admin, rolls back on reject, on an approved term:

v0.3 Approved   by reviewer          description Original definition
v0.4 Approved   by the listed bot    description Bot definition      (starts the run)
v0.5 In Review  workflow status write
task preview empty, base 0.3
after reject   v0.6 Approved, description still Bot definition

An edit by a bot that the running workflow lists in triggeringBots is under review, so it has to show in the preview and be undone on reject. Please use what #38797 added for this (GovernanceApprovalRegistry and changedByBot) instead of a separate bot rule. The ingestion bot cannot be used in the test because the schema does not allow system bots in triggeringBots, so use a bot created by an admin.

2. A failed history read leaves a 0 to 0 range and reject reverts nothing

This is the gitar finding and the code confirms it. CreateTask.cyclePreview records ReviewedRange(entityId, 0, 0, null) before reading the history. If the read throws, that placeholder stays. carriedApprovalBases skips ranges whose tip is 0, but RollbackEntityImpl.reviewedRange and ApprovalCycle.reviewedRange do not. Reject then undoes nothing and sets Rejected. Either ignore a range with tip 0 in rollback so it falls back to the legacy path, or do not record the placeholder. Please add a test for it.

3. Tasks opened before the upgrade (minor)

legacyReviewedRange covers only the triggering edit. For a chain of superseded tasks already open at upgrade time, reject undoes only the last edit. That is fine to keep, but please note it in the Consequences section of the ADR.

I have not run the scenario probes or the regression ITs on Postgres. Only ApprovalTaskPreviewIT ran on both databases.

@Vamsi-klu

Copy link
Copy Markdown
Contributor Author

@yan-3005 thank you for the thorough review and for running all those scenarios and live repros. I have addressed all three points in 5194276:

  1. Bots listed in triggeringBots: EventBasedEntityTrigger now passes changedByBot into the main workflow, and ApprovalCycleHistory.forWorkflow (called by CreateTask and RollbackEntityImpl) uses GovernanceApprovalRegistry.isTriggeringBotOfWorkflow and changedByBot to treat edits by listed triggering bots as under review. Workflow automation writes (governance-bot, including when writing on behalf of a listed bot) and unlisted bots stay outside review. Added unit tests in ApprovalCycleHistoryTest, RollbackEntityImplTest, and EventBasedEntityTriggerTest, plus two end-to-end tests in ApprovalTaskPreviewIT using an admin-created bot (covering preview and reject of a listed bot edit alongside an unlisted bot edit, a human edit superseding a listed bot edit, and removing the bot from triggeringBots while its task is open).
  2. Failed history read and placeholder 0..0 range: CreateTask.cyclePreview now clears the reviewed range with ApprovalCycle.clearReviewedRange before reading history instead of writing a 0..0 placeholder, and ApprovalCycle.rangeFor ignores any range with tip <= 0 so rollback falls back to legacyReviewedRange or the legacy approved-version rollback. Added regression tests in ApprovalCycleTest, CreateTaskTest, and RollbackEntityImplTest.
  3. Tasks opened before the upgrade: Added a note under the Consequences section of docs/decisions/2026-11-27-approval-rejection-restores-the-reviewed-edit.md documenting that a chain of superseded tasks already open at upgrade time falls back to legacyReviewedRange and undoes only the last triggering edit.

Verified locally:

  • Unit tests: 380 of 380 passing across 11 classes (ApprovalCycleTest, ApprovalCycleHistoryTest, ChangePreviewUtilsTest, CreateTaskTest, CreateTaskLifecycleMoveTest, RollbackEntityImplTest, EventBasedEntityTriggerTest, FilterEntityImplTest, WorkflowEventConsumerTest, GovernanceApprovalRegistryTest, TriggeringChangeTest).
  • Integration tests: ApprovalTaskPreviewIT passed 16 of 16 on MySQL with Elasticsearch.
  • mvn spotless:check and decision-record checks are clean.

Ready for another look whenever you have a moment.

Copy link
Copy Markdown
Contributor Author

I checked the required backend failure on 5194276. The batch and approval tests passed all 391 cases together, both serially and concurrently. I reproduced the seven CI failures by running PipelineObservabilityRuntimeTest just before BatchParallelismTest. The pipeline fixture leaves a null repository entry in the shared JVM, which the batch tests then hit during cleanup. The required check is still red and needs a maintainer to address that fixture and rerun it. Backend job

@yan-3005

yan-3005 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

@Vamsi-klu thanks for the last round. I checked 5194276 and the branch update on top of it. The behaviour matches the decision records, the ITs pass on MySQL and Postgres, and the live checks for listed triggering bots pass as well. A few things are left.

Docs

  1. The rollback node description in openmetadata-spec/.../automatedTask/rollbackEntityTask.json and the UI copy in governanceSchemas/automatedTask/rollbackEntityTask.json still say the node always rolls back to the most recent Approved status. Inside an approval flow it now undoes only the reviewed changes and restores the last recorded decision, so could you update that text? It shows up in the workflow builder.
  2. In 2026-11-27-approval-rejection-restores-the-reviewed-edit.md, decision 2 refers to the workflow bot bypass rule but does not say that an edit by a bot listed in triggeringBots counts as reviewed. Could you state that and cite ADR:2026-11-26-a-workflow-lists-the-bots-whose-changes-start-it?
  3. In the superseded 2026-11-26-an-approval-preview-lists-the-change-since-its-cycle-began.md, the deciders line still says agreement from me is pending, and the guard list still names VersionDiffTest, which no longer exists. Please drop both. On the 2026-11-27 record you can add me under deciders.

Gitar finding on prior task ranges

Please take a look at the open Gitar finding in #38857 (comment) and fix it if you agree it is relevant. From the code it looks real to me. WorkflowHandler.reviewedApprovalRange calls TaskService.getVariable, which can throw a Flowable exception if the prior task completes between the query and the read. previewOrFallback does not catch that, so the new approval task would not open. Corrected: skipping the unreadable prior range is not safe. ApprovalCycle.baseVersion takes the min over the carried bases, so dropping one moves the base forward. The preview then leaves out that task's edits while still reporting complete, and the recorded range that reject undoes shrinks with it. Please add FlowableException to the previewOrFallback catch instead, so the task opens with proposedChangesIncomplete as the ADR states, and add a test where reviewedApprovalRange throws.

Screenshots

If it is feasible, could you add as many screenshots as you can to the PR description, covering the scenarios this PR changes? For example:

  1. The Proposed Changes card for an edit by a bot listed in triggeringBots, and the entity after that task is rejected.
  2. The card after a bot edit outside review, and the entity after a reject showing the bot edit kept.
  3. A second cycle on a workflow whose reject sets Rejected, showing the earlier rejected edit is not listed again.
  4. A table workflow with rollback, before and after the reject.
  5. A term rejected at create, then edited and rejected again.
  6. An edit taken back within the cycle, and two quick edits consolidated into one version.
  7. The incomplete history warning on the task card and in the task created notification.

It would make the review much easier.

Copy link
Copy Markdown
Contributor Author

Thanks, @yan-3005. I updated the workflow builder and both decision records so they describe what rejection restores and which listed bot edits it covers.

@gitar-bot

gitar-bot Bot commented Dec 1, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk 4 closed / 4 findings

Approval rejection now reconstructs and patches entity fields from version history, so a faulty reviewed-range diff could restore or erase metadata.

Approval task previews now list every change since the approval cycle began, recomputed from version history on each task write, with the open-findings list empty. Resolved this session: failed history reads now abort task creation instead of leaving a 0..0 range, comparison fallback no longer reports inherited owners/reviewers as removed, and Flowable read failures for a prior task's range no longer abort task creation.

✅ 4 closed
✅ Bug: Failed history read now aborts approval task creation

📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/CreateTask.java:1328-1342 📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/util/ChangePreviewUtils.java:301-314 📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/util/ApprovedBaseline.java:37-40
The old buildProposedChangesPayload caught every exception and kept the existing payload. ChangePreviewUtils.previewOrUnchanged still has the comment "A preview the task cannot show must not keep the approval task from being created", but that guarantee no longer holds.

The cycle preview is now computed in CreateTask.cyclePreview (lines 1342-1361). That method runs repository.find, TriggeringChange.baseVersion, the approvedBaseline walk (which calls EntityStatusAdapter.forEntityType, SubjectContext.getSubjectContext) and history.changesSince. None of this runs inside previewOrUnchanged, and the previewOrUnchanged catch now only handles JsonParsingException.

So any other runtime failure while reading history reaches the catch (Exception exc) in notify and becomes a BpmnError, and the workflow fails without opening an approval task. Examples: an IllegalArgumentException from EntityStatusAdapter.forEntityType for an entity class that doesn't declare getEntityStatus (the erased return type is Enum, which isEnum() rejects), an EntityNotFoundException from find if the entity is deleted mid-run, or a transient DB error. The preview used to be best-effort and is now a hard dependency of task creation.

Fix: compute the CyclePreview inside the guarded path, e.g. make withCyclePreview take a Supplier<CyclePreview> that previewOrUnchanged invokes. Then catch the specific exceptions the history read can throw (EntityNotFoundException, IllegalArgumentException, JDBI/DB exceptions), log them and keep the existing payload.

✅ Bug: Comparison fallback reports inherited owners/reviewers as removed

📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/util/VersionDiff.java:54-67 📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/util/ApprovalCycleHistory.java:154-162
The fallback in netChange diffs two rows that are built differently. The base row comes from entity_extension. That row is the updater's original, which EntityRepository loads with setFieldsInternal and then setInheritedFields, so it holds the owners, reviewers and domains the term inherits from its glossary or parent, each marked inherited: true. The current version normally has no extension row. For it, EntityRepository.getVersion returns setFieldsInternal(find(id, ALL), putFields) and never calls setInheritedFields.

VersionDiff.reviewedFields only strips bookkeeping fields and derived tags. So when a term's reviewers come from its glossary, a cycle that falls back to the comparison (a missing row, or more than 200 versions) shows those inherited reviewers and owners as removed. The reviewer sees removals that nobody made.

The new IT doesn't catch this because approvedTerm puts reviewers on the term itself and gives the glossary no owners, reviewers or domains.

Fix: drop inherited references from both sides in reviewedFields, or load both versions through the same path so inheritance is applied the same way. Add a VersionDiffTest case where the base has an inherited reviewer and the current version has none.

✅ Bug: Failed history read leaves a 0..0 range, so reject reverts nothing

📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/CreateTask.java:1337-1351 📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/nodes/automatedTask/impl/RollbackEntityImpl.java:106-113 📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/nodes/automatedTask/impl/RollbackEntityImpl.java:143-157 📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/util/ApprovalCycle.java:61-75
cyclePreview stores a placeholder ReviewedRange(entityId, 0, 0, null) before it reads the history. If currentVersion, previousVersion or changesSince then throws, ChangePreviewUtils.previewOrFallback catches the error (JsonParsingException/EntityNotFoundException/IllegalArgumentException/JdbiException) and the task still opens, but the placeholder stays as the node and global range.

When the reviewer rejects, RollbackEntityImpl.reviewedRange → ApprovalCycle.reviewedRange returns that placeholder. Nothing there filters tip() > 0, so neither legacyReviewedRange nor the old applyRejection rollback runs. rejectReviewedChanges then undoes only versions with version <= 0, which is none, and sets the status to Rejected through priorDecision(…, 0). The rejected term keeps every unreviewed edit. carriedApprovalBases already treats tip == 0 as "no range", but the rollback path doesn't.

Fix: have rangeFor/reviewedRange ignore placeholder ranges (tip() > 0) so rejection falls back to the legacy or approved-version rollback. Or clear the variable instead of writing a 0..0 range.

✅ Bug: Flowable read failure for a prior task's range still aborts task creation

📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/CreateTask.java:1336 📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/CreateTask.java:1369-1380 📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/WorkflowHandler.java:1310-1322 📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/util/ChangePreviewUtils.java:321-335
cyclePreview reads each superseded task's reviewed range through WorkflowHandler.reviewedApprovalRange (CreateTask.java:1369-1380). That method runs Flowable queries and then calls TaskService.getVariable (WorkflowHandler.java:1310-1322). Those calls fail with FlowableException or FlowableObjectNotFoundException, for example when the prior run's user task completes or is cancelled between the task query and the variable read, or when the engine's own persistence fails.

previewOrFallback only catches JsonParsingException | EntityNotFoundException | IllegalArgumentException | JdbiException (ChangePreviewUtils.java:326-329). A Flowable error therefore escapes to notify(), which turns it into a BpmnError, and the approval task is never created. The ADR says the opposite should happen: "If the read fails, the task opens with any carried changes and the incomplete flag." One more problem: clearReviewedRange has already run by this point (CreateTask.java:1336).

Fix: catch FlowableException for each prior task in carriedApprovalBases, log it, and skip that prior's range. Alternatively, add FlowableException to the exceptions previewOrFallback tolerates.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@yan-3005

yan-3005 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@Vamsi-klu thanks for the updates. The docs and the Flowable fallback look good to me.

One gentle reminder on the screenshots. When you get a chance, could you add before and after screenshots to the PR description, with main as the before and this branch as the after? Seeing the same scenario side by side would show that the fix works in the product, not only in the tests.

The scenarios from my earlier comment are a good list to cover, especially these:

  1. A second approval cycle on a glossary term, where main shows the stale preview from the earlier task.
  2. A bot edit outside review, where main reverts it on reject and this branch keeps it.
  3. An edit by a bot listed in triggeringBots, with the preview and the entity after reject.
  4. A table workflow with rollback, where main leaves the edit in place after reject.
  5. The incomplete history warning on the task card and in the task created notification.

Thanks again.

@Vamsi-klu

Copy link
Copy Markdown
Contributor Author

Thanks for the reminder, @yan-3005. I ran all five scenarios against live builds of main (df1fdcdc27e) and this branch (28f17d3fe48) and added side by side before and after screenshots to the PR description. They cover the second cycle stale preview, the bot edit outside review before and after reject, the triggeringBots preview and reject result, the table rollback on reject, and the incomplete history warning on both the task card and the task created email notification.

@yan-3005

yan-3005 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@Vamsi-klu thank you for the screenshots, and for working through all the rounds on this. I know it has been a lot of back and forth.

There is one last case I want to raise, and it only affects the incomplete history path. In scenario 5 the description edit is hidden from task 2 because its history row is missing, which is fine with the warning shown. Reading the reject path, though, undoReviewedChanges cannot undo that hidden version, and priorDecision then sets the status back to Approved. The term ends up Approved with an edit nobody reviewed. On main, the same reject restores the approved version. A cycle longer than 200 versions takes the same path, which can happen on tables that bots update often while a task stays open.

When the history is incomplete but the base version row is readable, could reject restore the fields that differ between the base and the current version, as main does? One IT that drops a version row in the middle of a cycle, rejects the task, and checks the edit is reverted would cover it.

This branch has not been deployed

No deployments
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.

Approval task "Proposed Changes" shows a stale diff for glossary terms and omits the edited fields for metrics

3 participants