Skip to content

fix(governance): persist workflow task stage after Flowable commit to stop spurious 409 - #31590

Merged
yan-3005 merged 3 commits into
mainfrom
fix/dar-workflow-async-advance-namespacing
Aug 17, 2026
Merged

yan-3005 merged 3 commits into
mainfrom
fix/dar-workflow-async-advance-namespacing

Conversation

@yan-3005

@yan-3005 yan-3005 commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes

A /resolve for the next user-task transition can arrive while the workflow is still running an async automatedTask between two user tasks. The canonical case is Collate's DataAccessRequest workflow:

TaskReview --approve--> PolicyAgent (async automatedTask) --> ApprovedAccess --markAsGranted--> GrantedAccess

CreateTask.notify() runs as a Flowable TaskListener inside the command that creates the next runtime user task, but on the update path it persisted the entity's workflowStageId / availableTransitions via taskRepository.update(...) — which commits on JDBI's own connection mid-command, milliseconds before Flowable commits the ACT_RU_TASK row and the customTaskId process variable.

A client polling availableTransitions could therefore see the next transition (e.g. markAsGranted) advertised and resolve into a not-yet-committed runtime task: the resolve found no task, completed with no variables, and the outgoing gateway condition ${<node>_result == '<transition>'} evaluated an unbound variable → FlowableException → surfaced to the caller as a spurious 409 CONFLICT under concurrency.

Fix

  • Defer the update-path persist to a Flowable post-commit transaction listener (TransactionState.COMMITTED) so the entity's stage / availableTransitions are only advanced once the runtime task they advertise is durable.
  • This is non-blocking — the write is reordered, never waited on. No Thread.sleep, no polling, no thread blocked. COMMITTED listeners run synchronously inside the command's commit before a synchronous taskService.complete() returns, so synchronous stage advances (e.g. incident userTask→userTask) still reflect the new stage in their response. On rollback the listener never fires and the entity correctly keeps the prior stage.
  • The create path stays synchronous so a persist failure still aborts the workflow via BpmnError.
  • TaskWorkflowHandler.resolveWorkflowTask guards against a null namespace map (treats it as a failed resolve) so a genuinely stale resolve never completes a task with no variables.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How was this tested

  • CreateTaskPostCommitPersistTest — source-level regression guard that the update-path persist is deferred to a TransactionState.COMMITTED listener (not persisted inline), that it never blocks (Thread.sleep-free), and that the null-namespace guard is present.
  • Behavioural acceptance via the Collate DAR integration tests (DarStatusGroupIT, DataAccessRequestValidationIT, DataAccessRequestIT), which run the real PolicyAgent async node: the two CI-failing tests (darListEndpointMultiSelectStatus, testDarClose_onGranted_returns400) pass, and the full DAR suite is green across repeated concurrent runs.

Checklist

  • I have read the CONTRIBUTING document.
  • My PR title follows the repo conventions.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective.

🤖 Generated with Claude Code

Greptile Summary

The PR defers update-path task persistence until Flowable commits and prevents task completion with a null namespaced-variable map.

  • Registers task-entity updates on Flowable's committed transaction state.
  • Re-reads the latest task row before applying the deferred stage update.
  • Treats a missing runtime-task namespace as a failed workflow resolution.

Confidence Score: 4/5

The PR does not yet appear safe to merge because a terminal resolve can still update the task entity directly while its Flowable process is asynchronously advancing and has not materialized the next runtime task.

The null-map guard prevents completing a Flowable task without variables, but a null lookup also makes the active-task check false and leaves the existing terminal direct-resolution fallback reachable while the workflow may still be live.

Files Needing Attention: openmetadata-service/src/main/java/org/openmetadata/service/tasks/TaskWorkflowHandler.java

Important Files Changed

Filename Overview
openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/CreateTask.java Defers existing-task stage persistence to a Flowable committed-transaction listener while retaining synchronous creation behavior.
openmetadata-service/src/main/java/org/openmetadata/service/tasks/TaskWorkflowHandler.java Rejects null namespaced variables before invoking Flowable, but the previously reported terminal fallback remains reachable when no runtime task is visible.
openmetadata-service/src/test/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/CreateTaskPostCommitPersistTest.java Adds focused coverage for committed-listener registration, execution timing, fallback execution, and exception containment.

Sequence Diagram

sequenceDiagram
  participant Client
  participant TaskHandler as TaskWorkflowHandler
  participant Flowable
  participant Listener as CreateTask listener
  participant TaskDB as Task repository
  Client->>TaskHandler: Resolve transition
  TaskHandler->>Flowable: Complete current user task
  Flowable->>Listener: Create next user task
  Listener->>Flowable: Register COMMITTED callback
  Flowable->>Flowable: Commit runtime task and variables
  Flowable->>Listener: Run COMMITTED callback
  Listener->>TaskDB: Persist workflow stage and transitions
  Flowable-->>TaskHandler: Completion returns
