Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda Timeout issues with new ai.conversation() #2356

Open
cabcookie opened this issue Dec 12, 2024 · 3 comments
Open

Lambda Timeout issues with new ai.conversation() #2356

cabcookie opened this issue Dec 12, 2024 · 3 comments
Labels
ai-kit Issues related to Amplify AI Kit feature-request New feature or request pending-maintainer-response Issue is pending a response from the Amplify team

Comments

@cabcookie
Copy link

Environment information

System:
  OS: macOS 14.7.1
  CPU: (10) arm64 Apple M1 Pro
  Memory: 120.83 MB / 32.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 18.19.0 - ~/.nvm/versions/node/v18.19.0/bin/node
  Yarn: 1.22.22 - ~/.nvm/versions/node/v18.19.0/bin/yarn
  npm: 10.8.3 - ~/.nvm/versions/node/v18.19.0/bin/npm
  pnpm: 9.12.3 - ~/.nvm/versions/node/v18.19.0/bin/pnpm
NPM Packages:
  @aws-amplify/auth-construct: 1.5.1
  @aws-amplify/backend: 1.9.0
  @aws-amplify/backend-auth: 1.4.2
  @aws-amplify/backend-cli: 1.4.3
  @aws-amplify/backend-data: 1.2.2
  @aws-amplify/backend-deployer: 1.1.11
  @aws-amplify/backend-function: 1.9.0
  @aws-amplify/backend-output-schemas: 1.4.0
  @aws-amplify/backend-output-storage: 1.1.4
  @aws-amplify/backend-secret: 1.1.5
  @aws-amplify/backend-storage: 1.2.4
  @aws-amplify/cli-core: 1.2.1
  @aws-amplify/client-config: 1.5.3
  @aws-amplify/deployed-backend-client: 1.4.2
  @aws-amplify/form-generator: 1.0.3
  @aws-amplify/model-generator: 1.0.9
  @aws-amplify/platform-core: 1.3.0
  @aws-amplify/plugin-types: 1.6.0
  @aws-amplify/sandbox: 1.2.7
  @aws-amplify/schema-generator: 1.2.6
  aws-amplify: 6.10.2
  aws-cdk: 2.172.0
  aws-cdk-lib: 2.172.0
  typescript: 5.7.2
No AWS environment variables
No CDK environment variables

Data packages

[email protected]
├─┬ @aws-amplify/[email protected]
│ └─┬ @aws-amplify/[email protected]
│   └── @aws-amplify/[email protected]
└─┬ @aws-amplify/[email protected]
  └─┬ @aws-amplify/[email protected]
    └── @aws-amplify/[email protected]

Description

I am making use of the new ai.conversation() feature in my data schema. I recognized that when the LLM is responding to my input, at some point it starts replacing the message. Reason for that is that there is a Lambda being created which handles the streamed content from the LLM and writes it to DynamoDB. However, the Lambda's timeout is set to 60 seconds and if the response is quiet long, it can take more than that to stream the full response. Thus the Lambda is invoked again and overwrites the initial message. I tried to find an option to extend the Lambda's timeout but I couldn't find one. How an I solve this issue?

Some CloudWatch Log output:

