Skip to content

add RESET_REQUESTED state to standalone activity#10364

Merged
spkane31 merged 6 commits into
feature/activity-operator-cmdsfrom
spk/reset-requested
May 29, 2026
Merged

add RESET_REQUESTED state to standalone activity#10364
spkane31 merged 6 commits into
feature/activity-operator-cmdsfrom
spk/reset-requested

Conversation

@spkane31

Copy link
Copy Markdown
Contributor

What changed?

Replace the flagged base RESET state with a RESET_REQUESTED state. This takes fuller advantage of the CHASM state transition functionality.

Why?

Reduces the amount of special casing code and replaces this with an additional state (RESET_REQUESTED) and state transitions to handle the case where a STARTED activity is reset and has to be delivered on the next heartbeat or when an activity completes the attempt.

How did you test it?

  • built
  • run locally and tested manually
  • covered by existing tests
  • added new unit test(s)
  • added new functional test(s)

Potential risks

NA, unreleased code.

@spkane31 spkane31 requested review from a team as code owners May 22, 2026 18:54
@spkane31 spkane31 requested a review from dandavison May 22, 2026 18:54
@spkane31 spkane31 force-pushed the spk/reset-requested branch from 1595173 to 5cacf1e Compare May 28, 2026 15:56

@dandavison dandavison 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.

Did a pass. Looks good; a few things suggested in comments.

