[Bug] Roll back failed agent creation when follow-up update fails#264
[Bug] Roll back failed agent creation when follow-up update fails#264HiddenPuppy wants to merge 1 commit intoclawwork-ai:mainfrom
Conversation
|
Hi @HiddenPuppy, DetailsInstructions for interacting with me using comments are available here. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request improves the reliability of the agent creation process by implementing a transactional approach. By encapsulating the creation and update steps, the system now ensures that partial failures do not leave the application in an inconsistent state, while also providing better feedback and state synchronization for the user. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a createAgentWithRollback utility to ensure atomic agent creation by rolling back (deleting) the agent if a subsequent model update fails. The AgentsSection has been refactored to use this helper, and unit tests have been added. Feedback highlights the need to expand the utility's parameters for use in other dialogs, addresses a logic gap where missing agent IDs could lead to silent failures, and notes a style guide violation regarding hardcoded English strings instead of using the translation system.
| export async function createAgentWithRollback( | ||
| api: AgentBuilderApi, | ||
| params: { | ||
| gatewayId: string; | ||
| name: string; | ||
| workspace: string; | ||
| avatar?: string; | ||
| model?: string; | ||
| }, | ||
| ): Promise<AgentMutationResult> { |
There was a problem hiding this comment.
To fully achieve the goal of extracting the agent creation flow, this helper should ideally be used in AgentBuilderDialog.tsx as well. However, the current implementation lacks support for parameters like emoji and additional steps like setAgentFile (used for IDENTITY.md in the dialog). Consider expanding the helper's parameters and API interface to support these cases, ensuring consistent rollback behavior across all agent creation paths.
| const created = createRes.result; | ||
| const agentId = typeof created?.agentId === 'string' ? created.agentId : ''; | ||
| const model = params.model?.trim(); | ||
| if (!model || !agentId) return createRes; |
There was a problem hiding this comment.
If a model is provided but agentId is missing (despite createRes.ok being true), the function currently returns createRes (success). This results in a silent failure where the agent is created but the requested model update is skipped. It would be safer to return an error in this case to notify the user that the operation was incomplete.
|
|
||
| return { | ||
| ...updateRes, | ||
| error: `${updateRes.error ?? 'agent update failed'} (rollback failed: ${rollbackRes.error ?? 'unknown error'})`, |
There was a problem hiding this comment.
This error message contains hardcoded English strings ('agent update failed', 'rollback failed', 'unknown error'), which violates the repository style guide requirement to use t() for all user-facing strings. Since this helper is in the renderer process, consider returning error codes that the caller can translate, or use the translation system directly.
References
- Use t() for all user-facing strings. (link)
Summary
Validation
pnpm --filter @clawwork/desktop test -- agent-builder.test.tspnpm --filter @clawwork/desktop exec eslint src/renderer/lib/agent-builder.ts src/renderer/layouts/Settings/sections/AgentsSection.tsx test/agent-builder.test.tsNotes
pnpm --filter @clawwork/desktop exec tsc --noEmitcurrently fails on unrelatedteams/system-sessiontype errors already present on latestorigin/main(commit0445f11) and not touched by this PR.