Files
Long TranandGitHub 1224e4d0cd Propagate backlinks on Signal and Signal-with-Start responses (#9897)
## What changed?

### **High level**

With https://github.com/temporalio/api/pull/761 to add the linking on
the Signal and Signal-with-Start responses, This PR adds logic from the
server that:
* Adds `requestID` from Signal and Signal-with-Start requests to the
CHASM workflow tree under a new map field `IncomingSignals`, and event
store, so these requestIDs stay in buffer
* Return a backlink in the response that references the `requestID`
* On buffer flush to the DB transaction, attach these `requestID` to a
concrete `eventID`, which would allow users to later know which event
correlated w/ this request. We will wire the concrete event ID to the
signal request IDs stored in the workflow component CHASM tree
(`IncomingSignals` map)

> [!NOTE]
> Feature is gated behind a new dynamicconfig
`EnableCHASMSignalBacklinks`, which implicitly is only checked if
`EnableChasm` is enabled.

## Why?

This will enable the caller of the signal to have a backlink to the
cross-namespace signal invoked, which will become more relevant for
Nexus SDK ergonomics.

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

In functional tests, I augmented existing tests for Signal and
Signal-with-Start to:
* Ensure that backlink is returned via the responses
* Later use `DescribeWorkflow` to ensure that we get a concrete EventID
(mapped when buffer flushed)
* Multiple signals with the same `requestID` gets de-duped

```
$ go test ./tests/ -run TestLinksTestSuite
ok      go.temporal.io/server/tests     1.486s
```

```
$ go test ./tests/ -run 'TestNexusWorkflowTestSuite' -count=1
ok      go.temporal.io/server/tests     4.714s
```

## Potential risks

Need to test end-to-end to see that the link shows up correctly in the
Web UI.

Feature is gated behind dynamicconfig since it requires CHASM-based
workflow to be enabled.
2026-05-15 13:05:55 -04:00

108 lines
3.6 KiB
Go

package signalwithstartworkflow
import (
"context"
enumspb "go.temporal.io/api/enums/v1"
"go.temporal.io/api/serviceerror"
"go.temporal.io/server/api/historyservice/v1"
"go.temporal.io/server/api/matchingservice/v1"
"go.temporal.io/server/common/definition"
"go.temporal.io/server/common/locks"
"go.temporal.io/server/common/metrics"
"go.temporal.io/server/common/namespace"
"go.temporal.io/server/common/worker_versioning"
"go.temporal.io/server/service/history/api"
historyi "go.temporal.io/server/service/history/interfaces"
)
func Invoke(
ctx context.Context,
signalWithStartRequest *historyservice.SignalWithStartWorkflowExecutionRequest,
shard historyi.ShardContext,
workflowConsistencyChecker api.WorkflowConsistencyChecker,
matchingClient matchingservice.MatchingServiceClient,
versionCache worker_versioning.VersionMembershipAndReactivationStatusCache,
reactivationSignaler api.VersionReactivationSignalerFn,
) (_ *historyservice.SignalWithStartWorkflowExecutionResponse, retError error) {
namespaceEntry, err := api.GetActiveNamespace(shard, namespace.ID(signalWithStartRequest.GetNamespaceId()), signalWithStartRequest.SignalWithStartRequest.WorkflowId)
if err != nil {
return nil, err
}
namespaceID := namespaceEntry.ID()
var currentWorkflowLease api.WorkflowLease
currentWorkflowLease, err = workflowConsistencyChecker.GetWorkflowLease(
ctx,
nil,
definition.NewWorkflowKey(
string(namespaceID),
signalWithStartRequest.SignalWithStartRequest.WorkflowId,
"",
),
locks.PriorityHigh,
)
switch err.(type) {
case nil:
defer func() { currentWorkflowLease.GetReleaseFn()(retError) }()
case *serviceerror.NotFound:
currentWorkflowLease = nil
default:
return nil, err
}
startRequest := ConvertToStartRequest(
namespaceID,
signalWithStartRequest.SignalWithStartRequest,
shard.GetTimeSource().Now(),
)
request := startRequest.StartRequest
api.MigrateWorkflowIDReusePolicyForRunningWorkflow(
&signalWithStartRequest.SignalWithStartRequest.WorkflowIdReusePolicy,
&signalWithStartRequest.SignalWithStartRequest.WorkflowIdConflictPolicy)
api.OverrideStartWorkflowExecutionRequest(request, metrics.HistorySignalWithStartWorkflowExecutionScope, shard, shard.GetMetricsHandler())
err = api.ValidateStartWorkflowExecutionRequest(ctx, request, shard, namespaceEntry, "SignalWithStartWorkflowExecution")
if err != nil {
return nil, err
}
// Validation for versioning override, if any.
shouldSkipReactivation, revisionNumber, err := worker_versioning.ValidateVersioningOverrideAndGetReactivationEligibility(ctx, request.GetVersioningOverride(), matchingClient, versionCache, request.GetTaskQueue().GetName(), enumspb.TASK_QUEUE_TYPE_WORKFLOW, namespaceID.String())
if err != nil {
return nil, err
}
runID, started, err := SignalWithStartWorkflow(
ctx,
shard,
namespaceEntry,
currentWorkflowLease,
startRequest,
signalWithStartRequest.SignalWithStartRequest,
)
if err != nil {
return nil, err
}
// Notify version workflow if we're starting a new workflow pinned to a potentially drained version
if started {
api.ReactivateVersionWorkflowIfPinned(ctx, namespaceEntry, request.GetVersioningOverride(), reactivationSignaler, shard.GetConfig().EnableVersionReactivationSignals(), shouldSkipReactivation, revisionNumber)
}
swr := signalWithStartRequest.SignalWithStartRequest
return &historyservice.SignalWithStartWorkflowExecutionResponse{
RunId: runID,
Started: started,
SignalLink: api.GenerateRequestIDRefLink(
swr.GetNamespace(),
swr.GetWorkflowId(),
runID,
swr.GetRequestId(),
enumspb.EVENT_TYPE_WORKFLOW_EXECUTION_SIGNALED,
),
}, nil
}