Skip to content

Feat/background agent template#614

Merged
VISHWAJ33T merged 6 commits intomainfrom
feat/background_agent_template
Jul 13, 2025
Merged

Feat/background agent template#614
VISHWAJ33T merged 6 commits intomainfrom
feat/background_agent_template

Conversation

@VISHWAJ33T
Copy link
Copy Markdown
Collaborator

No description provided.

- Added SQS queue configuration and permissions in serverless.yml.
- Introduced new proxy handler to send messages to SQS for task processing.
- Refactored the main handler to process SQS events and manage task states.
- Updated package dependencies to include @aws-sdk/client-sqs and related packages.
- Introduced TaskState enum for improved task status handling.
- Updated Task interface to use TaskState and renamed 'data' to 'metadata'.
- Added getTask method for retrieving task details.
- Enhanced updateTask method to merge metadata updates correctly.
Copy link
Copy Markdown

@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: SQS Handler Errors and Inefficiencies

The SQS handler has several issues:

  1. Incorrect Task Status on Error: When an error occurs during SQS message processing, the task status is not updated to TaskState.Failed and remains in TaskState.Working.
  2. Improper SQS Handler Return Type: The handler incorrectly returns an API response (createApiResponse) which is unsuitable for SQS event processing; SQS handlers should return void or throw errors.
  3. Single Record Processing: The return statement inside the for loop causes the handler to exit after processing only the first SQS record, preventing subsequent records in the same event from being processed.
  4. Potential Serialization Failure: JSON.stringify(result) in the success path may fail if result contains circular references or other non-serializable data, causing unexpected task failures.

packages/puppeteer-sls/sls/src/index.ts#L57-L79

metadata: {
result: JSON.stringify(result),
},
});
// Return successful response
return createApiResponse(200, result);
} catch (error) {
console.error('Error in handler:', error);
// Handle custom API errors
if (error instanceof ApiError) {
return createApiResponse(error.statusCode, { error: error.message });
}
// Handle unexpected errors
const internalError = new InternalServerError(
error instanceof Error ? error.message : String(error),
);
return createApiResponse(internalError.statusCode, {
error: internalError.message,
details: process.env.NODE_ENV === 'development' ? error : undefined,
});
}

Fix in CursorFix in Web


Bug: SQS Handler Fails to Process Batch Records

The SQS handler only processes the first record in a batch due to an early return. Error handling is insufficient: JSON.parse lacks protection for malformed SQS message bodies, the initial task status update to Working is unhandled, and task status is not set to Failed on errors. Additionally, the handler incorrectly returns HTTP responses, which is inappropriate for SQS events.

packages/puppeteer-sls/sls/src/index.ts#L23-L81

export const handler = async (event: SQSEvent): Promise<any> => {
for (const record of event.Records) {
console.log("handler: processing record", { messageId: record.messageId });
const body = JSON.parse(record.body);
console.log("Processing message:", body);
const { triggerEvent, task_id } = body;
await taskHandler.updateTask(task_id, {
status: TaskState.Working,
});
try {
// Extract environment variables from the new structure
toolHandler.populateEnvVars(triggerEvent);
const constructorName = toolHandler.extractConstructor(triggerEvent);
// Map functions
const sdkMap = sdkInit({
constructorName,
...process.env,
});
// Extract function arguments
const args = toolHandler.extractArguments(triggerEvent);
// Extract function from the SDK map
const fn = toolHandler.extractFunction(sdkMap, triggerEvent);
// Invoke the function
const result = await toolHandler.executeFunction(fn, args);
await taskHandler.updateTask(task_id, {
status: TaskState.Completed,
metadata: {
result: JSON.stringify(result),
},
});
// Return successful response
return createApiResponse(200, result);
} catch (error) {
console.error('Error in handler:', error);
// Handle custom API errors
if (error instanceof ApiError) {
return createApiResponse(error.statusCode, { error: error.message });
}
// Handle unexpected errors
const internalError = new InternalServerError(
error instanceof Error ? error.message : String(error),
);
return createApiResponse(internalError.statusCode, {
error: internalError.message,
details: process.env.NODE_ENV === 'development' ? error : undefined,
});
}
}
};

Fix in CursorFix in Web


BugBot free trial expires on July 22, 2025
You have used $0.00 of your $50.00 spend limit so far. Manage your spend limit in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎

@VISHWAJ33T VISHWAJ33T merged commit e7d646e into main Jul 13, 2025
5 checks passed
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.

1 participant