Loading

Reviews (4): Last reviewed commit: "test(governance): make CreateTask post-c..." | Re-trigger Greptile

Context used:

@yan-3005
yan-3005 requested a review from a team as a code owner August 16, 2026 13:07
@yan-3005 yan-3005 added the To release Will cherry-pick this PR into the release branch label Aug 16, 2026
Copilot AI lite review requested due to automatic review settings August 16, 2026 13:07
@yan-3005 yan-3005 added the To release Will cherry-pick this PR into the release branch label Aug 16, 2026

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 reached their quota limit.

@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 Aug 16, 2026
@github-actions

github-actions Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit 37d026c8732a821a83e007bc5888dc68c65866ee in Playwright run 31958722269, attempt 1.

✅ 579 passed · ❌ 0 failed · 🟡 0 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 49m 45s

⏱️ Max setup 2m 57s · max shard execution 18m 36s · max shard-job elapsed before upload 21m 46s · reporting 4s

🌐 210.33 requests/attempt · 2.80 app boots/UI scenario · 2.87% common-shard skew

Optimization targets still in progress:

  • Browser traffic was 210.33 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.8 per UI scenario (1679 boots / 600 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard chromium-01 155 0 0 0 0 0
✅ Shard chromium-02 133 0 0 0 0 0
✅ Shard chromium-03 139 0 0 0 0 0
✅ Shard data-asset-rules-01 61 0 0 0 0 0
✅ Shard domain-isolation-01 14 0 0 0 0 0
✅ Shard global-state-01 34 0 0 0 0 0
✅ Shard ingestion-01 1 0 0 0 0 0
✅ Shard reindex-01 2 0 0 0 0 0
✅ Shard search-01 11 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

… stop spurious 409

A /resolve for the next user-task transition can arrive while the workflow is
still running an async automatedTask between two user tasks (e.g. Collate's
DataAccessRequest workflow: TaskReview --approve--> PolicyAgent(async) -->
ApprovedAccess --markAsGranted-->).

CreateTask.notify() runs as a Flowable TaskListener inside the command that
creates the next runtime user task, but on the update path it persisted the
entity's workflowStageId / availableTransitions via taskRepository.update(...),
which commits on JDBI's own connection mid-command — milliseconds before Flowable
commits the ACT_RU_TASK row and the customTaskId variable. A client polling
availableTransitions could see the next transition (e.g. markAsGranted) advertised
and resolve into a not-yet-committed runtime task: the resolve found no task,
completed with no variables, and the outgoing gateway condition
${<node>_result == '<transition>'} evaluated an unbound variable — a
FlowableException surfaced to the caller as a spurious 409 under concurrency.

Defer the update-path persist to a Flowable post-commit transaction listener
(TransactionState.COMMITTED) so the entity's stage/availableTransitions are only
advanced once the runtime task they advertise is durable. This is non-blocking:
the write is reordered, never waited on — no Thread.sleep, no polling, no thread
blocked. COMMITTED listeners run synchronously inside the command's commit before a
synchronous taskService.complete() returns, so synchronous stage advances still
reflect the new stage in their response; on rollback the listener never fires and
the entity correctly keeps the prior stage. The create path stays synchronous so a
persist failure still aborts the workflow via BpmnError.

Also guard resolveWorkflowTask against a null namespace map (treat as a failed
resolve) so a genuinely stale resolve never completes a task with no variables.

Verified against the Collate DAR integration tests (DarStatusGroupIT,
DataAccessRequestValidationIT, DataAccessRequestIT), which exercise the real
PolicyAgent async node: the two CI-failing tests pass and the full DAR suite is
green across repeated runs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 16, 2026 14:02
@yan-3005
yan-3005 force-pushed the fix/dar-workflow-async-advance-namespacing branch from 4d6bdc2 to a5371ce Compare August 16, 2026 14:02

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 reached their quota limit.

@yan-3005 yan-3005 changed the title fix(governance): wait for async workflow advance when namespacing resolve variables fix(governance): persist workflow task stage after Flowable commit to stop spurious 409 Aug 16, 2026
…le-version conflict

Address PR review: the deferred (post-commit) update-path persist used the task
snapshot read at the start of CreateTask.notify() as the update baseline. If the
stored task advanced between that read and the post-commit callback, updating
against the stale snapshot would fail the optimistic-version check and leave the
entity one stage behind the already-committed Flowable runtime. Re-read the
committed row inside the listener and update against it. On a hard persist failure
the entity self-heals on the next stage advance (which re-reads the current task).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 16, 2026 16:20

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 reached their quota limit.

@yan-3005

Copy link
Copy Markdown
Contributor Author

Addressing the review findings:

On the current commit (post-commit-listener approach):

  • Post-commit persist failure / stale baseline (gitar-bot, CreateTask.java) — fixed in 0671ad0a60: the deferred persist now re-reads the committed task row as the update baseline inside the COMMITTED listener, so a concurrent advance can't cause an optimistic-version conflict. On a genuine hard persist failure the entity is one stage behind the already-committed Flowable runtime and self-heals on the next stage advance (which re-reads the current task) — this is the inherent, documented trade-off of the JDBI↔Flowable datasource split, and is strictly safer than the prior ordering (entity leading the runtime).

  • CreateTaskPostCommitPersistTest asserts source text, not behaviour (gitar-bot) — intentional and consistent with the existing WorkflowHandlerLegacyThreadUpdateTest in the same package, which the repo uses precisely because a behavioural repro needs a live Flowable engine with a saturated async executor to force the race (flaky). The behavioural acceptance is the Collate DAR integration tests (DarStatusGroupIT, DataAccessRequestValidationIT, DataAccessRequestIT, which drive the real PolicyAgent async node) — green across 5/5 repeated concurrent runs locally, including the two previously-failing CI tests.

Stale (reviewed the earlier 4d6bdc2c39 commit): the findings about findUserTaskAwaitingAsyncAdvance / sleepQuietly / ASYNC_ADVANCE_MAX_WAIT_MS / the double 5s wait / WorkflowHandlerAsyncAdvanceTest reference a bounded-wait implementation that was replaced by the non-blocking post-commit-listener approach — that code no longer exists on the branch.

Address PR review: replace the source-text assertions with a behavioural test of
the ordering seam. Mock only the Flowable TransactionContext (framework boundary)
and assert the observable behaviour of registerPostCommitPersist: the persist does
not run inline, it is registered as a TransactionState.COMMITTED listener, it runs
exactly once when that listener fires, it runs inline when there is no active
transaction context, and a persist failure in the listener is contained (Flowable
has already committed — nothing to roll back). registerPostCommitPersist is now
package-private for the test. Full workflow behaviour remains covered by the
Collate DAR integration tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 16, 2026 16:28

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 reached their quota limit.

@yan-3005

Copy link
Copy Markdown
Contributor Author

Follow-up on the test finding: CreateTaskPostCommitPersistTest is now behavioural (37d026c) — it mocks only the Flowable TransactionContext (framework boundary) and asserts the observable ordering: the persist does not run inline, is registered as a TransactionState.COMMITTED listener, runs exactly once when that listener fires, runs inline when there is no transaction context, and a listener-side persist failure is contained. No more source-text assertions.

@yan-3005
yan-3005 added this pull request to the merge queue Aug 17, 2026
Merged via the queue into main with commit 08e2e7c Aug 17, 2026
109 of 111 checks passed
@yan-3005
yan-3005 deleted the fix/dar-workflow-async-advance-namespacing branch August 17, 2026 03:29
@github-actions

Copy link
Copy Markdown
Contributor

Changes have been cherry-picked to the 2.0 branch.

github-actions Bot pushed a commit that referenced this pull request Aug 17, 2026
… stop spurious 409 (#31590)

* fix(governance): persist workflow task stage after Flowable commit to stop spurious 409

A /resolve for the next user-task transition can arrive while the workflow is
still running an async automatedTask between two user tasks (e.g. Collate's
DataAccessRequest workflow: TaskReview --approve--> PolicyAgent(async) -->
ApprovedAccess --markAsGranted-->).

CreateTask.notify() runs as a Flowable TaskListener inside the command that
creates the next runtime user task, but on the update path it persisted the
entity's workflowStageId / availableTransitions via taskRepository.update(...),
which commits on JDBI's own connection mid-command — milliseconds before Flowable
commits the ACT_RU_TASK row and the customTaskId variable. A client polling
availableTransitions could see the next transition (e.g. markAsGranted) advertised
and resolve into a not-yet-committed runtime task: the resolve found no task,
completed with no variables, and the outgoing gateway condition
${<node>_result == '<transition>'} evaluated an unbound variable — a
FlowableException surfaced to the caller as a spurious 409 under concurrency.

Defer the update-path persist to a Flowable post-commit transaction listener
(TransactionState.COMMITTED) so the entity's stage/availableTransitions are only
advanced once the runtime task they advertise is durable. This is non-blocking:
the write is reordered, never waited on — no Thread.sleep, no polling, no thread
blocked. COMMITTED listeners run synchronously inside the command's commit before a
synchronous taskService.complete() returns, so synchronous stage advances still
reflect the new stage in their response; on rollback the listener never fires and
the entity correctly keeps the prior stage. The create path stays synchronous so a
persist failure still aborts the workflow via BpmnError.

Also guard resolveWorkflowTask against a null namespace map (treat as a failed
resolve) so a genuinely stale resolve never completes a task with no variables.

Verified against the Collate DAR integration tests (DarStatusGroupIT,
DataAccessRequestValidationIT, DataAccessRequestIT), which exercise the real
PolicyAgent async node: the two CI-failing tests pass and the full DAR suite is
green across repeated runs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(governance): re-read task before post-commit persist to avoid stale-version conflict

Address PR review: the deferred (post-commit) update-path persist used the task
snapshot read at the start of CreateTask.notify() as the update baseline. If the
stored task advanced between that read and the post-commit callback, updating
against the stale snapshot would fail the optimistic-version check and leave the
entity one stage behind the already-committed Flowable runtime. Re-read the
committed row inside the listener and update against it. On a hard persist failure
the entity self-heals on the next stage advance (which re-reads the current task).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(governance): make CreateTask post-commit persist test behavioural

Address PR review: replace the source-text assertions with a behavioural test of
the ordering seam. Mock only the Flowable TransactionContext (framework boundary)
and assert the observable behaviour of registerPostCommitPersist: the persist does
not run inline, it is registered as a TransactionState.COMMITTED listener, it runs
exactly once when that listener fires, it runs inline when there is no active
transaction context, and a persist failure in the listener is contained (Flowable
has already committed — nothing to roll back). registerPostCommitPersist is now
package-private for the test. Full workflow behaviour remains covered by the
Collate DAR integration tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
(cherry picked from commit 08e2e7c)
@github-actions

Copy link
Copy Markdown
Contributor

Failed to cherry-pick changes to the 1.13 branch.
Please cherry-pick the changes manually.
You can find more details here.

@gitar-bot

gitar-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 4 resolved / 4 findings

Defers update-path task stage persistence to a Flowable post-commit transaction listener and adds a null-namespace guard to resolve workflow tasks, addressing stale-version conflicts and spurious 409 errors. No open issues found.

✅ 4 resolved
✅ Performance: Interrupt turns bounded wait into a busy-loop hammering the DB

📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/WorkflowHandler.java:861-875
In findUserTaskAwaitingAsyncAdvance, sleepQuietly swallows InterruptedException and only re-sets the interrupt flag; the while loop does not check Thread.interrupted() and keeps iterating. Once the thread is interrupted, every subsequent Thread.sleep throws immediately, so the loop spins with no delay — firing getTaskFromCustomTaskId and hasPendingAsyncAdvance (each a full process-instance + job query) as fast as possible until the 5s deadline or the task materialises. That is a tight DB-hammering busy-wait. Break out of the loop when interrupted and return the current (possibly null) task.

✅ Performance: Resolve path can block a request thread up to ~5s (double wait)

📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/WorkflowHandler.java:945 📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/WorkflowHandler.java:1011
transformToNodeVariables now blocks up to ASYNC_ADVANCE_MAX_WAIT_MS (5s), and resolveTaskWithFreshReads waits again on the same customTaskId. In the common case the second wait returns quickly once the task materialises, but if the async job never completes both calls can each run to the full deadline, blocking the HTTP request thread up to ~10s. Under the concurrent-grant load the PR targets this can pressure the request thread pool. Consider sharing the wait result across both lookups, or documenting/tuning the combined worst-case latency.

✅ Edge Case: Post-commit persist failure leaves entity/runtime divergent

📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/CreateTask.java:206-220 📄 openmetadata-service/src/main/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/CreateTask.java:585-588
On the update path the stage/availableTransitions write is deferred to a COMMITTED transaction listener whose only failure handling is LOG.error(...). Previously the inline taskRepository.update(...) would throw and roll back the whole Flowable command, keeping entity and runtime consistent. Now the Flowable runtime task commits first, so if the deferred taskRepository.update fails (e.g. optimistic-version conflict from EntityRepository.updateWithOptimisticLocking, or DB error) the task entity permanently advertises the OLD stage/transitions while the workflow has already advanced — a silent divergence with no retry or reconciliation. Consider a compensating action or a reconciliation-on-read so a failed post-commit persist doesn't strand the entity in a stale state.

✅ Quality: Regression test asserts on source text, not behavior

📄 openmetadata-service/src/test/java/org/openmetadata/service/governance/workflows/elements/nodes/userTask/CreateTaskPostCommitPersistTest.java:54-68
The regression test asserts on raw source-file text (source.contains("registerPostCommitPersist("), contains("TransactionState.COMMITTED"), and an exact string in TaskWorkflowHandler.java). This verifies code shape, not observable behavior: it will pass even if the post-commit ordering is broken, and will break on harmless refactors/renames. As the file comment itself notes, real coverage lives in the DAR integration tests — consider dropping these brittle string guards or replacing them with a behavioral test that exercises the deferred-persist ordering.

Options

Display: compact → Showing less information.

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

This branch was previously deployed

1 inactive deployment
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 To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants