Introduction

"Since Genspark wrote the code, it must be perfect."

Many people tend to think this way, but it's a big misconception. In the early stages of website development, I also blindly trusted and deployed AI-generated code. The result was... an application full of bugs.

Genspark certainly generates code quickly. However, like humans, AI also embeds bugs. This time, following the previous article, I will introduce AI-related bugs I actually encountered and how to deal with them.

The Reality of AI Coding: The Bug Occurrence Rate is Surprisingly High

According to the latest survey in 2025, approximately 15-30% of AI-generated code is reported to contain some kind of issue. The following problems are particularly frequent:

Common AI-Related Bugs

1. Logic Errors

  • Missing conditional branches
  • Insufficient handling of edge cases
  • Asynchronous processing conflicts

2. Security Issues

  • Insufficient input validation
  • SQL injection vulnerabilities
  • Lacks of authentication/authorization

3. Performance Issues

  • Redundant loop processing
  • Inefficient database queries
  • Memory leaks

Cursor, an AI tool development company, released a dedicated bug detection tool called "Bugbot" in August 2025. This is a tool that uses AI to detect bugs in AI-written code. This fact itself speaks volumes about the prevalence of issues in AI-generated code.

Real Experience 1: AI Generated an Infinite Loop

This happened when I was implementing a feature to cache user web function results on a website.

My Request: "Please create a function that skips recalculation if a cache exists."

Code Generated by Genspark

async function getCachedResult(userId: string) {
  let result = await cache.get(userId);
  
  while (!result) {
    result = await calculateCompatibility(userId);
    await cache.set(userId, result);
  }
  
  return result;
}

It looks fine at first glance, but when actually executed...

Issues

  • If cache.get() fails, the while loop continues indefinitely.
  • If result is null or undefined, it falls into an infinite loop.
  • Even if cache saving fails, the loop cannot be exited.

Correct Implementation

async function getCachedResult(userId: string) {
  let result = await cache.get(userId);
  
  if (!result) {
    result = await calculateCompatibility(userId);
    await cache.set(userId, result);
  }
  
  return result;
}

Genspark understood the intention of "calculate if there is no cache," but it confused the while statement with the if statement.

Real Experience 2: Asynchronous Processing Race Condition

I encountered an even more serious bug with Twitter API integration.

Code Generated by Genspark

async function postToTwitter(tweets: Tweet[]) {
  for (const tweet of tweets) {
    await api.post(tweet);
    console.log('Posted:', tweet.id);
  }
}

Issues

  • Because await is used inside the loop, only one item can be posted at a time, making it very slow.
  • There's a possibility of hitting API rate limits.
  • There is no error handling whatsoever.

Improved Version

async function postToTwitter(tweets: Tweet[]) {
  const results = await Promise.allSettled(
    tweets.map(tweet => 
      api.post(tweet)
        .then(() => ({ success: true, id: tweet.id }))
        .catch(error => ({ success: false, id: tweet.id, error }))
    )
  );
  
  const succeeded = results.filter(r => r.status === 'fulfilled' && r.value.success);
  const failed = results.filter(r => r.status === 'rejected' || !r.value.success);
  
  console.log(`Posted: ${succeeded.length}, Failed: ${failed.length}`);
  return { succeeded, failed };
}

Genspark suggested a simple implementation of "posting in order," but it did not consider the importance of parallel processing and error handling.

Real Experience 3: Inefficient Database Queries

For the article list display feature, Genspark generated the following code:

Problematic Code

async function getArticlesWithCategories() {
  const articles = await db.query('SELECT * FROM articles');
  
  for (const article of articles) {
    article.category = await db.query(
      'SELECT name FROM categories WHERE id = ?',
      [article.category_id]
    );
  }
  
  return articles;
}

What's the Problem?

  • N+1 Problem: If there are 100 articles, a total of 101 queries will be executed.
  • Very high load on the database.
  • Response time becomes extremely slow.

