Skip to content

Fixes 36148: Keep approval tasks of long-named workflows bound to their own workflow run - #37856

Merged
yan-3005 merged 2 commits into
open-metadata:mainfrom
Vamsi-klu:fix/36148-long-workflow-process-key
Nov 19, 2026
Merged

yan-3005 merged 2 commits into
open-metadata:mainfrom
Vamsi-klu:fix/36148-long-workflow-process-key

Conversation

@Vamsi-klu

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

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #36148

A governance workflow with a long name (for example ownerAssignedTagApproval_<UUID>, 61 characters) lost its run identity, and its approval task ended up bound to the default RequestApprovalTaskWorkflow.

Flowable 7.2 builds a process-definition ID as key:version:id only while it fits in 64 characters. A longer ID becomes a bare generated number such as 6308 (BpmnDeployer.getIdForNewProcessDefinition; ACT_RE_PROCDEF.ID_ is varchar(64)). The shared helper WorkflowHandler.getProcessDefinitionKeyFromId split the ID on : and read the key as 6308. That caused a chain of failures:

  • The trigger was treated as a non-OpenMetadata process, so the run got no business key and no WorkflowInstance row.
  • CreateTask therefore created a task with neither an instance UUID nor a definition UUID.
  • TaskRepository adopted that task into RequestApprovalTaskWorkflow.

The same wrong key also broke change-request routing in FilterEntityImpl, stage and failure records, and sink labels. Two places split the ID on their own:

  • WorkflowHandler.deploy never cancelled the old entity-specific timer jobs of a long-named periodic workflow, so duplicate scheduled runs survived a redeploy.
  • FetchEntitiesImpl read the entity type from the split key. It was not observably broken: each per-type process is also given its own entity type, which the code falls back to.

The helper now reads the key from the deployed definition through RepositoryService.getProcessDefinition(id), which Flowable serves from its deployment cache. When the engine is not running or the definition cannot be read (an unknown ID, or a database error, including the MyBatis PersistenceException that escapes unwrapped outside a Flowable command), it falls back to the part of the ID before the first :. It returns null for a null ID and never throws, because most callers use it while logging inside a catch. The timer-job cleanup in deploy asks the repository service of the engine it is deploying to, and FetchEntitiesImpl now calls the helper for consistency, so nothing else parses a definition ID. The helper's signature is unchanged, so its 35 call sites in 25 files need no edits.

This fix is preventive. Tasks that are already misbound and historic instance rows that were never written are not repaired, as the issue states. Workflow names over about 248 characters still fail at deployment on ACT_RE_PROCDEF.KEY_ varchar(255); that limit is unchanged and out of scope.

Left for follow-ups: WorkflowFailureListener (L154) takes key.split("-")[0], so for a UUID-suffixed name like the issue's fixture isStageStatusEnabled is false and no failure stage row is written. That is the same outcome as before this fix, and as today for any short name containing -.

The rule is recorded in docs/decisions/2026-11-16-a-process-definition-key-is-read-from-its-deployed-definition.md.

Type of change:

  • Bug fix

High-level design:

N/A — small change. Alternatives considered:

  • Parsing the ID when it contains :. This relies on Flowable's private ID layout and breaks keys that contain :.
  • Changing every caller to pass the execution. That is a 27-file diff.
  • Capping the name length. No static cap is safe, because the threshold grows with the database ID and the version.

Tests:

Use cases covered

  • An event-triggered approval workflow with a 61-character name (both its main and trigger definitions get bare generated IDs, asserted as a precondition) creates a task that carries that workflow's definition UUID and a valid instance UUID. Approving it finishes that run, and the task is Approved.
  • A periodic workflow with a 65-character name (its <name>Trigger-tag definition gets a bare generated ID) records its run, and its approval task is bound to that run and workflow.
  • The reviewer-change regression test now selects the task by the workflow's UUID, not only by assignee.
  • Redeploying a periodic workflow cancels the entity-specific timer job of a definition with a bare generated ID, as well as one with a composite ID.
  • Through a running engine, a bare generated ID resolves to the deployed 68-character key.
  • A key containing : resolves to the full deployed key, not the part before the first :.
  • Short names, null IDs, IDs Flowable cannot read, a database error, and an uninitialized engine all fall back as described above. None of them throws.

