Skip to content

fix(workflows): stop WorkflowDefinitionResourceIT approval flakes at the source - #36560

Merged
yan-3005 merged 2 commits into
mainfrom
yan-3005/failing-test-rca-fix
Oct 29, 2026
Merged

yan-3005 merged 2 commits into
mainfrom
yan-3005/failing-test-rca-fix

Conversation

@yan-3005

@yan-3005 yan-3005 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

No linked issue: this fixes two WorkflowDefinitionResourceIT tests that kept failing in the merge queue and on main (failures listed below). Both races are removed at the source. Neither fix adds a retry or a longer timeout around a race.

1. test_approvalOnlyWorkflowApprovesTheEntity: 409 Workflow resolution failed for task … on transition 'approve'

Failure: MySQL + ES, global-state (merge queue for #36488).

Root cause (product race, not test-only): CreateTask commits the Task row on its own JDBI connection before the Flowable command that creates the runtime user task (ACT_RU_TASK + customTaskId) commits. #31590 deliberately kept the create path synchronous, so a BpmnError still aborts the workflow when the persist fails. Any caller can list the open task and POST /resolve inside that window. Only metric and ontology approvals waited for the runtime task, so this domain approval skipped the wait. From the failing run's server log:

11:51:47,304 [CreateTask] Created Task entity: id='eb37ed8e-…'
11:51:47,316 [TaskWorkflowHandler] Resolving task: id='eb37ed8e-…'
11:51:47,322 [WorkflowVariable] Task not found for customTaskId='eb37ed8e-…'
POST /api/v1/tasks/eb37ed8e-…/resolve 409

The runtime task committed between transformToNodeVariables (miss) and the hasActiveRuntimeTask recheck (hit). That skipped the existing retryable "still preparing" branch and threw the generic, non-retryable 409 instead.

Fix (TaskWorkflowHandler.resolveWorkflowTask):

  • A non-terminal task whose workflow instance is still running, but whose runtime task Flowable can't see yet, now waits for that task using the existing bounded readiness budget (6 × 50 ms). The wait happens before anything is written to the workflow, because process variables (rejection comment, assignees) set on an invisible runtime task are silently dropped. If the task is still not visible when the wait runs out, the resolve is refused right there with the retryable 409, before any workflow write.
  • The strict metric/ontology semantics are unchanged. The direct-resolution fallback for tasks whose instance has ended is unchanged.
  • If the variable lookup still misses a runtime task that exists by the time the failure is classified, the caller now gets the retryable The workflow is still preparing task …; retry the resolution 409, not the generic one. Nothing has reached the workflow at that point, so a retry is safe.
  • Fast-path cost: one extra Flowable lookup only for tasks whose workflow instance is running.

Residual, stated honestly: if Flowable's commit trails the task row by more than 250 ms, the caller still gets a 409. It is now the correct, retryable one, and nothing has been written to the workflow. The observed lag was under 20 ms.

2. test_upsertOfGatedFieldIsHeldForApproval: glossaryTerm … changed while this change was being submitted; reload and retry

Failures (4 in 3 days, every engine):

Root cause (test race): the glossary has a reviewer (USER1) that the creator (admin) is not, so the term starts in Draft. The seeded GlossaryApprovalWorkflow then moves it to In Review on the next WorkflowEventConsumer tick, about 1 s after create, which bumps the version 0.1 → 0.2. The test's upsert goes out about 1 s after create, because waitForWorkflowDeployment has a fixed 1 s pollDelay. That puts it in phase with the consumer tick. When the workflow's write lands between the upsert staging its base version and ChangeRequestService.lockEntityAtBase, the gate correctly refuses it as a concurrent change. From the 10-29 log:

02:12:57,837 Created glossaryTerm 57cbfd63 (v0.1)
02:12:58,868 WorkflowEventConsumer - Triggering with signal: glossaryTerm-entityCreated
02:12:58,958 Updated glossaryTerm 57cbfd63 … with version check (expected: 0.1, actual: 0.2)
PUT /api/v1/glossaryTerms 409   (29 ms request ending ~02:12:58,987)

The 10-27 failure has the same sequence (14,481 create → 15,513 tick → 15,576 update → PUT 409).

Rejecting this upsert is consistent with the ungated path. A plain PUT reads original without a row lock and stores with original.getVersion(), so the same race gives it a 412.

Fix (test only): wait until the seeded review has moved the term to In Review. The term is quiet after that: the workflow is parked on its user task, and the gated upsert never persists, so it raises no new event. The test also now asserts on the gate workflow's own task (by workflowDefinitionId). Before, it matched any open task assigned to USER1, and the seeded review's task could satisfy that too.

Origin

Neither test runs in the parallel lane. WorkflowDefinitionResourceIT runs in the global-state lane with @Execution(SAME_THREAD).

Type of change:

  • Bug fix

High-level design:

N/A — small change.

Tests:

Use cases covered

  • Resolving a workflow approval task that is listed before its Flowable runtime task commits succeeds, instead of returning a 409.
  • A resolve whose variable lookup missed a runtime task that has since committed returns the retryable "still preparing" 409.
  • A gated upsert on a glossary term is held for approval once the term's seeded review has settled.

Unit tests

  • TaskWorkflowHandlerTest adds 3 tests:
    • testResolveWaitsForTheRuntimeTaskItsRunningWorkflowIsStillCommitting
    • testRuntimeTaskAppearingAfterAMissedLookupAsksTheCallerToRetry
    • testRejectionIsNotWrittenToARuntimeTaskThatNeverBecameVisible
  • RED before the fix: the first failed with the exact CI message, Workflow resolution failed for task '…' on transition 'approve'. The third failed with NeverWantedButInvoked: setProcessVariable.
  • GREEN after the fix: TaskWorkflowHandlerTest 23/0/0, DataAccessRequestWorkflowTest 6/0/0.

Backend integration tests

UI / Playwright

  • Not applicable.

🤖 Generated with Claude Code

…the source

test_approvalOnlyWorkflowApprovesTheEntity: CreateTask commits the task row on
its own JDBI connection before the Flowable command that creates the runtime
user task commits. A caller that lists the open task and resolves it inside
that window misses the runtime task; only metric and ontology approvals waited
for it. When the runtime task committed between the variable lookup and the
failure check, the resolve also surfaced the generic, non-retryable
"Workflow resolution failed" 409. Any non-terminal task whose workflow
instance is still running now waits (same bounded budget) for its runtime task
before anything is written to the workflow, and a lookup that missed a task
which exists by the time the failure is classified returns the retryable
"still preparing" 409.

test_upsertOfGatedFieldIsHeldForApproval: the term has a reviewer its creator
is not, so the seeded GlossaryApprovalWorkflow moves it from Draft to In Review
one WorkflowEventConsumer tick (~1s) after create. The test's upsert goes out
~1s after create (fixed deployment poll delay), so it regularly staged against
the pre-review version and was refused as a concurrent change. The test now
waits for In Review, after which the term is quiet, and asserts on the gate
workflow's own task instead of any task assigned to the reviewer.
@yan-3005
yan-3005 requested a review from a team as a code owner October 29, 2026 13:50
@yan-3005
yan-3005 requested review from manerow and a balanced review from Copilot October 29, 2026 13:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

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

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

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.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Oct 29, 2026
The readiness wait for a task still being committed ignored its result. On
timeout the resolve went on to set taskAssignees and the rejection reason on a
runtime task Flowable could not see, which WorkflowHandler.setProcessVariable
drops with only a warning; if the task committed before the variable lookup,
the workflow was resolved without them. Refuse with the retryable "still
preparing" conflict before any workflow write instead.
Copilot AI balanced review requested due to automatic review settings October 29, 2026 14:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@gitar-bot

gitar-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 closed / 1 findings

🟡 Medium risk · Changing workflow resolution to wait for Flowable runtime tasks and return retryable conflicts could delay approvals when tasks remain unavailable.

Stops the WorkflowDefinitionResourceIT approval flakes at the source by making resolveWorkflowTask wait for a not-yet-visible Flowable runtime task before writing to the workflow, and by having the glossary upsert test wait for the seeded review to settle. The readiness wait result is now checked, so workflow writes no longer go to a missing task, addressing that finding. No open issues found.

✅ 1 closed
✅ Edge Case: Readiness wait result ignored; workflow writes still go to a missing task

📄 openmetadata-service/src/main/java/org/openmetadata/service/tasks/TaskWorkflowHandler.java:283-287 📄 openmetadata-service/src/main/java/org/openmetadata/service/tasks/TaskWorkflowHandler.java:319-333 📄 openmetadata-service/src/main/java/org/openmetadata/service/tasks/TaskWorkflowHandler.java:339-340
The new block's comment says the code waits before anything is written to the workflow, because Flowable silently drops process variables set on a runtime task it can't see yet. awaitActiveRuntimeTask returns false when the 6 × 50 ms budget runs out, and the code ignores that. It goes on to call setProcessVariable for taskAssignees and then recordRejection. WorkflowHandler.setProcessVariable only logs a warning and drops the value when no Flowable task exists. If Flowable commits the runtime task between those calls and transformToNodeVariables, the workflow is resolved without the rejection reason, the rejecting user or the payload assignees, and no error is raised. This is the silent loss the comment says the wait prevents. Fail fast when the wait times out. The description already treats that case as the retryable 409, and at that point nothing has reached the workflow, so a retry is safe.

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 enabled auto-merge October 29, 2026 14:04
@sonika-shah
sonika-shah removed the request for review from manerow October 29, 2026 17:20
@yan-3005
yan-3005 added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit 5f76085 Oct 29, 2026
70 of 72 checks passed
@yan-3005
yan-3005 deleted the yan-3005/failing-test-rca-fix branch October 29, 2026 23:56
harshach added a commit that referenced this pull request Oct 30, 2026
Main moved to b194104, the squash merge of PR10, after #36560. The one
conflict was the endpoint count in docs/generated/api-reference.md, which both
PRs change. scripts/generate_api_reference.py regenerated the doc from the
merged sources. The users/generateToken row keeps main's text, because main's
committed doc already differs from its source there and this PR does not change
that endpoint.
manerow pushed a commit that referenced this pull request Oct 30, 2026
…the source (#36560)

* fix(workflows): stop WorkflowDefinitionResourceIT approval flakes at the source

test_approvalOnlyWorkflowApprovesTheEntity: CreateTask commits the task row on
its own JDBI connection before the Flowable command that creates the runtime
user task commits. A caller that lists the open task and resolves it inside
that window misses the runtime task; only metric and ontology approvals waited
for it. When the runtime task committed between the variable lookup and the
failure check, the resolve also surfaced the generic, non-retryable
"Workflow resolution failed" 409. Any non-terminal task whose workflow
instance is still running now waits (same bounded budget) for its runtime task
before anything is written to the workflow, and a lookup that missed a task
which exists by the time the failure is classified returns the retryable
"still preparing" 409.

test_upsertOfGatedFieldIsHeldForApproval: the term has a reviewer its creator
is not, so the seeded GlossaryApprovalWorkflow moves it from Draft to In Review
one WorkflowEventConsumer tick (~1s) after create. The test's upsert goes out
~1s after create (fixed deployment poll delay), so it regularly staged against
the pre-review version and was refused as a concurrent change. The test now
waits for In Review, after which the term is quiet, and asserts on the gate
workflow's own task instead of any task assigned to the reviewer.

* fix(workflows): refuse a resolve whose runtime task never became visible

The readiness wait for a task still being committed ignored its result. On
timeout the resolve went on to set taskAssignees and the rejection reason on a
runtime task Flowable could not see, which WorkflowHandler.setProcessVariable
drops with only a warning; if the task committed before the variable lookup,
the workflow was resolved without them. Refuse with the retryable "still
preparing" conflict before any workflow write instead.
@yan-3005 yan-3005 self-assigned this Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants