diff --git a/docs/decisions/2026-10-22-agent-glossary-proposals-are-decided-through-the-approval-workflow.md b/docs/decisions/2026-10-22-agent-glossary-proposals-are-decided-through-the-approval-workflow.md index 43034e2dd0f2..ba4dc883109a 100644 --- a/docs/decisions/2026-10-22-agent-glossary-proposals-are-decided-through-the-approval-workflow.md +++ b/docs/decisions/2026-10-22-agent-glossary-proposals-are-decided-through-the-approval-workflow.md @@ -1,7 +1,7 @@ # Agents' glossary-term proposals are decided through the approval workflow - **Status:** Accepted -- **Revisions:** v1 2026-10-22 (initial) · v2 2026-10-23 (a proposal branch after the start; lifecycles ask for an approval) +- **Revisions:** v1 2026-10-22 (initial) · v2 2026-10-23 (a proposal branch after the start; lifecycles ask for an approval) · v3 2026-11-25 (a sole editor no longer keeps their own approval) - **Deciders:** Pere Miquel Brull - **Guard:** `GlossaryTermAutomationDraftIT`, `JSONLogicSearchClassBase.test.ts`, Collate `LifecycleWorkflow.behavior.test.ts`, `WorkflowEventConsumerTest`, `GlossaryApprovalWorkflowReviewTest`, `GlossaryAutomationReviewMigrationTest`, `GlossaryTermRepositoryStageDecisionTest`, `AutomationProposalsTest`, `ContextMemoryDerivationIT`, `useGlossaryProposals.test.tsx`, `ProposalCard.test.tsx`, `GlossaryAiGeneratedTerm.spec.ts` - **Related:** ADR:2026-10-19-memories-become-draft-glossary-terms-through-the-ai-provider @@ -91,3 +91,11 @@ A reviewer's own edit still approves a proposal, as it approves any term: the br term nobody can be assigned is approved as before (v1's admin fallback on them, and its consequence for reviewers that are teams without members, is withdrawn), and the migration no longer touches them. + +## Amendment (v3, 2026-11-25) + +- **A sole reviewer or owner who made the edit no longer keeps it.** v1's "a sole one keeps it" is + withdrawn: the editor is left off the assignees even when nobody else remains, and the step's + empty-assignee strategy decides, as it does when no approver resolves at all. A task kept by its + editor was filed by them and could not be resolved by them. See + ADR:2026-11-25-an-approval-never-goes-to-its-requester. diff --git a/docs/decisions/2026-11-25-an-approval-never-goes-to-its-requester.md b/docs/decisions/2026-11-25-an-approval-never-goes-to-its-requester.md new file mode 100644 index 000000000000..d9fe357783f5 --- /dev/null +++ b/docs/decisions/2026-11-25-an-approval-never-goes-to-its-requester.md @@ -0,0 +1,44 @@ +# An approval never goes to its requester + +- **Status:** Accepted +- **Revisions:** v1 2026-11-25 (initial) +- **Deciders:** Ram Narayan Balaji +- **Guard:** `WorkflowDefinitionResourceIT.test_editorWhoIsTheOnlyApproverIsNeverAskedToApprove`, + `WorkflowDefinitionResourceIT.test_editorIsLeftOffTheApprovalWhenSomeoneElseCanApprove`, + `SetApprovalAssigneesImplTest.testSelfApprovalPrevention_eventDrivenSoleRequester_*` +- **Related:** ADR:2026-11-12-approval-threshold-never-exceeds-eligible-voters; + amends ADR:2026-10-22-agent-glossary-proposals-are-decided-through-the-approval-workflow + (withdraws its "a sole one keeps it" consequence) + +## Context + +An approval node resolves its assignees from the entity's owners, reviewers and named candidates, +then removes the requester, the user whose edit started the run. For workflows not managed by a +task workflow, an emptied list was given back to the requester when the node's empty-assignee +strategy was `none`, to keep the task "actionable". It was not actionable: the task is filed by the +requester, and `TaskAuthorPolicy` denies a task's filer `ResolveTask`. The requester was the only +assignee and could not approve, so the run waited until an admin, who bypasses the policy, found +and resolved a task assigned to someone else. This hit any workflow whose approval node kept the +default strategy, for example a reviewers-only approval of a data contract edited by its only +reviewer. + +## Decision + +The requester is never an assignee of an approval their own edit started, in any workflow and +under any empty-assignee strategy. When removing the requester leaves no one, the node's strategy +decides: + +- `none` approves automatically, as it does when no approver resolves at all; +- `assignAdmins` assigns the platform admins other than the requester; +- `wait` opens the task with no assignee. + +## Consequences + +A workflow that must never approve an edit on its own when the editor is the only approver +configures `assignAdmins` or `wait`; lifecycle playbooks and the data access request workflow +already do. Under `none`, an edit by an entity's only approver is approved without review, which is +the documented meaning of `none`. Revisit only if `none` itself should stop approving automatically. + +On upgrade, an existing workflow under `none` stops opening these tasks: an edit by the entity's +only approver, which used to wait for an admin to step in, is approved automatically. A workflow +that relied on that wait switches the node to `wait` or `assignAdmins`. diff --git a/openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/WorkflowDefinitionResourceIT.java b/openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/WorkflowDefinitionResourceIT.java index 660fa8251703..b8dd1fa60845 100644 --- a/openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/WorkflowDefinitionResourceIT.java +++ b/openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/WorkflowDefinitionResourceIT.java @@ -85,6 +85,9 @@ import org.junit.jupiter.api.parallel.Execution; import org.junit.jupiter.api.parallel.ExecutionMode; import org.junit.jupiter.api.parallel.Isolated; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.junitpioneer.jupiter.RetryingTest; import org.openmetadata.it.bootstrap.SharedEntities; import org.openmetadata.it.factories.DatabaseSchemaTestFactory; @@ -104,6 +107,7 @@ import org.openmetadata.schema.api.data.CreateChart; import org.openmetadata.schema.api.data.CreateDashboard; import org.openmetadata.schema.api.data.CreateDashboardDataModel; +import org.openmetadata.schema.api.data.CreateDataContract; import org.openmetadata.schema.api.data.CreateDatabase; import org.openmetadata.schema.api.data.CreateDatabaseSchema; import org.openmetadata.schema.api.data.CreateGlossary; @@ -134,6 +138,7 @@ import org.openmetadata.schema.entity.data.APIEndpoint; import org.openmetadata.schema.entity.data.Chart; import org.openmetadata.schema.entity.data.Dashboard; +import org.openmetadata.schema.entity.data.DataContract; import org.openmetadata.schema.entity.data.Database; import org.openmetadata.schema.entity.data.DatabaseSchema; import org.openmetadata.schema.entity.data.Glossary; @@ -159,6 +164,7 @@ import org.openmetadata.schema.governance.workflows.AutomaticApprovalReason; import org.openmetadata.schema.governance.workflows.WorkflowDefinition; import org.openmetadata.schema.governance.workflows.WorkflowInstance; +import org.openmetadata.schema.governance.workflows.elements.nodes.userTask.Assignees__1.EmptyAssigneeStrategy; import org.openmetadata.schema.services.connections.api.OpenAPISchemaURL; import org.openmetadata.schema.services.connections.api.RestConnection; import org.openmetadata.schema.services.connections.database.MysqlConnection; @@ -18436,4 +18442,197 @@ void test_onlyTheAssigneesDecideAWorkflowApproval(TestNamespace ns) throws Excep .resolve(task.getId().toString(), approve); awaitApprovedApprovalTask(client, tag.getFullyQualifiedName()); } + + /** Who an approval node asks: the contract's owners, its reviewers, or both. */ + private enum ApproverSource { + OWNERS(true, false), + REVIEWERS(false, true), + OWNERS_AND_REVIEWERS(true, true); + + private final boolean addOwners; + private final boolean addReviewers; + + ApproverSource(boolean addOwners, boolean addReviewers) { + this.addOwners = addOwners; + this.addReviewers = addReviewers; + } + } + + private static Stream approverSourcesAndEmptyAssigneeStrategies() { + return Stream.of(ApproverSource.values()) + .flatMap( + source -> + Stream.of(EmptyAssigneeStrategy.values()) + .map(strategy -> Arguments.of(source, strategy))); + } + + @ParameterizedTest(name = "{0} / {1}") + @MethodSource("approverSourcesAndEmptyAssigneeStrategies") + void test_editorWhoIsTheOnlyApproverIsNeverAskedToApprove( + ApproverSource source, EmptyAssigneeStrategy strategy, TestNamespace ns) throws Exception { + OpenMetadataClient admin = SdkClients.adminClient(); + User steward = createPlainUser(admin, "steward"); + // The steward owns and reviews the contract, so every source resolves to the steward alone. + DataContract contract = + createContract( + ns, List.of(steward.getEntityReference()), List.of(steward.getEntityReference())); + String workflowName = createContractApprovalWorkflow(contract, source, strategy); + + editDescriptionAs(steward, contract); + + switch (strategy) { + case NONE -> { + // Nobody else can approve, so the node approves instead of asking the steward. + JsonNode instance = awaitOnlyInstanceEnded(admin, workflowName); + assertEquals( + WorkflowInstance.WorkflowStatus.FINISHED.value(), + instance.path("status").asText(), + instance.toString()); + assertTrue( + listOpenApprovalTasks(admin, contract.getFullyQualifiedName()).getData().isEmpty(), + "no approval task may be opened for the steward's own edit"); + } + case ASSIGN_ADMINS -> { + UUID adminId = admin.users().getByName("admin").getId(); + Task task = + awaitOpenApprovalTaskAssignedTo(admin, contract.getFullyQualifiedName(), adminId); + assertFalse(assigneeNames(task).contains(steward.getName()), assigneeNames(task)::toString); + } + case WAIT -> { + Task task = awaitOpenApprovalTask(admin, contract.getFullyQualifiedName()); + assertTrue(assigneeNames(task).isEmpty(), assigneeNames(task)::toString); + } + } + } + + @ParameterizedTest(name = "{0} / {1}") + @MethodSource("approverSourcesAndEmptyAssigneeStrategies") + void test_editorIsLeftOffTheApprovalWhenSomeoneElseCanApprove( + ApproverSource source, EmptyAssigneeStrategy strategy, TestNamespace ns) throws Exception { + OpenMetadataClient admin = SdkClients.adminClient(); + User steward = createPlainUser(admin, "steward"); + User colleague = createPlainUser(admin, "colleague"); + EntityReference stewardRef = steward.getEntityReference(); + EntityReference colleagueRef = colleague.getEntityReference(); + // The steward stays an owner so they may edit; the colleague is reachable through each source. + List owners = + source == ApproverSource.REVIEWERS + ? List.of(stewardRef) + : List.of(stewardRef, colleagueRef); + List reviewers = + source == ApproverSource.OWNERS ? List.of() : List.of(stewardRef, colleagueRef); + DataContract contract = createContract(ns, owners, reviewers); + createContractApprovalWorkflow(contract, source, strategy); + + editDescriptionAs(steward, contract); + + Task task = + awaitOpenApprovalTaskAssignedTo(admin, contract.getFullyQualifiedName(), colleague.getId()); + assertEquals(Set.of(colleague.getName()), assigneeNames(task)); + } + + private static User createPlainUser(OpenMetadataClient admin, String role) { + String name = "%s_%s".formatted(role, UUID.randomUUID().toString().substring(0, 8)); + return admin + .users() + .create( + new CreateUser() + .withName(name) + .withEmail(name + "@example.com") + .withPassword("password123")); + } + + private static DataContract createContract( + TestNamespace ns, List owners, List reviewers) { + DatabaseSchema schema = DatabaseSchemaTestFactory.createSimple(ns); + Table table = TableTestFactory.createSimple(ns, schema.getFullyQualifiedName()); + return SdkClients.adminClient() + .dataContracts() + .create( + new CreateDataContract() + .withName("contract_" + UUID.randomUUID().toString().substring(0, 8)) + .withDescription("initial") + .withEntity(table.getEntityReference()) + .withOwners(owners) + .withReviewers(reviewers)); + } + + private String createContractApprovalWorkflow( + DataContract contract, ApproverSource source, EmptyAssigneeStrategy strategy) + throws Exception { + ensureWorkflowEventConsumerIsActive(SdkClients.adminClient()); + String workflowName = "editorApproval" + UUID.randomUUID().toString().substring(0, 8); + String onlyThisContract = + "{\"!=\":[{\"var\":\"fullyQualifiedName\"},\"%s\"]}" + .formatted(contract.getFullyQualifiedName()); + String json = + """ + { + "name": "%s", + "description": "Approval of data contract edits", + "trigger": { + "type": "eventBasedEntity", + "config": { + "entityTypes": ["dataContract"], + "events": ["Updated"], + "exclude": ["reviewers"], + "filter": %s + }, + "output": ["relatedEntity", "updatedBy"] + }, + "nodes": [ + {"type": "startEvent", "subType": "startEvent", "name": "StartNode"}, + {"type": "endEvent", "subType": "endEvent", "name": "EndNode"}, + { + "type": "userTask", + "subType": "userApprovalTask", + "name": "EditApproval", + "config": { + "assignees": { + "addOwners": %s, + "addReviewers": %s, + "candidates": [], + "emptyAssigneeStrategy": "%s" + }, + "approvalThreshold": 1, + "rejectionThreshold": 1 + }, + "input": ["relatedEntity"], + "inputNamespaceMap": {"relatedEntity": "global"}, + "output": ["updatedBy"], + "branches": ["true", "false"] + } + ], + "edges": [ + {"from": "StartNode", "to": "EditApproval"}, + {"from": "EditApproval", "to": "EndNode", "condition": "approve"}, + {"from": "EditApproval", "to": "EndNode", "condition": "reject"} + ] + } + """ + .formatted( + workflowName, + JsonUtils.pojoToJson(Map.of("dataContract", onlyThisContract)), + source.addOwners, + source.addReviewers, + strategy.value()); + createWorkflow((ObjectNode) MAPPER.readTree(json), workflowName); + return workflowName; + } + + private static void editDescriptionAs(User editor, DataContract contract) throws Exception { + SdkClients.createClient(editor.getName(), editor.getEmail(), new String[] {}) + .dataContracts() + .patch( + contract.getId().toString(), + MAPPER.readTree( + "[{\"op\":\"replace\",\"path\":\"/description\",\"value\":\"edited by %s\"}]" + .formatted(editor.getName()))); + } + + private static Set assigneeNames(Task task) { + return listOrEmpty(task.getAssignees()).stream() + .map(EntityReference::getName) + .collect(Collectors.toSet()); + } } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/impl/SetApprovalAssigneesImpl.java b/openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/impl/SetApprovalAssigneesImpl.java index 598fd42ac5ab..d4549d9a9d27 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/impl/SetApprovalAssigneesImpl.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/impl/SetApprovalAssigneesImpl.java @@ -37,7 +37,6 @@ import org.openmetadata.schema.utils.ResultList; import org.openmetadata.service.Entity; import org.openmetadata.service.exception.EntityNotFoundException; -import org.openmetadata.service.governance.approval.ChangeRequestRun; import org.openmetadata.service.governance.workflows.WorkflowVariableHandler; import org.openmetadata.service.governance.workflows.WorkflowVariableHandler.InputNamespaces; import org.openmetadata.service.jdbi3.EntityRepository; @@ -209,11 +208,11 @@ && cascadesOwners(assigneesConfig)) { // (DAR, GlossaryApproval, RequestApproval) publish the requester as `taskUpdatedBy`; entity // workflows (glossary term / tag approval, certification changes, …) publish it as the // global `updatedBy`. Both are checked because each variable is authoritative for its own - // workflow family — reading only one silently leaves the other's requester on the list. A - // non-workflow-managed task under the "none" strategy keeps the requester when no one else is - // available, so the task stays actionable; "assignAdmins" and "wait" have a fallback of their - // own below, and workflow-managed tasks rely on it too. A change request is never given back - // to its requester. + // workflow family — reading only one silently leaves the other's requester on the list. The + // requester is never given back their own approval, even when no one else is left: the task + // would be filed by them, and TaskAuthorPolicy denies a filer ResolveTask, so only an admin + // could act on it. An emptied list goes to the empty-assignee strategy below instead. + // ADR:2026-11-25-an-approval-never-goes-to-its-requester // A stored definition may carry the key with a null value; it means the default, none. final EmptyAssigneeStrategy emptyAssigneeStrategy = Optional.ofNullable(assigneesConfig.get("emptyAssigneeStrategy")) @@ -221,16 +220,7 @@ && cascadesOwners(assigneesConfig)) { .map(EmptyAssigneeStrategy::fromValue) .orElse(NONE); final boolean assignAdmins = emptyAssigneeStrategy == ASSIGN_ADMINS; - List preRemovalAssignees = new ArrayList<>(assigneeList); - boolean removedRequester = assigneeList.removeAll(requesterEntityLinks); - boolean reviewsChangeRequest = ChangeRequestRun.from(varHandler).isPresent(); - if (removedRequester - && assigneeList.isEmpty() - && !workflowManagedTask - && !reviewsChangeRequest - && emptyAssigneeStrategy == NONE) { - assigneeList.addAll(preRemovalAssignees); - } + assigneeList.removeAll(requesterEntityLinks); // Empty-assignee strategy: when nothing resolved (no reviewers/owners, or the only // assignee was the requester and was stripped above), apply the node's configured diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/impl/SetApprovalAssigneesImplTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/impl/SetApprovalAssigneesImplTest.java index eed5d1916b69..24326347c69f 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/impl/SetApprovalAssigneesImplTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/impl/SetApprovalAssigneesImplTest.java @@ -443,9 +443,9 @@ void testSelfApprovalPrevention_workflowManagedTaskRemovesCreatorAndLeavesTaskUn } @Test - void testSelfApprovalPrevention_eventDrivenSoleRequester_keptWhenNoOneElse() { - // Event-driven approval (not workflow-managed, not a change request): the only reviewer is the - // requester, who is kept so the task stays actionable. + void testSelfApprovalPrevention_eventDrivenSoleRequester_neverAssignedAndAutoApproved() { + // Event-driven approval whose only reviewer is the requester: the requester is never their own + // approver (as filer they could not resolve it), so under "none" the node approves. EntityReference creatorRef = new EntityReference().withType("user").withFullyQualifiedName("alice"); @@ -456,9 +456,27 @@ void testSelfApprovalPrevention_eventDrivenSoleRequester_keptWhenNoOneElse() { delegate.execute(execution); + assertEquals("[]", capturedVars.get("ApprovalTask_assignees")); + assertFalse((Boolean) capturedVars.get("hasAssignees")); + } + + @Test + void testSelfApprovalPrevention_eventDrivenSoleRequester_routedToOtherAdmins() { + EntityReference creatorRef = + new EntityReference().withType("user").withFullyQualifiedName("alice"); + when(mockEntity.getReviewers()).thenReturn(List.of(creatorRef)); + when(execution.getVariable("global_updatedBy")).thenReturn("alice"); + givenAdmins("alice", "platform_admin"); + when(assigneesExpr.getValue(execution)) + .thenReturn( + "{\"addReviewers\":true,\"addOwners\":false,\"users\":[],\"teams\":[],\"emptyAssigneeStrategy\":\"assignAdmins\"}"); + + delegate.execute(execution); + String assigneesJson = (String) capturedVars.get("ApprovalTask_assignees"); - assertNotNull(assigneesJson); - assertTrue(assigneesJson.contains("alice"), "sole requester is kept outside change requests"); + assertTrue(assigneesJson.contains("platform_admin"), assigneesJson); + assertFalse(assigneesJson.contains("<#E::user::alice>"), assigneesJson); + assertTrue((Boolean) capturedVars.get("hasAssignees")); } @Test