Unit tests

  • I added unit tests for the new/changed logic.
  • Added: WorkflowHandlerProcessDefinitionKeyTest (6 tests: a bare generated ID, a key containing :, an unknown ID, a MyBatis database error, a null ID, and an engine that is not running). It resets WorkflowHandler's static state before and after each test.
  • Added: WorkflowHandlerSchemaUpdateTest#runningEngineReadsTheKeyOfABareGeneratedIdFromTheDeployedDefinition, which initializes WorkflowHandler with a mocked engine and asserts that getProcessDefinitionKeyFromId("6308") returns the deployed 68-character key. Reverting the public helper to the : split, or making it ignore the running engine, fails this test (expected: <ownerAssignedTagApproval_…Trigger> but was: <6308>) while the other 25 tests in the two classes stay green.
  • Updated: WorkflowHandlerSchemaUpdateTest#deployCancelsEntitySpecificPeriodicTimerJobs. Its deep-stubbed RepositoryService now answers the definition lookup the cleanup makes, and it adds a timer job whose definition has a bare generated ID (6310), which the old split never cancelled.
  • Re-run: every test class under org.openmetadata.service.governance plus WorkflowRedeployEntryPointTest, IngestionPipelineMigrationEntryPointTest and OntologyEntityDAOTest: 1001 tests, 0 failures, 0 errors.
  • Coverage: all 16 changed executable lines in WorkflowHandler and FetchEntitiesImpl are covered by unit tests (JaCoCo). WorkflowHandler is a 2,400-line class, so class-level coverage is not meaningful for this change.

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/.
  • Files updated: WorkflowDefinitionResourceIT.
    • New: test_longWorkflowNameKeepsItsApprovalTaskAndCompletesItsRun and test_longPeriodicWorkflowNameRecordsItsRunAndBindsItsTask.
    • Tightened: test_reviewerChangeDoesNotOverwriteOwnerAssignedApprovalTask.
  • Before the fix (production code from main, mysql-elasticsearch, global-state lane): 3 of 3 fail with ConditionTimeoutException on the workflow-UUID selector, for example Condition with alias 'open approval task of workflow <id> on ...guardTag' didn't complete within 2 minutes. The opaque-ID precondition guards passed in both new tests, so the fixtures do reproduce Long workflow names lose process identity and bind approval tasks to the default lifecycle #36148.
  • After the fix: 3 of 3 pass on mysql-elasticsearch and 3 of 3 pass on postgres-opensearch (global-state lane; Tests run: 3, Failures: 0, Errors: 0 in TEST-org.openmetadata.it.tests.WorkflowDefinitionResourceIT.xml for each engine).
  • The WorkflowHandlerSchemaUpdateTest change also fails on main's production code: deleteJob("generated-id-timer") is "Wanted but not invoked".
  • Pending: make java_affected_run ARGS="--scope focused --update-pr" (needs this PR) and --scope full.

Local Java test run: PASSED

  • Commit: 0e077cd05c81 (base origin/main)
  • Finished: 2026-11-16 07:54 UTC · 14.8 min
  • Details: the classes each step ran, why these tests, the commands
  • Scope: focused; merge readiness is not established. Broader steps deferred: 5 (run --scope full).
Step Scope Classes Tests Failed Skipped Min Result
unit openmetadata-service (3 classes) 3 28 0 0 1.9 passed
integration mysql-elasticsearch · isolated 1 147 0 0 12.9 passed

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Visual regression baselines

  • Not applicable (no rendering change).

Manual testing performed

  1. Checked the 64-character rule in the Flowable 7.2.0 jar (javap on BpmnDeployer), and that a nested RepositoryService call from a listener reuses the running command context (CommandConfig defaults to contextReusePossible=true, REQUIRED propagation).
  2. Ran the three ITs before the fix (all fail) and after it (all pass), as listed above.

UI screen recording:

Not applicable — backend-only bug fix.

Checklist:

  • I have read the CONTRIBUTING document.

  • My PR title is Fixes <issue-number>: <short explanation>

  • My PR is linked to a GitHub issue via Fixes #<issue-number> 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.

  • For a UI feature or feature task: as part of PR creation, I ran the PR build in Docker with sample data and embedded a verified GitHub-hosted recording plus build/health evidence above (or explained why this requirement is not applicable).

  • I have added tests (unit / integration / Playwright as applicable) and listed them above.

  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.

  • Decision check: adds docs/decisions/2026-11-16-a-process-definition-key-is-read-from-its-deployed-definition.md.

  • I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.

RetriggerView in GreptileConfidence Score: 5/5

The latest changes appear safe to merge.

Summary

The PR keeps approval tasks for long-named workflows tied to the correct workflow and run.

  • Long workflow names keep their run and approval task identity.
  • Periodic redeploys cancel matching timers for long-named workflows.

