Skip to content

Conversation

@dandavison
Copy link
Contributor

@dandavison dandavison commented Oct 16, 2025

What changed?

Adds a state machine defining valid transitions for a CHASM activity.

The state machine does not include transitions related to cancel and pause states: we can add those when we implement those features.

image

Why?

Part of foundations for CHASM activity implementation / Standalone Activity.

How did you test it?

  • Added new unit test

Note

Introduces an Activity state machine with core execution transitions and updates the chasm Transition API to take (SM, Context, Event) parameter order.

  • Activity state machine (chasm/lib/activity/statemachine.go):
    • Implements activity.Activity as chasm.StateMachine[activitypb.ActivityExecutionStatus] with State()/SetState().
    • Defines transitions:
      • UNSPECIFIED -> SCHEDULED
      • SCHEDULED -> STARTED
      • STARTED -> COMPLETED | FAILED
      • SCHEDULED | STARTED -> TERMINATED | TIMED_OUT
  • API change (chasm/statemachine.go):
    • Reorders Transition.apply signature to apply(SM, MutableContext, E) and updates NewTransition/Apply accordingly.

Written by Cursor Bugbot for commit 59cd168. This will update automatically on new commits. Configure here.

@dandavison dandavison requested review from a team as code owners October 16, 2025 15:38
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

var _ chasm.StateMachine[activitypb.ActivityExecutionStatus] = (*Activity)(nil)

// State returns the current status of the activity.
func (a *Activity) State() activitypb.ActivityExecutionStatus {
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 change the state machine abstraction to expect Status and SetStatus as it seems we are converging on that terminology?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I like that. I feel that this makes sense:

  • A state machine library has State() and SetState()
  • For a given client of that library, "status" is the field name used for the state that is governed by the state machine library.

Comment on lines 21 to 23
if a.ActivityState == nil {
return
}
Copy link
Member

Choose a reason for hiding this comment

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

Let it panic, this should be an invalid state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

"go.temporal.io/server/chasm/lib/activity/gen/activitypb/v1"
)

func TestValidTransitions(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't like this type of test, you are just testing configuration here and duplicating what is defined in the code being tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree! Deleted test. We'll start having test coverage when we add the API method PRs.

}
}

func TestInvalidTransitions(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

a.ActivityState.Status = state
}

var (
Copy link
Member

Choose a reason for hiding this comment

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

Can you get rid of this redundant nesting? By the time you get to the function implementation, you're three levels in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

activitypb.ACTIVITY_EXECUTION_STATUS_UNSPECIFIED,
},
activitypb.ACTIVITY_EXECUTION_STATUS_SCHEDULED,
func(_ chasm.MutableContext, _ *Activity, _ any) error {
Copy link
Member

Choose a reason for hiding this comment

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

It might be nice to change the transition function's signature to take SM as the first argument so you can pass a method pointer here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems like a good idea. Done.

}

var (
TransitionScheduled = chasm.NewTransition(
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 add some docstrings to explain what this is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes good call, done.

@dandavison dandavison force-pushed the standalone-activity-state-machine branch from e518ec7 to 984ed80 Compare October 16, 2025 17:04
@dandavison dandavison changed the base branch from standalone-activity to standalone-activity-post-rebase-fixups October 16, 2025 17:06
@dandavison dandavison force-pushed the standalone-activity-state-machine branch from 984ed80 to f722d1c Compare October 16, 2025 18:41
@dandavison
Copy link
Contributor Author

Ready for review again

Base automatically changed from standalone-activity-post-rebase-fixups to standalone-activity October 16, 2025 18:46
@dandavison dandavison requested a review from fretz12 October 16, 2025 18:48
Copy link
Member

@bergundy bergundy left a comment

Choose a reason for hiding this comment

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

LGTM, but you'll want to rebase and not include the proto changes here.

@dandavison dandavison force-pushed the standalone-activity-state-machine branch from 193fa7f to 59cd168 Compare October 16, 2025 19:20
@dandavison dandavison merged commit ca2c560 into standalone-activity Oct 16, 2025
54 of 58 checks passed
@dandavison dandavison deleted the standalone-activity-state-machine branch October 16, 2025 20:00
dandavison added a commit that referenced this pull request Oct 30, 2025
Adds a state machine defining valid transitions for a CHASM activity.

The state machine does not include transitions related to cancel and
pause states: we can add those when we implement those features.

Part of foundations for CHASM activity implementation / Standalone
Activity.

- Built (a unit test was written but not committed)
dandavison added a commit that referenced this pull request Dec 19, 2025
Adds a state machine defining valid transitions for a CHASM activity.

The state machine does not include transitions related to cancel and
pause states: we can add those when we implement those features.

Part of foundations for CHASM activity implementation / Standalone
Activity.

- Built (a unit test was written but not committed)
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