Comment thread chasm/lib/activity/statemachine.go Outdated
func(a *Activity, ctx chasm.MutableContext, event completeEvent) error {
return a.StoreOrSelf(ctx).RecordCompleted(ctx, func(ctx chasm.MutableContext) error {
a.ActivityReset = false
a.PauseState = nil

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.

We shouldn't clear PauseState because no logic should be expressed in terms of PauseState and it's cleaner just to let it be, rather than have the code imply that something would go wrong if it's not cleared in all the right places.

Same comment applies to all the places below where PauseState is cleared.

This will make it like CancelState and TerminateState. As I mentioned in other comments, I'd be open to calling it LastPauseState to make it clear that this one might be non-current unlike CancelState and TerminateState which I believe are always current (but lmk if that's wrong).

Comment thread chasm/lib/activity/activity.go Outdated
CancelRequested: a.Status == activitypb.ACTIVITY_EXECUTION_STATUS_CANCEL_REQUESTED,
ActivityPaused: a.Status == activitypb.ACTIVITY_EXECUTION_STATUS_PAUSE_REQUESTED,
ActivityReset: a.ActivityReset,
ActivityPaused: (a.PauseState != nil || a.Status == activitypb.ACTIVITY_EXECUTION_STATUS_PAUSE_REQUESTED) && a.Status != activitypb.ACTIVITY_EXECUTION_STATUS_CANCEL_REQUESTED,

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.

With the change to PauseRequested we should not be using PauseState as a flag any longer. And IMO we shouldn't ever clear it: just let it be set without clearing, like CancelState and TerminateState. We could call it LastPauseState to emphasize that it isn't necessarily current -- does that rename appeal to you?

I think we'll need to store ResetKeepPaused on the activity state.

So this line should look like

ActivityPaused: a.Status == PAUSE_REQUESTED || (a.Status == RESET_REQUESTED && a.ResetKeepPaused)

Comment thread chasm/lib/activity/activity.go Outdated
if !keepPaused {
// Clear PauseState now so the deferred reset can dispatch on retry without being
// blocked by the validator (which drops dispatch tasks when PauseState != nil).
a.PauseState = nil

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.

The task validators no longer gate on PauseState so this is not needed.

Comment thread chasm/lib/activity/statemachine.go Outdated
return a.StoreOrSelf(ctx).RecordCompleted(ctx, func(ctx chasm.MutableContext) error {
req := event.req.GetFailedRequest()
a.ActivityReset = false
a.PauseState = nil

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.

No need to clear PauseState (see comment above)

Comment thread chasm/lib/activity/statemachine.go Outdated
RequestId: event.request.RequestID,
}
a.ActivityReset = false
a.PauseState = nil

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.

No need to clear PauseState (see comment above)

Comment thread chasm/lib/activity/statemachine.go Outdated
},
}
a.ActivityReset = false
a.PauseState = nil

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.

No need to clear PauseState (see comment above)

Comment thread chasm/lib/activity/statemachine.go Outdated
}

a.ActivityReset = false
a.PauseState = nil

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.

No need to clear PauseState (see comment above)

@spkane31 spkane31 requested a review from dandavison May 29, 2026 18:16
Comment on lines +997 to +1000
// keepPaused on a paused (PAUSE_REQUESTED) activity preserves the pause: when the worker
// yields the activity lands back in PAUSED rather than SCHEDULED. Recorded as an explicit
// flag so no logic has to gate on the descriptive LastPauseState field.
a.ResetKeepPaused = keepPaused && a.Status == activitypb.ACTIVITY_EXECUTION_STATUS_PAUSE_REQUESTED

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.

The second part of the comment will be hard for a future reader to understand.

Suggested change
// keepPaused on a paused (PAUSE_REQUESTED) activity preserves the pause: when the worker
// yields the activity lands back in PAUSED rather than SCHEDULED. Recorded as an explicit
// flag so no logic has to gate on the descriptive LastPauseState field.
a.ResetKeepPaused = keepPaused && a.Status == activitypb.ACTIVITY_EXECUTION_STATUS_PAUSE_REQUESTED
// keepPaused on a paused (PAUSE_REQUESTED) activity preserves the pause: when the worker
// yields the activity lands back in PAUSED rather than SCHEDULED.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added

// keepPaused=true while the activity was in PAUSE_REQUESTED). The failed attempt is recorded, the
// attempt count is reset to 1, and no dispatch task is emitted — the activity stays paused until
// an explicit unpause.
var TransitionResetAttemptFailedToPaused = chasm.NewTransition(

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.

We might want to look again over our transition names to see if we're happy with how consistent they are (I used While but after some back and forth, and I know yours have to distinguish between the two destinations). But we don't have to do that now since tit has no impact on persisted data or public exposure -- can fiddle with them at any time in the future.

@dandavison dandavison 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.

LGTM!

@spkane31 spkane31 merged commit 0ddb873 into feature/activity-operator-cmds May 29, 2026
46 checks passed
@spkane31 spkane31 deleted the spk/reset-requested branch May 29, 2026 20:15
spkane31 added a commit that referenced this pull request Jun 2, 2026
## What changed?
Replace the flagged base `RESET` state with a `RESET_REQUESTED` state.
This takes fuller advantage of the CHASM state transition functionality.

## Why?
Reduces the amount of special casing code and replaces this with an
additional state (`RESET_REQUESTED`) and state transitions to handle the
case where a `STARTED` activity is reset and has to be delivered on the
next heartbeat or when an activity completes the attempt.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [X] covered by existing tests
- [ ] added new unit test(s)
- [X] added new functional test(s)

## Potential risks
NA, unreleased code.
spkane31 added a commit that referenced this pull request Jun 2, 2026
## What changed?
Replace the flagged base `RESET` state with a `RESET_REQUESTED` state.
This takes fuller advantage of the CHASM state transition functionality.

## Why?
Reduces the amount of special casing code and replaces this with an
additional state (`RESET_REQUESTED`) and state transitions to handle the
case where a `STARTED` activity is reset and has to be delivered on the
next heartbeat or when an activity completes the attempt.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [X] covered by existing tests
- [ ] added new unit test(s)
- [X] added new functional test(s)

## Potential risks
NA, unreleased code.
fretz12 pushed a commit that referenced this pull request Jun 9, 2026
Implements Pause, Unpause, Reset, and UpdateActivityExecutionOptions
RPCs for standalone CHASM activities. Adds matching frontend and
history service handlers in chasm/lib/activity that dispatch to
either the workflow-activity path or the standalone-activity path
based on the presence of a workflow ID.

Also adds PAUSE_REQUESTED and RESET_REQUESTED state machine states
for standalone activities, the original_options snapshot for
restore-on-reset semantics, the activity-options merge helpers
(common/activityoptions), and the supporting proto schema changes
(start_request_id, sdk_name, sdk_version, etc.).

Squash of the 29 commits previously on this branch. Original PRs:
  #9693  RPC boilerplate and code generation
  #9850  Implement UpdateActivityExecutionOptions
  #9851  Implement Pause/UnpauseActivityExecution for SAA
  #9852  Implement ResetActivityExecution for SAA
  #10001 Pause returns FailedPrecondition when already paused
  #10025 Validator function fixes
  #10265 Replace PauseState flag with PAUSE_REQUESTED state
  #10364 Add RESET_REQUESTED state to standalone activity
fretz12 pushed a commit that referenced this pull request Jun 9, 2026
Implements Pause, Unpause, Reset, and UpdateActivityExecutionOptions
RPCs for standalone CHASM activities. Adds matching frontend and
history service handlers in chasm/lib/activity that dispatch to
either the workflow-activity path or the standalone-activity path
based on the presence of a workflow ID.

Also adds PAUSE_REQUESTED and RESET_REQUESTED state machine states
for standalone activities, the original_options snapshot for
restore-on-reset semantics, the activity-options merge helpers
(common/activityoptions), and the supporting proto schema changes
(start_request_id, sdk_name, sdk_version, etc.).

Squash of the 29 commits previously on this branch. Original PRs:
  #9693  RPC boilerplate and code generation
  #9850  Implement UpdateActivityExecutionOptions
  #9851  Implement Pause/UnpauseActivityExecution for SAA
  #9852  Implement ResetActivityExecution for SAA
  #10001 Pause returns FailedPrecondition when already paused
  #10025 Validator function fixes
  #10265 Replace PauseState flag with PAUSE_REQUESTED state
  #10364 Add RESET_REQUESTED state to standalone activity
fretz12 pushed a commit that referenced this pull request Jun 16, 2026
Implements Pause, Unpause, Reset, and UpdateActivityExecutionOptions
RPCs for standalone CHASM activities. Adds matching frontend and
history service handlers in chasm/lib/activity that dispatch to
either the workflow-activity path or the standalone-activity path
based on the presence of a workflow ID.

Also adds PAUSE_REQUESTED and RESET_REQUESTED state machine states
for standalone activities, the original_options snapshot for
restore-on-reset semantics, the activity-options merge helpers
(common/activityoptions), and the supporting proto schema changes
(start_request_id, sdk_name, sdk_version, etc.).

Squash of the 29 commits previously on this branch. Original PRs:
  #9693  RPC boilerplate and code generation
  #9850  Implement UpdateActivityExecutionOptions
  #9851  Implement Pause/UnpauseActivityExecution for SAA
  #9852  Implement ResetActivityExecution for SAA
  #10001 Pause returns FailedPrecondition when already paused
  #10025 Validator function fixes
  #10265 Replace PauseState flag with PAUSE_REQUESTED state
  #10364 Add RESET_REQUESTED state to standalone activity
fretz12 pushed a commit that referenced this pull request Jul 1, 2026
Implements Pause, Unpause, Reset, and UpdateActivityExecutionOptions
RPCs for standalone CHASM activities. Adds matching frontend and
history service handlers in chasm/lib/activity that dispatch to
either the workflow-activity path or the standalone-activity path
based on the presence of a workflow ID.

Also adds PAUSE_REQUESTED and RESET_REQUESTED state machine states
for standalone activities, the original_options snapshot for
restore-on-reset semantics, the activity-options merge helpers
(common/activityoptions), and the supporting proto schema changes
(start_request_id, sdk_name, sdk_version, etc.).

Squash of the 29 commits previously on this branch. Original PRs:
  #9693  RPC boilerplate and code generation
  #9850  Implement UpdateActivityExecutionOptions
  #9851  Implement Pause/UnpauseActivityExecution for SAA
  #9852  Implement ResetActivityExecution for SAA
  #10001 Pause returns FailedPrecondition when already paused
  #10025 Validator function fixes
  #10265 Replace PauseState flag with PAUSE_REQUESTED state
  #10364 Add RESET_REQUESTED state to standalone activity
fretz12 pushed a commit that referenced this pull request Jul 10, 2026
Implements Pause, Unpause, Reset, and UpdateActivityExecutionOptions
RPCs for standalone CHASM activities. Adds matching frontend and
history service handlers in chasm/lib/activity that dispatch to
either the workflow-activity path or the standalone-activity path
based on the presence of a workflow ID.

Also adds PAUSE_REQUESTED and RESET_REQUESTED state machine states
for standalone activities, the original_options snapshot for
restore-on-reset semantics, the activity-options merge helpers
(common/activityoptions), and the supporting proto schema changes
(start_request_id, sdk_name, sdk_version, etc.).

Squash of the 29 commits previously on this branch. Original PRs:
  #9693  RPC boilerplate and code generation
  #9850  Implement UpdateActivityExecutionOptions
  #9851  Implement Pause/UnpauseActivityExecution for SAA
  #9852  Implement ResetActivityExecution for SAA
  #10001 Pause returns FailedPrecondition when already paused
  #10025 Validator function fixes
  #10265 Replace PauseState flag with PAUSE_REQUESTED state
  #10364 Add RESET_REQUESTED state to standalone activity
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.

2 participants