The latest changes split the approval test into named helpers without changing its checks. Both previous findings are addressed; no new issues were found.

Reviews (7) · Last reviewed commit: "Split the long-workflow-name IT into nam..." · Reviewed by Greptile

…ir own workflow run

Flowable 7.2 replaces a process-definition ID with a bare generated id
when "key:version:id" exceeds 64 characters. WorkflowHandler's shared
getProcessDefinitionKeyFromId split the ID on ':', so a workflow named
like ownerAssignedTagApproval_<UUID> read as key "6308". Its trigger was
then treated as non-OpenMetadata, the run got no business key or
WorkflowInstance row, and CreateTask produced a task with no instance or
definition UUID that TaskRepository adopted into RequestApprovalTaskWorkflow.

The helper now reads the key from the deployed definition through
RepositoryService, which is served from Flowable's deployment cache. It
falls back to the ID prefix only when the engine is not running or the
definition cannot be read, including a MyBatis database error raised
outside a Flowable command, so callers logging from catch blocks never
see it throw. The timer-job cleanup in WorkflowHandler.deploy, which
never cancelled the entity-specific timers of long-named periodic
workflows, now reads the key the same way. FetchEntitiesImpl also uses
the helper so nothing else parses a definition ID; it was not observably
broken, because each per-type process is also given its entity type.
The rule is recorded in a decision record.

Tests: a unit test for the helper, including a key that contains ':' and
a database error; a running-engine case and a bare-generated-ID timer job
in WorkflowHandlerSchemaUpdateTest; an event IT with a long name that
checks the task keeps its workflow and instance UUIDs and that approving
it finishes the run; a periodic IT with a long name that checks the run
is recorded and the task is bound to it; and
test_reviewerChangeDoesNotOverwriteOwnerAssignedApprovalTask now selects
its task by the workflow's UUID.
@Vamsi-klu
Vamsi-klu requested a review from a team as a code owner November 16, 2026 07:31
@Vamsi-klu
Vamsi-klu requested a review from IceS2 November 16, 2026 07:31
@Vamsi-klu

Copy link
Copy Markdown
Contributor Author

cc @yan-3005 @harshach — fixes 36148: the shared getProcessDefinitionKeyFromId now reads the key from the deployed Flowable definition, so a workflow name over Flowable's 64-char ID limit keeps its run and its approval task; ITs cover event and periodic triggers on both engines.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@Vamsi-klu

Copy link
Copy Markdown
Contributor Author

Local Java test run: PASSED — details

  • Commit: 0e077cd05c81 (base origin/main)
  • The summary is in the PR description.

Tests run locally

  • unit · openmetadata-service (3 classes): FetchEntitiesImplTest (2 passed), WorkflowHandlerProcessDefinitionKeyTest (6 passed), WorkflowHandlerSchemaUpdateTest (20 passed)
  • integration · mysql-elasticsearch · isolated: WorkflowDefinitionResourceIT (147 passed)

Broader coverage not executed by this focused run

  • mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=FetchEntitiesImplTest,IngestionPipelineMigrationEntryPointTest,MigrationUtilTaskWorkflowTest,OntologyEntityDAOTest,TaskRepositoryLifecycleEventTest,TaskWorkflowHandlerReviewVotesTest,TaskWorkflowHandlerTest,WorkflowEventConsumerTest,WorkflowHandlerProcessDefinitionKeyTest,WorkflowHandlerSchemaUpdateTest,WorkflowHandlerTriggerTest,WorkflowInstanceTerminatorTest,WorkflowRedeployEntryPointTest,WorkflowRedeployMigrationTest,WorkflowSignalIsolationTest -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel '-Dit.test=<46 classes>' -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=global-state -Dit.test=AppsResourceIT,ChangeRequestAdmissionIT,ChangeRequestApplyIT,ChangeRequestDecisionIT,ChangeRequestImportAndBulkIT,ChangeRequestLifecycleIT,ChangeRequestResourceIT,DataContractValidationAppIT,TagRecognizerFeedbackIT,WorkflowDefinitionResourceIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=rdf -Dit.test=RdfGovernanceRulesIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Psearch-it -DdatabaseType=postgres -DsearchType=opensearch -Djpw.data.mode=ingest -Dit.test=SearchAccessRulesIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
Commands
mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=FetchEntitiesImplTest,WorkflowHandlerProcessDefinitionKeyTest,WorkflowHandlerSchemaUpdateTest -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=global-state -Dit.test=WorkflowDefinitionResourceIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false

@greptile-apps

greptile-apps Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