Correct Implementation (Using JOIN)

async function getArticlesWithCategories() {
  const articles = await db.query(`
    SELECT 
      articles.*, 
      categories.name as category_name
    FROM articles
    LEFT JOIN categories ON articles.category_id = categories.id
  `);
  
  return articles;
}

Genspark can generate basic SQL, but it tends to struggle with optimization considering performance.

Why Does Genspark Embed Bugs?

Main reasons why AI generates bugs:

1. Quality of Training Data

  • Approximately 20% of the code included in the training data itself contains bugs.
  • It also learns "incorrect answers" from sources like StackOverflow.

2. Limitations in Contextual Understanding

  • Cannot understand the overall project structure.
  • Cannot consider consistency with existing code.
  • Cannot anticipate edge cases.

3. Lack of Optimization

  • It can generate "working code" but not "good code."
  • Performance and security are secondary.

Why Human Coding Knowledge is Important

So, should coding beginners give up on AI development? The answer is No.

However, a minimum level of coding knowledge is required:

Required Skill Level

1. Understanding Basic Syntax

  • Variables, functions, conditional branches, loops
  • Data types and how to read type errors

2. Debugging Basics

  • How to read error messages
  • Checking operation with console.log
  • How to use breakpoints

3. Basic Algorithms

  • Array manipulation
  • Basics of asynchronous processing
  • Fundamentals of database operations

With this knowledge, you can notice problems in the code generated by Genspark and instruct it to make corrections.

Practical Debugging Techniques

1. Habitual AI Code Review

Always check the following for code generated by Genspark:

  • ✓ Is there error handling?
  • ✓ Does it handle edge cases (null, empty arrays, etc.)?
  • ✓ Is the loop's termination condition correct?
  • ✓ Are there no asynchronous processing race conditions?
  • ✓ Are database queries efficient?
  • ✓ Are there any security issues?

2. Incremental Test Execution

Don't implement all features at once; test in small steps:

// Step 1: Test basic functionality
console.log('Test 1: Basic function');
const result1 = await basicFunction();
console.log('Result:', result1);

// Step 2: Test edge cases
console.log('Test 2: Empty input');
const result2 = await basicFunction([]);
console.log('Result:', result2);

// Step 3: Test error cases
console.log('Test 3: Invalid input');
try {
  const result3 = await basicFunction(null);
} catch (error) {
  console.log('Error caught:', error);
}

3. Ask AI to "Explain the Reason for Correction"

When requesting bug fixes:

❌ Bad example: "Fix this code."

✅ Good example: "An infinite loop is occurring in this code. Please identify the cause, provide a proposed fix, and explain the reason for the correction."

By asking for explanations, you can confirm the AI's understanding and prevent new bugs from being embedded.

Cursor Bugbot and AI Debugging Tools

Released by Cursor in August 2025, "Bugbot" is a tool that automatically detects bugs in AI-generated code.

Bugbot Features

  • Detection of logical errors
  • Scanning for security vulnerabilities
  • Identification of edge cases

However, since Bugbot itself is also AI, 100% accuracy is not guaranteed. The final judgment must be made by humans.

Summary: AI and Human Collaboration is Ideal

Key points to remember:
  1. Genspark generates code quickly but is not perfect - A bug inclusion rate of 15-30% is within expectations.
  2. A minimum level of human coding knowledge is essential - Understanding basic syntax, debugging, and algorithms.
  3. Do not neglect code review and testing - AI-generated code, in particular, requires careful checking.
  4. Incremental implementation and verification - Build small, test small.
  5. Utilize AI debugging tools - but do not over-rely on them.

Genspark can increase development speed by tenfold, but skipping bug checks will cost you ten times as much time later.

Trust AI, but ensure thorough human oversight — this is the best practice for AI development in 2025.

Next time, under the theme of "Genspark Freezes/Loops", I will introduce the issue of AI chat freezing and backup strategies to prevent data loss.

For pricing details: Genspark Official Pricing