{"record":{"id":"36a040a2c748daa8","repo":"temporalio/temporal","slug":"completion-token-has-no-operation-state-machine-re","errorCode":null,"errorMessage":"completion token has no operation state machine reference","messagePattern":"completion token has no operation state machine reference","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nexusworkflowref/nexusworkflowref.go","lineNumber":145,"sourceCode":"\t\t\tMachineInitialVersionedTransition:    &persistencespb.VersionedTransition{},\n\t\t\tMachineLastUpdateVersionedTransition: &persistencespb.VersionedTransition{},\n\t\t},\n\t\tRequestId: id.requestID,\n\t}\n}\n\nfunc scheduledEventIDFromHSMRef(ref *persistencespb.StateMachineRef) (int64, error) {\n\tfor _, key := range ref.GetPath() {\n\t\tif key.GetType() != nexusoperations.OperationMachineType {\n\t\t\tcontinue\n\t\t}\n\t\tscheduledEventID, err := strconv.ParseInt(key.GetId(), 10, 64)\n\t\tif err != nil {\n\t\t\treturn 0, fmt.Errorf(\"invalid operation state machine id %q: %w\", key.GetId(), err)\n\t\t}\n\t\treturn scheduledEventID, nil\n\t}\n\treturn 0, errors.New(\"completion token has no operation state machine reference\")\n}\n\nfunc scheduledEventIDFromComponentPath(path []string) (int64, error) {\n\tif len(path) != 2 || path[0] != operationsFieldName {\n\t\treturn 0, fmt.Errorf(\"unexpected nexus operation component path %v\", path)\n\t}\n\tscheduledEventID, err := strconv.ParseInt(path[1], 10, 64)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"invalid scheduled event id %q: %w\", path[1], err)\n\t}\n\treturn scheduledEventID, nil\n}\n","sourceCodeStart":127,"sourceCodeEnd":158,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/nexusworkflowref/nexusworkflowref.go#L127-L158","documentation":"Raised by scheduledEventIDFromHSMRef when a Nexus completion token's payload contains no operation state machine reference (the ref's key or type is not an HSM machine reference), so the scheduled event ID cannot be extracted. Callers like identityFromHSM need this ID to build the workflow identity for completing an operation.","triggerScenarios":"Completing/canceling a Nexus operation with a completion token that was not generated from an HSM operation reference - e.g. a malformed, hand-crafted, or from-an-older-version token whose Ref/ComponentRef is absent.","commonSituations":"Worker or custom code constructing completion tokens manually, tokens persisted before the HSM-based operation tracking was introduced, or copying tokens between workflows/namespaces.","solutions":["Regenerate the completion token from the Nexus operation task/start response rather than constructing it manually","Verify the token originates from the same workflow run that scheduled the operation","Check server versions: tokens from pre-HSM server versions are incompatible; fail over or re-run the operation","Inspect the token's ref fields - ensure the state machine key ID is present and parses as an int64 scheduled event ID"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before using a completion token, verify it carries an HSM ref:\nif token.GetRef() == nil || token.GetRef().GetStateMachines() == nil || len(token.GetRef().GetStateMachines().GetComponent()) == 0 {\n    return errors.New(\"token missing operation state machine reference\")\n}","typeGuard":"func hasHSMRef(t *nexuspb.CompletionToken) bool {\n  return t != nil && t.GetRef() != nil && t.GetRef().GetStateMachines() != nil && t.GetRef().GetStateMachines().GetId() != \"\"\n}","tryCatchPattern":null,"preventionTips":["Always source completion tokens from the framework-generated task/start responses","Never construct or hand-edit completion tokens","Fail over tokens across server versions only after verifying compatibility"],"tags":["nexus","completion-token","hsm","temporal-server"],"backgroundTag":"invalid-operation-completion-token","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}