@IceS2
IceS2 requested review from yan-3005 and removed request for IceS2 November 18, 2026 09:52
…final

test_longWorkflowNameKeepsItsApprovalTaskAndCompletesItsRun now reads as deploy,
start, bind check, approve and await, each a named helper, and reuses approve().
The locals and parameters added for the deployed-definition key lookup are final.
@gitar-bot

gitar-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk

The shared key resolver changes run identity, approval-task binding, and timer cleanup across workflow consumers; lookup mismatches could disrupt lifecycle handling.

Keeps approval tasks of long-named workflows bound to their own workflow run by reading the process definition key from the deployed Flowable definition instead of splitting the definition ID on :. Timer-job cleanup on redeploy and FetchEntitiesImpl now use the same helper. No issues found.

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

This comment was marked as outdated.

@yan-3005

Copy link
Copy Markdown
Contributor

Thank you for the PR, merging it in

@yan-3005
yan-3005 merged commit 9f85999 into open-metadata:main Nov 19, 2026
54 of 56 checks passed
yan-3005 added a commit that referenced this pull request Nov 19, 2026
Closing a workflow-managed task sent the task's terminateProcess message,
which reaches a terminate end event with terminateAll and deletes the
root process instance. In a periodic batch that tore down the whole
trigger and marked the shared run CANCELLED. In parallel approval
branches it left the sibling's task open with nothing behind it.

- The close now deletes, one at a time, each process holding a Flowable
  task of the closed task, never the root, so a batch's trigger carries
  on. A run that is not a periodic batch is recorded CANCELLED first;
  its other open tasks about the same entity are closed after it ends,
  because parallel branches overwrite the process-wide customTaskId.
- The delete cause is whitelisted in WorkflowFailureListener.
- The task lookup narrows by the run only when the task store can be
  read, so an engine-only lookup no longer fails.
- Drop the long-workflow-name fix: #37856 fixed #36148 more completely.
- Decision records for the close rule and for the retiring engine
  keeping its job locks.
yan-3005 added a commit that referenced this pull request Nov 19, 2026
* Fixes #36148: Fix governance workflow lifecycle bugs

- Closing or bulk-cancelling a workflow-managed task now records its run
  as CANCELLED and terminates the waiting Flowable process, instead of
  leaving the run RUNNING forever.
- The certification node writes with governance-bot as impersonator, so
  its write no longer re-triggers the entity's workflows.
- The Flowable task lookup by customTaskId also matches the run's
  business key (indexed), instead of scanning ACT_RU_VARIABLE on every
  resolve, vote and terminate. The old query is the fallback.
- Replacing the engine on a workflow-settings save keeps the retiring
  executor's job locks, so a job still running is not acquired and run a
  second time. Server shutdown keeps releasing locks.
- unlockJobsOnStartup stays unwired, with a comment on why.
- RunApp's wait polls every 5s instead of spinning on the database, logs
  failed reads and honours interrupts.
- A process definition id without a key (a long workflow name) resolves
  its key from the deployed definition, so its tasks keep the right
  workflow and run.

* End only the closed task's processes, not the trigger root

Closing a workflow-managed task sent the task's terminateProcess message,
which reaches a terminate end event with terminateAll and deletes the
root process instance. In a periodic batch that tore down the whole
trigger and marked the shared run CANCELLED. In parallel approval
branches it left the sibling's task open with nothing behind it.

- The close now deletes, one at a time, each process holding a Flowable
  task of the closed task, never the root, so a batch's trigger carries
  on. A run that is not a periodic batch is recorded CANCELLED first;
  its other open tasks about the same entity are closed after it ends,
  because parallel branches overwrite the process-wide customTaskId.
- The delete cause is whitelisted in WorkflowFailureListener.
- The task lookup narrows by the run only when the task store can be
  read, so an engine-only lookup no longer fails.
- Drop the long-workflow-name fix: #37856 fixed #36148 more completely.
- Decision records for the close rule and for the retiring engine
  keeping its job locks.

* Record a closed task's run as CANCELLED only after its delete succeeds

The close recorded the run CANCELLED before deleting its process, so a
delete refused by a job executing on another server left a CANCELLED run
with a live process. A run that is not a periodic batch belongs to the
closed task alone: its whole process tree is now deleted from its root,
which runs no end listener, and CANCELLED is recorded only after the
delete succeeded. A periodic batch still deletes only the process holding
the task and leaves the run's status to its trigger.

endTaskProcess is split into named steps. The decision record states the
new order.
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.

Long workflow names lose process identity and bind approval tasks to the default lifecycle

3 participants