Skip to content

[Bug] Roll back failed agent creation when follow-up update fails#264

Open
HiddenPuppy wants to merge 1 commit intoclawwork-ai:mainfrom
HiddenPuppy:codex/issue-263-agent-builder-rollback
Open

[Bug] Roll back failed agent creation when follow-up update fails#264
HiddenPuppy wants to merge 1 commit intoclawwork-ai:mainfrom
HiddenPuppy:codex/issue-263-agent-builder-rollback

Conversation

@HiddenPuppy
Copy link
Copy Markdown
Contributor

Summary

  • extract the new-agent creation flow into a helper that rolls back the created agent if the follow-up model update fails
  • stop reporting success when the second step fails, and refresh the agent list after a failed create attempt
  • add a regression test covering rollback on partial creation failure

Validation

  • pnpm --filter @clawwork/desktop test -- agent-builder.test.ts
  • pnpm --filter @clawwork/desktop exec eslint src/renderer/lib/agent-builder.ts src/renderer/layouts/Settings/sections/AgentsSection.tsx test/agent-builder.test.ts

Notes

  • pnpm --filter @clawwork/desktop exec tsc --noEmit currently fails on unrelated teams / system-session type errors already present on latest origin/main (commit 0445f11) and not touched by this PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

Hi @HiddenPuppy,
Thanks for your pull request!
If the PR is ready, use the /auto-cc command to assign Reviewer to Review.
We will review it shortly.

Details

Instructions for interacting with me using comments are available here.
If you have questions or suggestions related to my behavior, please file an issue against the gh-ci-bot repository.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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

  • Atomic Agent Creation: Introduced a helper function to manage the agent creation flow, ensuring that if the subsequent model update fails, the newly created agent is automatically rolled back.
  • Improved Error Handling: Updated the UI to stop reporting success when the secondary update step fails and ensured the agent list is refreshed after any failed creation attempt.
  • Regression Testing: Added a new test suite to verify the rollback logic and ensure that errors are correctly surfaced even if the rollback itself fails.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +18 to +27
export async function createAgentWithRollback(
api: AgentBuilderApi,
params: {
gatewayId: string;
name: string;
workspace: string;
avatar?: string;
model?: string;
},
): Promise<AgentMutationResult> {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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'})`,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
  1. Use t() for all user-facing strings. (link)

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