Skip to content

Conversation

@fretz12
Copy link
Contributor

@fretz12 fretz12 commented Dec 12, 2025

What changed?

Added support for ID conflict use existing. Added error details on conflict policy fail.

Why?

We now have the use existing policy support on chasm engine, so we can support it. Also need to pass back error details on conflict policy fail in struct ActivityExecutionAlreadyStartedError

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)

Note

Cursor Bugbot is generating a summary for commit f264bba. Configure here.

@fretz12 fretz12 marked this pull request as ready for review December 12, 2025 23:23
@fretz12 fretz12 requested review from a team as code owners December 12, 2025 23:23
@fretz12
Copy link
Contributor Author

fretz12 commented Dec 12, 2025

cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: UseExisting policy returns incorrect Started=true for existing activity

When ACTIVITY_ID_CONFLICT_POLICY_USE_EXISTING is used and an activity with the same ID already exists, the response incorrectly returns Started: true. The callback that creates the response with Started: true is always executed, even when the engine returns an existing activity via the UseExisting conflict policy. Per the established convention (seen in workflow's similar USE_EXISTING behavior in telemetry tests), Started should be false when returning an existing execution rather than creating a new one. This could mislead callers into thinking a new activity was started when it wasn't.

chasm/lib/activity/handler.go#L68-L84

},
func(mutableContext chasm.MutableContext, request *workflowservice.StartActivityExecutionRequest) (*Activity, *workflowservice.StartActivityExecutionResponse, error) {
newActivity, err := NewStandaloneActivity(mutableContext, request)
if err != nil {
return nil, nil, err
}
err = TransitionScheduled.Apply(newActivity, mutableContext, nil)
if err != nil {
return nil, nil, err
}
return newActivity, &workflowservice.StartActivityExecutionResponse{
Started: true,
// EagerTask: TODO when supported, need to call the same code that would handle the HandleStarted API
}, nil
},

Fix in Cursor Fix in Web


@fretz12
Copy link
Contributor Author

fretz12 commented Dec 13, 2025

Bug: UseExisting policy returns incorrect Started=true for existing activity

When ACTIVITY_ID_CONFLICT_POLICY_USE_EXISTING is used and an activity with the same ID already exists, the response incorrectly returns Started: true. The callback that creates the response with Started: true is always executed, even when the engine returns an existing activity via the UseExisting conflict policy. Per the established convention (seen in workflow's similar USE_EXISTING behavior in telemetry tests), Started should be false when returning an existing execution rather than creating a new one. This could mislead callers into thinking a new activity was started when it wasn't.

chasm/lib/activity/handler.go#L68-L84

},
func(mutableContext chasm.MutableContext, request *workflowservice.StartActivityExecutionRequest) (*Activity, *workflowservice.StartActivityExecutionResponse, error) {
newActivity, err := NewStandaloneActivity(mutableContext, request)
if err != nil {
return nil, nil, err
}
err = TransitionScheduled.Apply(newActivity, mutableContext, nil)
if err != nil {
return nil, nil, err
}
return newActivity, &workflowservice.StartActivityExecutionResponse{
Started: true,
// EagerTask: TODO when supported, need to call the same code that would handle the HandleStarted API
}, nil
},

Fix in Cursor Fix in Web

That behavior would seem confusing as the activity is in Started state. WHere are you deducing this for workflows? Give me evidence

StartToCloseTimeout: durationpb.New(1 * time.Minute),
IdConflictPolicy: enumspb.ACTIVITY_ID_CONFLICT_POLICY_USE_EXISTING,
})
require.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should check that the returned runID is the same as the first one, and that started is false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added runID assertion.
As discussed, added a TODO. We need a way for chasm engine to tell us execution is already created. I'll dig through the code and ping chasm crew

Copy link
Contributor

@dandavison dandavison left a comment

Choose a reason for hiding this comment

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

Approved with that suggestion to change the error and some minor comments.

@fretz12 fretz12 merged commit 1da738f into standalone-activity Dec 17, 2025
55 of 57 checks passed
@fretz12 fretz12 deleted the saa-id-policy-enhance branch December 17, 2025 20:37
dandavison pushed a commit that referenced this pull request Dec 19, 2025
## What changed?
Added support for ID conflict use existing. Added error details on
conflict policy fail.

## Why?
We now have the use existing policy support on chasm engine, so we can
support it. Also need to pass back error details on conflict policy fail
in struct ActivityExecutionAlreadyStartedError

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

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> <sup>[Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) is
generating a summary for commit
f264bba. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
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