Handling conversation turn event, currentMessageId=8b71d956-79c3-49b6-bf9d-8206811b0752, conversationId=03c37cfe-d0a0-4a44-97a2-dd9d9bc63cd0
Sending Bedrock Converse Stream request
Received Bedrock Converse Stream response, requestId=99d83b55-2eba-4051-8ce3-cd8079fd533e
timeout durationMs: 60017.269 producedBytes: 0
durationMs: 60021.344, billedDurationMs: 60000, memorySizeMB: 512, maxMemoryUsedMB: 124
platform.initStart
platform.start
Handling conversation turn event, currentMessageId=0d9d5336-cf0a-4e2f-b241-499ab67fcaa6, conversationId=cdffbcef-fdf5-4841-892e-06cf1e93cf49
Sending Bedrock Converse Stream request
A conversation must alternate between user and assistant roles. Make sure the conversation alternates between user and assistant roles and try again.
ValidationException: A conversation must alternate between user and assistant roles. Make sure the conversation alternates between user and assistant roles and try again.
at de_ValidationExceptionRes (/var/runtime/node_modules/@aws-sdk/client-bedrock-runtime/dist-cjs/index.js:1195:21)
    at de_CommandError (/var/runtime/node_modules/@aws-sdk/client-bedrock-runtime/dist-cjs/index.js:1028:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /var/runtime/node_modules/@aws-sdk/node_modules/@smithy/middleware-serde/dist-cjs/index.js:35:20
    at async /var/runtime/node_modules/@aws-sdk/node_modules/@smithy/core/dist-cjs/index.js:165:18
    at async /var/runtime/node_modules/@aws-sdk/node_modules/@smithy/middleware-retry/dist-cjs/index.js:320:38
    at async /var/runtime/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:34:22
    at async BedrockConverseAdapter.askBedrockStreaming (/var/task/index.js:813:29)
    at async ConversationTurnExecutor.execute (/var/task/index.js:1009:32)
    at async Runtime.handleConversationTurnEvent [as handler] (/var/task/index.js:1043:7)
    A conversation must alternate between user and assistant roles. Make sure the conversation alternates between user and assistant roles and try again.
ValidationException: A conversation must alternate between user and assistant roles. Make sure the conversation alternates between user and assistant roles and try again.
at de_ValidationExceptionRes (/var/runtime/node_modules/@aws-sdk/client-bedrock-runtime/dist-cjs/index.js:1195:21)
    at de_CommandError (/var/runtime/node_modules/@aws-sdk/client-bedrock-runtime/dist-cjs/index.js:1028:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /var/runtime/node_modules/@aws-sdk/node_modules/@smithy/middleware-serde/dist-cjs/index.js:35:20
    at async /var/runtime/node_modules/@aws-sdk/node_modules/@smithy/core/dist-cjs/index.js:165:18
    at async /var/runtime/node_modules/@aws-sdk/node_modules/@smithy/middleware-retry/dist-cjs/index.js:320:38
    at async /var/runtime/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:34:22
    at async BedrockConverseAdapter.askBedrockStreaming (/var/task/index.js:813:29)
    at async ConversationTurnExecutor.execute (/var/task/index.js:1009:32)
    at async Runtime.handleConversationTurnEvent [as handler] (/var/task/index.js:1043:7)
    platform.report
durationMs: 895.652, billedDurationMs: 896, memorySizeMB: 512, maxMemoryUsedMB: 49
platform.start
Handling conversation turn event, currentMessageId=8b71d956-79c3-49b6-bf9d-8206811b0752, conversationId=03c37cfe-d0a0-4a44-97a2-dd9d9bc63cd0
Sending Bedrock Converse Stream request
Received Bedrock Converse Stream response, requestId=dc82200a-279f-4159-8a25-de3d758b8423
platform.report
durationMs: 60045.522, billedDurationMs: 60000, memorySizeMB: 512, maxMemoryUsedMB: 63
platform.initStart
platform.start
Handling conversation turn event, currentMessageId=8b71d956-79c3-49b6-bf9d-8206811b0752, conversationId=03c37cfe-d0a0-4a44-97a2-dd9d9bc63cd0
Sending Bedrock Converse Stream request
Received Bedrock Converse Stream response, requestId=17a95440-fc77-47e3-98a6-37256635701f
Conversation turn event handled successfully, currentMessageId=8b71d956-79c3-49b6-bf9d-8206811b0752, conversationId=03c37cfe-d0a0-4a44-97a2-dd9d9bc63cd0
platform.report
durationMs: 12305.726, billedDurationMs: 12306, memorySizeMB: 512, maxMemoryUsedMB: 58
@cabcookie cabcookie added the pending-triage Incoming issues that need categorization label Dec 12, 2024
@Siqi-Shan Siqi-Shan added pending-maintainer-response Issue is pending a response from the Amplify team and removed pending-triage Incoming issues that need categorization labels Dec 16, 2024
@Siqi-Shan
Copy link
Member

Hi @cabcookie, thanks for raising the issue! We'll investigate and see what's going on, and get back to you once we have a solution.

@atierian atierian transferred this issue from aws-amplify/amplify-category-api Dec 19, 2024
@atierian atierian added the ai-kit Issues related to Amplify AI Kit label Dec 19, 2024
@sobolk sobolk mentioned this issue Dec 19, 2024
4 tasks
@sobolk sobolk added the feature-request New feature or request label Dec 19, 2024
@sobolk
Copy link
Member

sobolk commented Dec 19, 2024

@cabcookie We added timeout here #2358 . Once we release this, you can use custom handler to configure timeout, see https://docs.amplify.aws/react/ai/conversation/tools/#custom-lambda-tools .

However, it seems that conversationId in the log you shared is different for the request that timed out and the one that threw validation exception. Therefore, we might be dealing with two separate problems here.

Would it be possible to share more logs, ideally with log level set to debug? We'd like to see all logs that belong to conversationId which failed with validation exception.

@cabcookie
Copy link
Author

I ran a prompt that created a long response again. I am using the standard handler Amplify creates. As I use the standard handler, I can't adjust the timeout time. I can do so for a custom handler after the change you mentioned. However, I tried to use a custom handler because of the issues with the standard handler. However, I ran into other issues with a custom handler as well. Which I will highlight in a separate issue.

Now, back to the standard handler issue. Here are the logs:


Event Time Message
2024-12-21T14:36:59.003Z {"time":"2024-12-21T14:36:59.003Z","type":"platform.start","record":{"requestId":"ac6a0530-3abe-46b9-b6e9-2e3fb6dcf0cf","version":"$LATEST"}}
2024-12-21T14:36:59.004Z {"timestamp":"2024-12-21T14:36:59.004Z","level":"INFO","requestId":"ac6a0530-3abe-46b9-b6e9-2e3fb6dcf0cf","message":"Handling conversation turn event, currentMessageId=cdc53fde-6b05-4e5b-a2d3-b13a1f308eb3, conversationId=c6192a07-8df3-4bff-b87b-3fbb4346fd97"}
2024-12-21T14:36:59.262Z {"timestamp":"2024-12-21T14:36:59.262Z","level":"INFO","requestId":"ac6a0530-3abe-46b9-b6e9-2e3fb6dcf0cf","message":"Sending Bedrock Converse Stream request"}
2024-12-21T14:36:59.402Z {"timestamp":"2024-12-21T14:36:59.402Z","level":"INFO","requestId":"ac6a0530-3abe-46b9-b6e9-2e3fb6dcf0cf","message":"Received Bedrock Converse Stream response, requestId=05df2fcd-5368-4e33-a404-2ed83f8e61bd"}
2024-12-21T14:37:59.020Z {"time":"2024-12-21T14:37:59.020Z","type":"platform.runtimeDone","record":{"requestId":"ac6a0530-3abe-46b9-b6e9-2e3fb6dcf0cf","status":"timeout","metrics":{"durationMs":60016.92,"producedBytes":0}}}
2024-12-21T14:37:59.024Z {"time":"2024-12-21T14:37:59.024Z","type":"platform.report","record":{"requestId":"ac6a0530-3abe-46b9-b6e9-2e3fb6dcf0cf","metrics":{"durationMs":60021.082,"billedDurationMs":60000,"memorySizeMB":512,"maxMemoryUsedMB":124},"status":"timeout"}}
2024-12-21T14:37:59.050Z {"time":"2024-12-21T14:37:59.050Z","type":"platform.initStart","record":{"initializationType":"on-demand","phase":"init","runtimeVersion":"nodejs:18.v57","runtimeVersionArn":"arn:aws:lambda:us-east-1::runtime:8865cfc6a1d3f2dfabf5c509eaa9fbd70aa12fa4bbe614047030158c21978bcc","functionName":"amplify-personalcrm-carsk-GeneralChatDefaultConver-spp2BdxbwWuH","functionVersion":"$LATEST"}}
2024-12-21T14:39:06.245Z {"time":"2024-12-21T14:39:06.245Z","type":"platform.start","record":{"requestId":"ac6a0530-3abe-46b9-b6e9-2e3fb6dcf0cf","version":"$LATEST"}}
2024-12-21T14:39:06.259Z {"timestamp":"2024-12-21T14:39:06.259Z","level":"INFO","requestId":"ac6a0530-3abe-46b9-b6e9-2e3fb6dcf0cf","message":"Handling conversation turn event, currentMessageId=cdc53fde-6b05-4e5b-a2d3-b13a1f308eb3, conversationId=c6192a07-8df3-4bff-b87b-3fbb4346fd97"}
2024-12-21T14:39:06.999Z {"timestamp":"2024-12-21T14:39:06.999Z","level":"INFO","requestId":"ac6a0530-3abe-46b9-b6e9-2e3fb6dcf0cf","message":"Sending Bedrock Converse Stream request"}
2024-12-21T14:39:07.259Z {"timestamp":"2024-12-21T14:39:07.259Z","level":"INFO","requestId":"ac6a0530-3abe-46b9-b6e9-2e3fb6dcf0cf","message":"Received Bedrock Converse Stream response, requestId=f323f343-d7b4-46f7-bc79-a42f7b7e345a"}
2024-12-21T14:40:06.307Z {"time":"2024-12-21T14:40:06.307Z","type":"platform.runtimeDone","record":{"requestId":"ac6a0530-3abe-46b9-b6e9-2e3fb6dcf0cf","status":"timeout","metrics":{"durationMs":60061.306,"producedBytes":0}}}
2024-12-21T14:40:06.318Z {"time":"2024-12-21T14:40:06.318Z","type":"platform.report","record":{"requestId":"ac6a0530-3abe-46b9-b6e9-2e3fb6dcf0cf","metrics":{"durationMs":60073.09,"billedDurationMs":60000,"memorySizeMB":512,"maxMemoryUsedMB":58},"status":"timeout"}}
2024-12-21T14:40:06.340Z {"time":"2024-12-21T14:40:06.340Z","type":"platform.initStart","record":{"initializationType":"on-demand","phase":"init","runtimeVersion":"nodejs:18.v57","runtimeVersionArn":"arn:aws:lambda:us-east-1::runtime:8865cfc6a1d3f2dfabf5c509eaa9fbd70aa12fa4bbe614047030158c21978bcc","functionName":"amplify-personalcrm-carsk-GeneralChatDefaultConver-spp2BdxbwWuH","functionVersion":"$LATEST"}}

I upgraded my dependencies to the following versions:

@aws-amplify/backend: 1.11.0
@aws-amplify/backend-cli: 1.4.5
@aws-amplify/backend-data: 1.3.0
@aws-amplify/backend-deployer: 1.1.12
@aws-amplify/backend-function: 1.10.0
@aws-amplify/client-config: 1.5.4
@aws-amplify/deployed-backend-client: 1.5.0
@aws-amplify/model-generator: 1.0.11
@aws-amplify/platform-core: 1.4.0
@aws-amplify/sandbox: 1.2.8
aws-amplify: 6.11.0
aws-cdk: 2.173.2
aws-cdk-lib: 2.173.2

Afterwards I ran the prompt again. The problem is still there and here are the logs for that run:


Event Time Message
2024-12-21T14:59:53.844Z {"time":"2024-12-21T14:59:53.844Z","type":"platform.initStart","record":{"initializationType":"on-demand","phase":"init","runtimeVersion":"nodejs:18.v57","runtimeVersionArn":"arn:aws:lambda:us-east-1::runtime:8865cfc6a1d3f2dfabf5c509eaa9fbd70aa12fa4bbe614047030158c21978bcc","functionName":"amplify-personalcrm-carsk-GeneralChatDefaultConver-spp2BdxbwWuH","functionVersion":"$LATEST"}}
2024-12-21T15:00:29.856Z {"time":"2024-12-21T15:00:29.856Z","type":"platform.start","record":{"requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","version":"$LATEST"}}
2024-12-21T15:00:29.862Z {"timestamp":"2024-12-21T15:00:29.862Z","level":"INFO","requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","message":"Handling conversation turn event, currentMessageId=ed58dfff-d9f6-49b5-8051-398043625158, conversationId=2758ff17-d49f-439e-ae97-06a38a5c7c94"}
2024-12-21T15:00:30.401Z {"timestamp":"2024-12-21T15:00:30.401Z","level":"INFO","requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","message":"Sending Bedrock Converse Stream request"}
2024-12-21T15:00:30.642Z {"timestamp":"2024-12-21T15:00:30.642Z","level":"INFO","requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","message":"Received Bedrock Converse Stream response, requestId=d87bdd05-ee4a-41cf-bd7f-fa6dd86aefc3"}
2024-12-21T15:00:51.291Z {"time":"2024-12-21T15:00:51.291Z","type":"platform.initStart","record":{"initializationType":"on-demand","phase":"init","runtimeVersion":"nodejs:18.v57","runtimeVersionArn":"arn:aws:lambda:us-east-1::runtime:8865cfc6a1d3f2dfabf5c509eaa9fbd70aa12fa4bbe614047030158c21978bcc","functionName":"amplify-personalcrm-carsk-GeneralChatDefaultConver-spp2BdxbwWuH","functionVersion":"$LATEST"}}
2024-12-21T15:01:29.859Z {"time":"2024-12-21T15:01:29.859Z","type":"platform.runtimeDone","record":{"requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","status":"timeout","metrics":{"durationMs":60000.723,"producedBytes":0}}}
2024-12-21T15:01:29.865Z {"time":"2024-12-21T15:01:29.865Z","type":"platform.report","record":{"requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","metrics":{"durationMs":60007.499,"billedDurationMs":60000,"memorySizeMB":512,"maxMemoryUsedMB":58},"status":"timeout"}}
2024-12-21T15:01:29.884Z {"time":"2024-12-21T15:01:29.884Z","type":"platform.initStart","record":{"initializationType":"on-demand","phase":"init","runtimeVersion":"nodejs:18.v57","runtimeVersionArn":"arn:aws:lambda:us-east-1::runtime:8865cfc6a1d3f2dfabf5c509eaa9fbd70aa12fa4bbe614047030158c21978bcc","functionName":"amplify-personalcrm-carsk-GeneralChatDefaultConver-spp2BdxbwWuH","functionVersion":"$LATEST"}}
2024-12-21T15:02:29.044Z {"time":"2024-12-21T15:02:29.044Z","type":"platform.start","record":{"requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","version":"$LATEST"}}
2024-12-21T15:02:29.061Z {"timestamp":"2024-12-21T15:02:29.061Z","level":"INFO","requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","message":"Handling conversation turn event, currentMessageId=ed58dfff-d9f6-49b5-8051-398043625158, conversationId=2758ff17-d49f-439e-ae97-06a38a5c7c94"}
2024-12-21T15:02:29.703Z {"timestamp":"2024-12-21T15:02:29.703Z","level":"INFO","requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","message":"Sending Bedrock Converse Stream request"}
2024-12-21T15:02:29.983Z {"timestamp":"2024-12-21T15:02:29.983Z","level":"INFO","requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","message":"Received Bedrock Converse Stream response, requestId=bef0dc19-d218-4212-af99-29ced6202417"}
2024-12-21T15:03:29.101Z {"time":"2024-12-21T15:03:29.101Z","type":"platform.runtimeDone","record":{"requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","status":"timeout","metrics":{"durationMs":60055.457,"producedBytes":0}}}
2024-12-21T15:03:29.121Z {"time":"2024-12-21T15:03:29.121Z","type":"platform.report","record":{"requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","metrics":{"durationMs":60075.545,"billedDurationMs":60000,"memorySizeMB":512,"maxMemoryUsedMB":58},"status":"timeout"}}
2024-12-21T15:03:29.145Z {"time":"2024-12-21T15:03:29.145Z","type":"platform.initStart","record":{"initializationType":"on-demand","phase":"init","runtimeVersion":"nodejs:18.v57","runtimeVersionArn":"arn:aws:lambda:us-east-1::runtime:8865cfc6a1d3f2dfabf5c509eaa9fbd70aa12fa4bbe614047030158c21978bcc","functionName":"amplify-personalcrm-carsk-GeneralChatDefaultConver-spp2BdxbwWuH","functionVersion":"$LATEST"}}
2024-12-21T15:05:39.287Z {"time":"2024-12-21T15:05:39.287Z","type":"platform.start","record":{"requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","version":"$LATEST"}}
2024-12-21T15:05:39.288Z {"timestamp":"2024-12-21T15:05:39.288Z","level":"INFO","requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","message":"Handling conversation turn event, currentMessageId=ed58dfff-d9f6-49b5-8051-398043625158, conversationId=2758ff17-d49f-439e-ae97-06a38a5c7c94"}
2024-12-21T15:05:39.724Z {"timestamp":"2024-12-21T15:05:39.724Z","level":"INFO","requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","message":"Sending Bedrock Converse Stream request"}
2024-12-21T15:05:40.042Z {"timestamp":"2024-12-21T15:05:40.042Z","level":"INFO","requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","message":"Received Bedrock Converse Stream response, requestId=7b14aee4-8524-4877-8711-c3badd1b5c44"}
2024-12-21T15:05:54.892Z {"timestamp":"2024-12-21T15:05:54.892Z","level":"INFO","requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","message":"Conversation turn event handled successfully, currentMessageId=ed58dfff-d9f6-49b5-8051-398043625158, conversationId=2758ff17-d49f-439e-ae97-06a38a5c7c94"}
2024-12-21T15:05:54.896Z {"time":"2024-12-21T15:05:54.896Z","type":"platform.report","record":{"requestId":"e6fcbb3b-faa5-46ef-8313-1da1795dfc12","metrics":{"durationMs":15609.304,"billedDurationMs":15610,"memorySizeMB":512,"maxMemoryUsedMB":58},"status":"success"}}

You can see the Lambda has a timeout and then after a while launches again and in DynamoDB I can see it overwrites existing entries.

I recorded a small video that shows the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai-kit Issues related to Amplify AI Kit feature-request New feature or request pending-maintainer-response Issue is pending a response from the Amplify team
Projects
None yet
Development

No branches or pull requests

4 participants