Skip to content

feat: Add cron and workflow execution related fields to visibility#7527

Merged
neil-xie merged 10 commits intocadence-workflow:masterfrom
neil-xie:CDNC-16908-cron
Jan 27, 2026
Merged

feat: Add cron and workflow execution related fields to visibility#7527
neil-xie merged 10 commits intocadence-workflow:masterfrom
neil-xie:CDNC-16908-cron

Conversation

@neil-xie
Copy link
Member

@neil-xie neil-xie commented Dec 11, 2025

Detailed Description
Add cronSchedule, executionStatus and scheduleExecutionTime to visibility records, which will be available for list workflow executions.
ExecutionStatus will have pending, started and the close statuses, we populate the actual close status for cron workflows instead of purely displaying continued as new.
ScheduledExecutionTime will calculate the actual execution time for cron workflows, before that it will be in pending status. When it generates the first decision task, the status will be switched to started.
These changes will require a schema upgrade.

ExecutionStatus is available in CLI by default, CronSchedule and ScheduledExecutionTime are optional, will be available using the flag --print_cron

% ./cadence --do default wf list --print_cron
       WORKFLOW TYPE      |                WORKFLOW ID                |                RUN ID                | TASK LIST | IS CRON | START TIME | EXECUTION TIME | CLOSE STATUS | HISTORY LENGTH | UPDATE TIME | EXECUTION STATUS | CRON SCHEDULE | SCHEDULED EXECUTION TIME
  test                    | test_workflow                             | f61149e0-bd7c-45b8-96ba-445ba3c5b8ff | tasklist  | true    | 13:31:49   | 14:00:00       | COMPLETED    |              0 | 16:00:00    | PENDING          | 0 * * * *     | 14:00:00
  main.sampleCronWorkflow | cron_016ba5f8-4e71-455d-b233-c25b34cb6a2e | a4a1d289-ec99-4451-a92a-e92e5d6064c3 | cronGroup | true    | 13:31:00   | 13:32:00       | COMPLETED    |              0 | 16:00:00    | STARTED          | * * * * *     | 13:32:00
  
       WORKFLOW TYPE      |                WORKFLOW ID                |                RUN ID                | TASK LIST | IS CRON | START TIME | EXECUTION TIME | END TIME |   CLOSE STATUS   | HISTORY LENGTH | UPDATE TIME | EXECUTION STATUS | CRON SCHEDULE | SCHEDULED EXECUTION TIME
  main.sampleCronWorkflow | cron_016ba5f8-4e71-455d-b233-c25b34cb6a2e | a4a1d289-ec99-4451-a92a-e92e5d6064c3 | cronGroup | true    | 13:31:00   | 13:32:00       | 16:00:00 | COMPLETED        |              0 | 16:00:00    | STARTED          | * * * * *     | 13:32:00
  main.sampleCronWorkflow | cron_016ba5f8-4e71-455d-b233-c25b34cb6a2e | 97766224-3d95-49eb-b0da-e1eca01d8bfa | cronGroup | true    | 13:29:00   | 13:30:00       | 13:31:00 | CONTINUED_AS_NEW |              3 | 16:00:00    | TIMED_OUT        | * * * * *     | 13:30:00
  main.sampleCronWorkflow | cron_016ba5f8-4e71-455d-b233-c25b34cb6a2e | 436c02b2-bc83-45fd-bb17-0558461ec60f | cronGroup | true    | 13:27:00   | 13:28:00       | 13:29:00 | CONTINUED_AS_NEW |              3 | 16:00:00    | TIMED_OUT        | * * * * *     | 13:28:00

Impact Analysis

  • Backward Compatibility: Yes
  • Forward Compatibility: Schema upgrade is required

Testing Plan

  • Unit Tests: Yes
  • Persistence Tests: Yes
  • Integration Tests: Yes
  • Compatibility Tests: Server won't start if schema is not upgraded

Rollout Plan

  • What is the rollout plan? staging -> production
  • Does the order of deployment matter? No
  • Is it safe to rollback? Does the order of rollback matter? Yes, just no value for the new fields, which is completely fine.
  • Is there a kill switch to mitigate the impact immediately? NA

// Check if the first decision task has been scheduled yet
// If there's no decision info, the workflow is still pending
if !hasPending && !hasInFlight && !hasProcessed {
executionStatus = types.WorkflowExecutionStatusPending
Copy link
Member

Choose a reason for hiding this comment

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

is this only true when there's backoff? What about when there's not backoff?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, when decision task doesn't exist and there is backoff, we consider it as pending. Without backoff the status is started.

Signed-off-by: Neil Xie <neil.xie@uber.com>
Signed-off-by: Neil Xie <neil.xie@uber.com>
Signed-off-by: Neil Xie <neil.xie@uber.com>
Signed-off-by: Neil Xie <neil.xie@uber.com>
…uledExecutionTime

This commit adds complete support for three new visibility fields to enable
better workflow lifecycle tracking and cron workflow scheduling.

Changes:
1. Type Mappers:
   - Added WorkflowExecutionStatus enum mappers (Thrift and Proto)
   - Added Ptr(), String(), UnmarshalText(), MarshalText() methods to WorkflowExecutionStatus
   - Updated WorkflowExecutionInfo mappers to include all three new fields

2. Elasticsearch Support:
   - Added three fields to VisibilityRecord struct for ES deserialization
   - Updated convertSearchResultToVisibilityRecord to populate the new fields
   - This fixes the issue where fields were written but not read from ES

3. Service Layer:
   - Updated timer active task executor to pass ScheduledExecutionTime
   - Updated transfer task executor base to include new fields in visibility records

The fields are now properly:
- Written to Elasticsearch during workflow start, upsert, and close
- Read from Elasticsearch when listing workflows
- Displayed in CLI output with --print_cron flag
- Mapped correctly between Thrift, Proto, and internal types

Signed-off-by: Neil Xie <neil.xie@uber.com>
Signed-off-by: Neil Xie <neil.xie@uber.com>
Signed-off-by: Neil Xie <neil.xie@uber.com>
Signed-off-by: Neil Xie <neil.xie@uber.com>
Signed-off-by: Neil Xie <neil.xie@uber.com>
… to helper function

Signed-off-by: Neil Xie <neil.xie@uber.com>
Aliases: []string{"psa"},
Usage: "Print search attributes",
},
&cli.BoolFlag{
Copy link
Member

Choose a reason for hiding this comment

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

Should we/is it complicated to have it by default?

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure how useful is it to show CronSchedule for all workflows, maybe we need to implement a filter to automatically hide the column if it is all empty.
I will make this flag more useful, maybe automatically apply isCron when they have this flag and show the cron related fields

@neil-xie neil-xie merged commit 0f4b650 into cadence-workflow:master Jan 27, 2026
42 checks passed
@neil-xie neil-xie deleted the CDNC-16908-cron branch January 27, 2026 21:58
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.

3 participants