Skip to content

Fix: Rollback tool intake and return error when category insert fails - #99

Merged
Power-Maverick merged 2 commits into
mainfrom
copilot/bug-fix-categories-missing
Aug 16, 2026
Merged

Fix: Rollback tool intake and return error when category insert fails#99
Power-Maverick merged 2 commits into
mainfrom
copilot/bug-fix-categories-missing

Conversation

Copilot AI commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Category insert failures in app/api/submit-tool/route.ts were silently swallowed — the API returned success while tool_intake_categories was left empty, causing tools to appear with no categories in the dashboard.

Changes

  • Category ID validation — Before inserting, validates all submitted categoryIds against the categories table. Invalid IDs (stale, tampered, or nonexistent) trigger a 400 rollback response.
  • Rollback on failure — Any failure during category lookup or insert now deletes the just-created tool_intakes row and returns an error (400/500) prompting the user to resubmit rather than silently succeeding.
  • Shared rollback helper — Extracted a local rollbackIntake() helper to avoid duplicating the delete logic across three failure paths; also logs a warning if the rollback itself fails so orphaned records are surfaced in logs.
// Before: failure was ignored, intake persisted with no categories
if (categoryError) {
  console.error("Error inserting tool intake categories:", categoryError);
  // Note: We don't fail the request here...
}

// After: rollback and surface error to client
if (categoryError) {
  await rollbackIntake();
  console.error("Error inserting tool intake categories:", categoryError);
  return NextResponse.json(
    { error: "Failed to save tool categories. Please resubmit.", step: "category_insert" },
    { status: 500 },
  );
}

@vercel

vercel Bot commented Aug 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
web Ready Ready Preview Aug 16, 2026 2:35am

Co-authored-by: Power-Maverick <36135520+Power-Maverick@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix missing categories after successful tool submit Fix: Rollback tool intake and return error when category insert fails Aug 16, 2026
Copilot AI requested a review from Power-Maverick August 16, 2026 02:36
@Power-Maverick
Power-Maverick marked this pull request as ready for review August 16, 2026 02:51
@Power-Maverick
Power-Maverick merged commit 76863ca into main Aug 16, 2026
4 checks passed
@Power-Maverick
Power-Maverick deleted the copilot/bug-fix-categories-missing branch August 16, 2026 02:53
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.

[Bug]: Categories missing after successful tool submit

2 participants