paperclipai/paperclip · error · Error

${errorMessage(error)} Cleanup also failed for newly-created

Error message

${errorMessage(error)} Cleanup also failed for newly-created company ${company.id}: ${errorMessage(cleanupError)}

What it means

During bootstrapTestDrive, if creating the agent after company creation fails, the code compensates by deleting the newly created company. If that cleanup DELETE also fails, it throws a combined error carrying both the original failure and the cleanup failure, with the original as `cause`. This indicates a partially-created company was left behind on the server.

Source

Thrown at cli/src/commands/test-drive.ts:388

      await input.api.post<Agent>(`/api/companies/${company.id}/agents`, {
        name: resolved.agentName,
        role: "ceo",
        adapterType: resolved.adapterType,
        adapterConfig,
      }),
      "creating the CEO agent",
    );

    if (input.linkedWorktree) {
      await reconcileTestDriveWorktreeExecution(input.api, input.instanceId);
    }
    return { reused: false, company, agent };
  } catch (error) {
    if (company) {
      try {
        await input.api.delete(`/api/companies/${company.id}`);
      } catch (cleanupError) {
        throw new Error(
          `${errorMessage(error)} Cleanup also failed for newly-created company ${company.id}: ${errorMessage(cleanupError)}`,
          { cause: error },
        );
      }
    }
    throw error;
  }
}

function dashboardUrl(server: StartedServer): string {
  return server.apiUrl.replace(/\/api\/?$/, "");
}

export async function testDriveCommand(
  options: TestDriveOptions,
  dependencies: TestDriveDependencies = {
    run: runCommand,
    createApi: (apiBase) => new PaperclipApiClient({ apiBase }),

View on GitHub (pinned to 01ad858492)

Solutions

  1. Manually delete the orphaned company: DELETE /api/companies/<company.id> (or via the board UI)
  2. Inspect the `cause` of the error to fix the original bootstrap failure before retrying
  3. Retry the test-drive; if the same company name collides, remove the stale company first

Example fix

// after failure, clean up manually:
curl -X DELETE http://localhost:3100/api/companies/<company-id>
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await bootstrapTestDrive(opts);
} catch (e) {
  const root = e.cause ?? e;
  console.error('bootstrap failed:', root.message);
  console.error('check for orphaned companies and DELETE /api/companies/<id>');
}

Prevention

When it happens

Trigger: Agent creation fails (e.g. invalid adapter config, API error) and the subsequent DELETE /api/companies/:id fails (e.g. transient network error, server rejects deletion due to existing references, auth expiry).

Common situations: Network blip mid-bootstrap leaving an orphaned test-drive company; company deletion blocked by foreign references in a newer server version; expired API credentials between the create and delete calls.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of paperclipai/paperclip@01ad858492 (2026-09-10). Data as JSON: /api/errors/666ac80c9d6065db. Report an issue: GitHub.