dify icon indicating copy to clipboard operation
dify copied to clipboard

Run failed: Node Code Execution run failed: Failed to parse result

Open majestichou opened this issue 1 year ago • 8 comments

Self Checks

  • [X] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [X] I have searched for existing issues search for existing issues, including closed ones.
  • [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • [X] Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.15

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I started dify version 0.6.15 with docker. I set the environment variable for the code node. Run the following command to check the environment variables of the sanbox container:

[root@cturf165 docker]# docker exec -it docker-sandbox-1 env
PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=831f3c73466a
TERM=xterm
SANDBOX_PORT=8194
CODE_MAX_NUMBER_ARRAY_LENGTH=10000000
TEMPLATE_TRANSFORM_MAX_LENGTH=80000000
CODE_MAX_STRING_LENGTH=80000000
HTTPS_PROXY=http://ssrf_proxy:3128
CODE_MAX_NUMBER=922337203685477580700
CODE_MAX_STRING_ARRAY_LENGTH=300000
ENABLE_NETWORK=true
CODE_MAX_OBJECT_ARRAY_LENGTH=300000
CODE_MIN_NUMBER=-922337203685477580800
WORKER_TIMEOUT=15
API_KEY=dify-sandbox
GIN_MODE=release
HTTP_PROXY=http://ssrf_proxy:3128
LANG=C.UTF-8
GPG_KEY=A035C8C19219BA821ECEA86B64E628F8D684696D
PYTHON_VERSION=3.10.14
PYTHON_PIP_VERSION=23.0.1
PYTHON_SETUPTOOLS_VERSION=65.5.1
PYTHON_GET_PIP_URL=https://github.com/pypa/get-pip/raw/e03e1607ad60522cf34a92e834138eb89f57667c/public/get-pip.py
PYTHON_GET_PIP_SHA256=ee09098395e42eb1f82ef4acb231a767a6ae85504a9cf9983223df0a7cbd35d7
HOME=/root

I built an app using chatflow and the content of its DSL file named "test.yml" is as follows:

app:
  description: ''
  icon: "\U0001F916"
  icon_background: '#FFEAD5'
  mode: advanced-chat
  name: test
kind: app
version: 0.1.0
workflow:
  environment_variables: []
  features:
    file_upload:
      image:
        enabled: false
        number_limits: 3
        transfer_methods:
        - local_file
        - remote_url
    opening_statement: ''
    retriever_resource:
      enabled: true
    sensitive_word_avoidance:
      enabled: false
    speech_to_text:
      enabled: false
    suggested_questions: []
    suggested_questions_after_answer:
      enabled: false
    text_to_speech:
      enabled: false
      language: ''
      voice: ''
  graph:
    edges:
    - data:
        isInIteration: false
        sourceType: code
        targetType: iteration
      id: 1722480460067-source-1722488343394-target
      source: '1722480460067'
      sourceHandle: source
      target: '1722488343394'
      targetHandle: target
      type: custom
      zIndex: 0
    - data:
        isInIteration: true
        iteration_id: '1722488343394'
        sourceType: code
        targetType: answer
      id: 1722488455130-source-1722488502069-target
      source: '1722488455130'
      sourceHandle: source
      target: '1722488502069'
      targetHandle: target
      type: custom
      zIndex: 1002
    - data:
        isInIteration: false
        sourceType: start
        targetType: code
      id: 1722480438479-source-1722480460067-target
      source: '1722480438479'
      sourceHandle: source
      target: '1722480460067'
      targetHandle: target
      type: custom
      zIndex: 0
    nodes:
    - data:
        desc: ''
        selected: false
        title: "\u5F00\u59CB"
        type: start
        variables: []
      height: 54
      id: '1722480438479'
      position:
        x: 282
        y: 282
      positionAbsolute:
        x: 282
        y: 282
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        code: "def main() -> dict:\n    original_strings_with_empty = [\"apple\",\
          \ \"\", \"cherry\", \"date\", \"\", \"fig\", \"grape\", \"honeydew\", \"\
          kiwi\", \"\", \"mango\", \"nectarine\", \"orange\", \"papaya\", \"quince\"\
          , \"raspberry\", \"strawberry\", \"tangerine\", \"ugli fruit\", \"vanilla\
          \ bean\", \"watermelon\", \"xigua\", \"yellow passionfruit\", \"zucchini\"\
          ] * 5\n\n    # \u6269\u5C55\u6BCF\u4E2A\u5B57\u7B26\u4E32\u52303000\u4E2A\
          \u5B57\u7B26\uFF0C\u901A\u8FC7\u91CD\u590D\u539F\u59CB\u5B57\u7B26\u4E32\
          \u7684\u5B57\u7B26\n    extended_strings = []\n\n    for s in original_strings_with_empty:\n\
          \        if s:  # \u68C0\u67E5\u5B57\u7B26\u4E32\u662F\u5426\u975E\u7A7A\
          \n            # \u8BA1\u7B97\u9700\u8981\u91CD\u590D\u7684\u6B21\u6570\uFF0C\
          \u4F7F\u7528ceil\u51FD\u6570\u786E\u4FDD\u957F\u5EA6\u81F3\u5C11\u4E3A3000\n\
          \            repeat_times = 600\n            # \u91CD\u590D\u5B57\u7B26\u4E32\
          \u5E76\u5207\u7247\u4EE5\u786E\u4FDD\u957F\u5EA6\u6B63\u597D\u4E3A3000\n\
          \            extended_s = (s * repeat_times)[:2000]\n            extended_strings.append(extended_s)\n\
          \        else:\n            # \u5982\u679C\u5B57\u7B26\u4E32\u4E3A\u7A7A\
          \uFF0C\u8FD9\u91CC\u5047\u8BBE\u4E0D\u5904\u7406\u7A7A\u5B57\u7B26\u4E32\
          \uFF0C\u76F4\u63A5\u4FDD\u6301\u4E3A\u7A7A\n            extended_strings.append(s)\
          \ \n    \n    return {\n        \"result\": extended_strings,\n    }"
        code_language: python3
        desc: ''
        outputs:
          result:
            children: null
            type: array[string]
        selected: false
        title: "\u4EE3\u7801\u6267\u884C"
        type: code
        variables: []
      height: 54
      id: '1722480460067'
      position:
        x: 680
        y: 282
      positionAbsolute:
        x: 680
        y: 282
      selected: true
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
    - data:
        desc: ''
        height: 209
        iterator_selector:
        - '1722480460067'
        - result
        output_selector:
        - '1722488455130'
        - result
        output_type: array[string]
        selected: false
        startNodeType: code
        start_node_id: '1722488455130'
        title: "\u8FED\u4EE3"
        type: iteration
        width: 681
      height: 209
      id: '1722488343394'
      position:
        x: 962
        y: 282
      positionAbsolute:
        x: 962
        y: 282
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 681
      zIndex: 1
    - data:
        code: "\ndef main(arg1: str) -> dict:\n    return {\n        \"result\": arg1,\n\
          \    }\n"
        code_language: python3
        desc: ''
        isInIteration: true
        isIterationStart: true
        iteration_id: '1722488343394'
        outputs:
          result:
            children: null
            type: string
        selected: false
        title: "\u4EE3\u7801\u6267\u884C 2"
        type: code
        variables:
        - value_selector:
          - '1722488343394'
          - item
          variable: arg1
      extent: parent
      height: 54
      id: '1722488455130'
      parentId: '1722488343394'
      position:
        x: 117
        y: 85
      positionAbsolute:
        x: 1079
        y: 367
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
      zIndex: 1001
    - data:
        answer: '

          {{#1722488455130.result#}}'
        desc: ''
        isInIteration: true
        iteration_id: '1722488343394'
        selected: false
        title: "\u76F4\u63A5\u56DE\u590D"
        type: answer
        variables: []
      extent: parent
      height: 107
      id: '1722488502069'
      parentId: '1722488343394'
      position:
        x: 421
        y: 85
      positionAbsolute:
        x: 1383
        y: 367
      selected: false
      sourcePosition: right
      targetPosition: left
      type: custom
      width: 244
      zIndex: 1002
    viewport:
      x: -650.5
      y: 62
      zoom: 1

The code of Code Execution Node 1 is as follows:

def main() -> dict:
    original_strings_with_empty = ["apple", "", "cherry", "date", "", "fig", "grape", "honeydew", "kiwi", "", "mango", "nectarine", "orange", "papaya", "quince", "raspberry", "strawberry", "tangerine", "ugli fruit", "vanilla bean", "watermelon", "xigua", "yellow passionfruit", "zucchini"] * 5


    extended_strings = []

    for s in original_strings_with_empty:
        if s: 
            repeat_times = 600
            extended_s = (s * repeat_times)[:3000]
            extended_strings.append(extended_s)
        else:
            extended_strings.append(s) 
    
    return {
        "result": extended_strings,
    }

And then I run the app. The app crashes. The error message is as follows:

Run failed: Node Code Execution run failed: Failed to parse result

Then I change the code of Code Execution Node 1 to set the character length to 2000.

def main() -> dict:
    original_strings_with_empty = ["apple", "", "cherry", "date", "", "fig", "grape", "honeydew", "kiwi", "", "mango", "nectarine", "orange", "papaya", "quince", "raspberry", "strawberry", "tangerine", "ugli fruit", "vanilla bean", "watermelon", "xigua", "yellow passionfruit", "zucchini"] * 5


    extended_strings = []

    for s in original_strings_with_empty:
        if s:  
            repeat_times = 600

            extended_s = (s * repeat_times)[:2000]
            extended_strings.append(extended_s)
        else:

            extended_strings.append(s) 
    
    return {
        "result": extended_strings,
    }

The application is running properly.

Then I change the code of Code Execution Node 1 to make the original_strings_with_empty have less elements.

def main() -> list:
    original_strings_with_empty = ["apple", "", "cherry", "date", "", "fig", "grape", "honeydew", "kiwi", "", "mango", "nectarine", "orange", "papaya"] * 5

    extended_strings = []

    for s in original_strings_with_empty:
        if s:  
            repeat_times = 600
            extended_s = (s * repeat_times)[:3000]
            extended_strings.append(extended_s)
        else:
            extended_strings.append(s) 
    
    return {
        "result": extended_strings,
    }

The application is also running properly.

According to my understanding, I have configured the environment variables correctly, but the application still reports an error. It cannot handle a string array with more than 3000 elements per string.

✔️ Expected Behavior

The application is running properly.

❌ Actual Behavior

Run failed: Node Code Execution run failed: Failed to parse result

majestichou avatar Aug 01 '24 05:08 majestichou

The error message "Run failed: Node 代码执行 run failed: Failed to parse result" when handling a string array with more than 3000 elements per string is likely due to the limitations in the code execution environment of the Dify app. Despite configuring the environment variables, the code execution environment has specific constraints on the size of data structures, including string arrays.

The environment variables CODE_MAX_STRING_LENGTH and CODE_MAX_STRING_ARRAY_LENGTH are set to limit the maximum length of a string and the maximum number of strings in an array, respectively. Specifically, CODE_MAX_STRING_LENGTH is set to 80000 characters, and CODE_MAX_STRING_ARRAY_LENGTH is set to 300000 elements. However, the actual execution environment may still impose practical limits that cause the code to fail when these limits are approached.

To resolve this issue, you should consider breaking down your string array into smaller chunks that comply with the environment's limitations. This can be done by processing the array in smaller segments and then combining the results as needed. Here is an example of how you might handle this in Python:

def process_large_array(large_array):
    chunk_size = 1000  # Define a chunk size that is manageable
    results = []
    
    for i in range(0, len(large_array), chunk_size):
        chunk = large_array[i:i + chunk_size]
        # Process each chunk
        result = process_chunk(chunk)
        results.append(result)
    
    # Combine results if necessary
    final_result = combine_results(results)
    return final_result

def process_chunk(chunk):
    # Your processing logic here
    return chunk

def combine_results(results):
    # Logic to combine results
    return results

By processing the array in smaller chunks, you can avoid hitting the resource limits of the sandboxed environment and prevent the app from crashing [1][2][3][4].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Aug 01 '24 05:08 dosubot[bot]

Could you take a look at this one @Yeuoly

crazywoola avatar Aug 02 '24 06:08 crazywoola

In the template_transformer.py file of the dify source code, there is a function named extract_result_str_from_response. Debugging the code that triggers the Run failed: Node Code Execution run failed: Failed to parse result error. It is found that the input parameter response format of extract_result_str_from_response is incorrect.

The incorrect response is as follows:

<<RESULT>>{
    "result": [
        "appleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleappleapple",
      ................................................ (A lot of content is omitted here for simplicity)
        "ugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruitugli fruit",
        "vanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla beanvanilla bea

As you can see, the content of the response variable is not complete, there is no << RESULT >> at the end, and the content of "result": is also incomplete.

The content of the response variable is obtained by the following statement response = post(str(url), json=data, headers=headers, timeout=CODE_EXECUTION_TIMEOUT)

I run the preceding test code in the dify-sandbox-1 container. The code is all working fine. So I think that maybe the POST request is truncated.

majestichou avatar Aug 02 '24 09:08 majestichou

Thanks for reporting this, it looks like the response content is incomplete, I will check it soon, or have you already got any idea of how to fix it?

Yeuoly avatar Aug 02 '24 16:08 Yeuoly

Thanks for report this, it looks like the response content is incomplete, I will check it soon, or have you already got any idea of how to fix it?

I haven't found the root cause yet, why truncation is triggered. I don’t know if it’s due to Nginx or post or the dify code bug.

majestichou avatar Aug 02 '24 16:08 majestichou

Thanks for reporting this, it looks like the response content is incomplete, I will check it soon, or have you already got any idea of how to fix it?

A few words to add, the following code sometimes triggers an error, and sometimes it doesn’t. This is also very magical.

def main() -> dict:
    original_strings_with_empty = ["apple", "", "cherry", "date", "", "fig", "grape", "honeydew", "kiwi", "", "mango", "nectarine", "orange", "papaya", "quince", "raspberry", "strawberry", "tangerine", "ugli fruit", "vanilla bean", "watermelon", "xigua", "yellow passionfruit", "zucchini"] * 5


    extended_strings = []

    for s in original_strings_with_empty:
        if s: 
            repeat_times = 600
            extended_s = (s * repeat_times)[:3000]
            extended_strings.append(extended_s)
        else:
            extended_strings.append(s) 
    
    return {
        "result": extended_strings,
    }

I also reproduced this bug using the online version of dify official website

majestichou avatar Aug 02 '24 16:08 majestichou

Thanks for reporting this, it looks like the response content is incomplete, I will check it soon, or have you already got any idea of how to fix it?

A few words to add, the following code sometimes triggers an error, and sometimes it doesn’t. This is also very magical.

def main() -> dict:
    original_strings_with_empty = ["apple", "", "cherry", "date", "", "fig", "grape", "honeydew", "kiwi", "", "mango", "nectarine", "orange", "papaya", "quince", "raspberry", "strawberry", "tangerine", "ugli fruit", "vanilla bean", "watermelon", "xigua", "yellow passionfruit", "zucchini"] * 5


    extended_strings = []

    for s in original_strings_with_empty:
        if s: 
            repeat_times = 600
            extended_s = (s * repeat_times)[:3000]
            extended_strings.append(extended_s)
        else:
            extended_strings.append(s) 
    
    return {
        "result": extended_strings,
    }

I also reproduced this bug using the online version of dify official website

I have reproduced it successfully, but not only this, I also encountered an operation not permitted error, I guess it should be a memory optimization issue, will fix it soon in 0.2.5.

Yeuoly avatar Aug 02 '24 16:08 Yeuoly

@Yeuoly Thanks a lot. Looking forward to the next version

majestichou avatar Aug 02 '24 16:08 majestichou

Thanks for reporting this, it looks like the response content is incomplete, I will check it soon, or have you already got any idea of how to fix it?

A few words to add, the following code sometimes triggers an error, and sometimes it doesn’t. This is also very magical.

def main() -> dict:
    original_strings_with_empty = ["apple", "", "cherry", "date", "", "fig", "grape", "honeydew", "kiwi", "", "mango", "nectarine", "orange", "papaya", "quince", "raspberry", "strawberry", "tangerine", "ugli fruit", "vanilla bean", "watermelon", "xigua", "yellow passionfruit", "zucchini"] * 5


    extended_strings = []

    for s in original_strings_with_empty:
        if s: 
            repeat_times = 600
            extended_s = (s * repeat_times)[:3000]
            extended_strings.append(extended_s)
        else:
            extended_strings.append(s) 
    
    return {
        "result": extended_strings,
    }

I also reproduced this bug using the online version of dify official website

I have reproduced it successfully, but not only this, I also encountered an operation not permitted error, I guess it should be a memory optimization issue, will fix it soon in 0.2.5.

When will the update to version 0.2.5 be released? @Yeuoly

leoterry-ulrica avatar Aug 14 '24 09:08 leoterry-ulrica

Resolved https://github.com/langgenius/dify-sandbox/pull/41

Yeuoly avatar Aug 19 '24 10:08 Yeuoly

@majestichou I solved it, and your test case has been added to CI, thanks so much for your contributions!

Yeuoly avatar Aug 19 '24 10:08 Yeuoly