mckaywrigley / buildware-ai

https://buildware.ai
MIT License
509 stars 71 forks source link

Failed to run first issue #45

Open walt93 opened 1 month ago

walt93 commented 1 month ago

Installed, configured Postgres and keys and PAT, wrote my first issue for the AI to handle, and it failed with an exception. In the UI we see:

"Error: Failed to run issue: Error: invalid byte sequence for encoding "UTF8": 0x00"

Note: did absolute minimum configuration on Supabase & took defaults for everything except password, so probably, user error

There seem to be rather a lot of Postgress issues leading up to the failure, attaching all in case it is helpful.


% npm run dev

> buildware@0.1.0 dev
> next dev

  ▲ Next.js 14.2.3
  - Local:        http://localhost:3000
  - Environments: .env.local

 ✓ Starting...
 ✓ Ready in 1321ms
 ✓ Compiled /middleware in 146ms (224 modules)
 ○ Compiling / ...
 ✓ Compiled / in 1733ms (1629 modules)
 GET / 200 in 2129ms
 ✓ Compiled in 380ms (689 modules)
 ○ Compiling /onboarding ...
 ✓ Compiled /onboarding in 856ms (2095 modules)
 ✓ Compiled /workspaces in 271ms (2107 modules)
 ✓ Compiled /[workspaceId] in 300ms (2354 modules)
 GET /46913e44-0e06-4520-a22f-c32f1d78b916 200 in 146ms
 ○ Compiling /[workspaceId]/[projectId]/settings ...
 ✓ Compiled /[workspaceId]/[projectId]/settings in 906ms (2475 modules)
 POST /46913e44-0e06-4520-a22f-c32f1d78b916/52408bd7-a1c1-486e-b845-76c1ed9974f4/settings 200 in 190ms
 POST /46913e44-0e06-4520-a22f-c32f1d78b916/0a3356da-6fe2-4b10-947b-afa39caaad38/settings 200 in 94ms
 POST /46913e44-0e06-4520-a22f-c32f1d78b916/dc591b2d-6e2f-426e-afba-e90c2c4cd663/settings 200 in 103ms
 POST /46913e44-0e06-4520-a22f-c32f1d78b916 200 in 100ms
Error getting workspace by id account: PostgresError: invalid input syntax for type uuid: "account"
    at ErrorResponse (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:803:66)
    at handle (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:489:6)
    at Socket.data (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:330:9)
    at Socket.emit (node:events:517:28)
    at addChunk (node:internal/streams/readable:335:12)
    at readableAddChunk (node:internal/streams/readable:308:9)
    at Readable.push (node:internal/streams/readable:245:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '22P02',
  where: "unnamed portal parameter $1 = '...'",
  file: 'uuid.c',
  line: '133',
  routine: 'string_to_uuid'
}
 ⨯ PostgresError: invalid input syntax for type uuid: "account"
    at Socket.emit (node:events:517:28)
digest: "3491611571"
 ⨯ PostgresError: invalid input syntax for type uuid: "account"
    at Socket.emit (node:events:517:28)
digest: "3491611571"
 ⨯ PostgresError: invalid input syntax for type uuid: "account"
    at Socket.emit (node:events:517:28)
digest: "3491611571"
 GET /account 500 in 134ms
 POST /46913e44-0e06-4520-a22f-c32f1d78b916/cab5438b-dc0c-4e2a-b654-c50d1107bcca/settings 200 in 273ms
Error getting workspace by id favicon.ico: PostgresError: invalid input syntax for type uuid: "favicon.ico"
    at ErrorResponse (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:803:66)
    at handle (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:489:6)
    at Socket.data (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:330:9)
    at Socket.emit (node:events:517:28)
    at addChunk (node:internal/streams/readable:335:12)
    at readableAddChunk (node:internal/streams/readable:308:9)
    at Readable.push (node:internal/streams/readable:245:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '22P02',
  where: "unnamed portal parameter $1 = '...'",
  file: 'uuid.c',
  line: '133',
  routine: 'string_to_uuid'
}
 ⨯ PostgresError: invalid input syntax for type uuid: "favicon.ico"
    at Socket.emit (node:events:517:28)
digest: "1407938611"
 ⨯ PostgresError: invalid input syntax for type uuid: "favicon.ico"
    at Socket.emit (node:events:517:28)
digest: "1407938611"
 ⨯ PostgresError: invalid input syntax for type uuid: "favicon.ico"
    at Socket.emit (node:events:517:28)
digest: "1407938611"
 GET /favicon.ico 500 in 76ms
 ✓ Compiled /[workspaceId]/[projectId]/issues in 321ms (2499 modules)
 POST /46913e44-0e06-4520-a22f-c32f1d78b916/cab5438b-dc0c-4e2a-b654-c50d1107bcca/settings 200 in 430ms
 ⚠ Fast Refresh had to perform a full reload due to a runtime error.
Error getting workspace by id account: PostgresError: invalid input syntax for type uuid: "account"
    at ErrorResponse (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:803:66)
    at handle (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:489:6)
    at Socket.data (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:330:9)
    at Socket.emit (node:events:517:28)
    at addChunk (node:internal/streams/readable:335:12)
    at readableAddChunk (node:internal/streams/readable:308:9)
    at Readable.push (node:internal/streams/readable:245:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '22P02',
  where: "unnamed portal parameter $1 = '...'",
  file: 'uuid.c',
  line: '133',
  routine: 'string_to_uuid'
}
 ⨯ PostgresError: invalid input syntax for type uuid: "account"
    at Socket.emit (node:events:517:28)
digest: "3491611571"
 ⨯ PostgresError: invalid input syntax for type uuid: "account"
    at Socket.emit (node:events:517:28)
digest: "3491611571"
 ⨯ PostgresError: invalid input syntax for type uuid: "account"
    at Socket.emit (node:events:517:28)
digest: "3491611571"
 GET /account 500 in 229ms
Error getting workspace by id favicon.ico: PostgresError: invalid input syntax for type uuid: "favicon.ico"
    at ErrorResponse (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:803:66)
    at handle (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:489:6)
    at Socket.data (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:330:9)
    at Socket.emit (node:events:517:28)
    at addChunk (node:internal/streams/readable:335:12)
    at readableAddChunk (node:internal/streams/readable:308:9)
    at Readable.push (node:internal/streams/readable:245:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '22P02',
  where: "unnamed portal parameter $1 = '...'",
  file: 'uuid.c',
  line: '133',
  routine: 'string_to_uuid'
}
 ⨯ PostgresError: invalid input syntax for type uuid: "favicon.ico"
    at Socket.emit (node:events:517:28)
digest: "1407938611"
 ⨯ PostgresError: invalid input syntax for type uuid: "favicon.ico"
    at Socket.emit (node:events:517:28)
digest: "1407938611"
 ⨯ PostgresError: invalid input syntax for type uuid: "favicon.ico"
    at Socket.emit (node:events:517:28)
digest: "1407938611"
 GET /favicon.ico 500 in 80ms
 ✓ Compiled /[workspaceId]/[projectId]/issues/create in 258ms (2531 modules)
 ⚠ Fast Refresh had to perform a full reload due to a runtime error.
Error getting workspace by id account: PostgresError: invalid input syntax for type uuid: "account"
    at ErrorResponse (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:803:66)
    at handle (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:489:6)
    at Socket.data (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:330:9)
    at Socket.emit (node:events:517:28)
    at addChunk (node:internal/streams/readable:335:12)
    at readableAddChunk (node:internal/streams/readable:308:9)
    at Readable.push (node:internal/streams/readable:245:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '22P02',
  where: "unnamed portal parameter $1 = '...'",
  file: 'uuid.c',
  line: '133',
  routine: 'string_to_uuid'
}
 ⨯ PostgresError: invalid input syntax for type uuid: "account"
    at Socket.emit (node:events:517:28)
digest: "3491611571"
 ⨯ PostgresError: invalid input syntax for type uuid: "account"
    at Socket.emit (node:events:517:28)
digest: "3491611571"
 ⨯ PostgresError: invalid input syntax for type uuid: "account"
    at Socket.emit (node:events:517:28)
digest: "3491611571"
 GET /account 500 in 192ms
Error getting workspace by id favicon.ico: PostgresError: invalid input syntax for type uuid: "favicon.ico"
    at ErrorResponse (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:803:66)
    at handle (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:489:6)
    at Socket.data (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:330:9)
    at Socket.emit (node:events:517:28)
    at addChunk (node:internal/streams/readable:335:12)
    at readableAddChunk (node:internal/streams/readable:308:9)
    at Readable.push (node:internal/streams/readable:245:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '22P02',
  where: "unnamed portal parameter $1 = '...'",
  file: 'uuid.c',
  line: '133',
  routine: 'string_to_uuid'
}
 ⨯ PostgresError: invalid input syntax for type uuid: "favicon.ico"
    at Socket.emit (node:events:517:28)
digest: "1407938611"
 ⨯ PostgresError: invalid input syntax for type uuid: "favicon.ico"
    at Socket.emit (node:events:517:28)
digest: "1407938611"
 ⨯ PostgresError: invalid input syntax for type uuid: "favicon.ico"
    at Socket.emit (node:events:517:28)
digest: "1407938611"
 GET /favicon.ico 500 in 79ms
 POST /46913e44-0e06-4520-a22f-c32f1d78b916/cab5438b-dc0c-4e2a-b654-c50d1107bcca/issues/create 200 in 167ms
 POST /46913e44-0e06-4520-a22f-c32f1d78b916/cab5438b-dc0c-4e2a-b654-c50d1107bcca/issues/create 200 in 284ms
 ○ Compiling /[workspaceId]/[projectId]/issues/[issueId] ...
 ✓ Compiled /[workspaceId]/[projectId]/issues/[issueId] in 1604ms (4501 modules)
 ⚠ Fast Refresh had to perform a full reload due to a runtime error.
Error getting workspace by id account: PostgresError: invalid input syntax for type uuid: "account"
    at ErrorResponse (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:803:66)
    at handle (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:489:6)
    at Socket.data (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:330:9)
    at Socket.emit (node:events:517:28)
    at addChunk (node:internal/streams/readable:335:12)
    at readableAddChunk (node:internal/streams/readable:308:9)
    at Readable.push (node:internal/streams/readable:245:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '22P02',
  where: "unnamed portal parameter $1 = '...'",
  file: 'uuid.c',
  line: '133',
  routine: 'string_to_uuid'
}
 ⨯ PostgresError: invalid input syntax for type uuid: "account"
    at Socket.emit (node:events:517:28)
digest: "3491611571"
 ⨯ PostgresError: invalid input syntax for type uuid: "account"
    at Socket.emit (node:events:517:28)
digest: "3491611571"
 ⨯ PostgresError: invalid input syntax for type uuid: "account"
    at Socket.emit (node:events:517:28)
digest: "3491611571"
 GET /account 500 in 248ms
Error getting workspace by id favicon.ico: PostgresError: invalid input syntax for type uuid: "favicon.ico"
    at ErrorResponse (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:803:66)
    at handle (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:489:6)
    at Socket.data (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:330:9)
    at Socket.emit (node:events:517:28)
    at addChunk (node:internal/streams/readable:335:12)
    at readableAddChunk (node:internal/streams/readable:308:9)
    at Readable.push (node:internal/streams/readable:245:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '22P02',
  where: "unnamed portal parameter $1 = '...'",
  file: 'uuid.c',
  line: '133',
  routine: 'string_to_uuid'
}
 ⨯ PostgresError: invalid input syntax for type uuid: "favicon.ico"
    at Socket.emit (node:events:517:28)
digest: "1407938611"
 ⨯ PostgresError: invalid input syntax for type uuid: "favicon.ico"
    at Socket.emit (node:events:517:28)
digest: "1407938611"
 ⨯ PostgresError: invalid input syntax for type uuid: "favicon.ico"
    at Socket.emit (node:events:517:28)
digest: "1407938611"
 GET /favicon.ico 500 in 154ms
 POST /46913e44-0e06-4520-a22f-c32f1d78b916/cab5438b-dc0c-4e2a-b654-c50d1107bcca/issues/3cac8388-4ad8-42f3-af66-3280cccb6a29 200 in 170ms
 POST /46913e44-0e06-4520-a22f-c32f1d78b916/cab5438b-dc0c-4e2a-b654-c50d1107bcca/issues/3cac8388-4ad8-42f3-af66-3280cccb6a29 200 in 454ms
 POST /46913e44-0e06-4520-a22f-c32f1d78b916/cab5438b-dc0c-4e2a-b654-c50d1107bcca/issues/3cac8388-4ad8-42f3-af66-3280cccb6a29 200 in 504ms
Branch needs updating
Error inserting records into embedded_files: PostgresError: invalid byte sequence for encoding "UTF8": 0x00
    at ErrorResponse (webpack-internal:///(action-browser)/./node_modules/postgres/src/connection.js:803:66)
    at handle (webpack-internal:///(action-browser)/./node_modules/postgres/src/connection.js:489:6)
    at Socket.data (webpack-internal:///(action-browser)/./node_modules/postgres/src/connection.js:330:9)
    at Socket.emit (node:events:517:28)
    at addChunk (node:internal/streams/readable:335:12)
    at readableAddChunk (node:internal/streams/readable:308:9)
    at Readable.push (node:internal/streams/readable:245:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '22021',
  where: 'unnamed portal parameter $646',
  file: 'mbutils.c',
  line: '1665',
  routine: 'report_invalid_encoding'
}
Error in embedBranch: PostgresError: invalid byte sequence for encoding "UTF8": 0x00
    at ErrorResponse (webpack-internal:///(action-browser)/./node_modules/postgres/src/connection.js:803:66)
    at handle (webpack-internal:///(action-browser)/./node_modules/postgres/src/connection.js:489:6)
    at Socket.data (webpack-internal:///(action-browser)/./node_modules/postgres/src/connection.js:330:9)
    at Socket.emit (node:events:517:28)
    at addChunk (node:internal/streams/readable:335:12)
    at readableAddChunk (node:internal/streams/readable:308:9)
    at Readable.push (node:internal/streams/readable:245:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '22021',
  where: 'unnamed portal parameter $646',
  file: 'mbutils.c',
  line: '1665',
  routine: 'report_invalid_encoding'
}
Error embedding target branch: PostgresError: invalid byte sequence for encoding "UTF8": 0x00
    at ErrorResponse (webpack-internal:///(action-browser)/./node_modules/postgres/src/connection.js:803:66)
    at handle (webpack-internal:///(action-browser)/./node_modules/postgres/src/connection.js:489:6)
    at Socket.data (webpack-internal:///(action-browser)/./node_modules/postgres/src/connection.js:330:9)
    at Socket.emit (node:events:517:28)
    at addChunk (node:internal/streams/readable:335:12)
    at readableAddChunk (node:internal/streams/readable:308:9)
    at Readable.push (node:internal/streams/readable:245:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '22021',
  where: 'unnamed portal parameter $646',
  file: 'mbutils.c',
  line: '1665',
  routine: 'report_invalid_encoding'
}
 ⨯ PostgresError: invalid byte sequence for encoding "UTF8": 0x00
    at Socket.emit (node:events:517:28)
digest: "2129785742"
 POST /46913e44-0e06-4520-a22f-c32f1d78b916/cab5438b-dc0c-4e2a-b654-c50d1107bcca/issues/3cac8388-4ad8-42f3-af66-3280cccb6a29 500 in 21851ms
 POST /46913e44-0e06-4520-a22f-c32f1d78b916/cab5438b-dc0c-4e2a-b654-c50d1107bcca/issues/3cac8388-4ad8-42f3-af66-3280cccb6a29 200 in 115ms
 POST /46913e44-0e06-4520-a22f-c32f1d78b916/cab5438b-dc0c-4e2a-b654-c50d1107bcca/issues/3cac8388-4ad8-42f3-af66-3280cccb6a29 200 in 113ms
FlynnCruse commented 1 month ago

I had the same issue and was able to solve it by removing cases where null's could be attempted to be stored in the pg database.

I sanitized the null values out of embed_files.ts. Here is the refactored file: `"use server"

import { InsertEmbeddedFile } from "@/db/schema" import { BUILDWARE_EMBEDDING_DIMENSIONS, BUILDWARE_EMBEDDING_MODEL } from "@/lib/constants/buildware-config" import { GitHubFileContent } from "@/types/github" import { encode } from "gpt-tokenizer" import OpenAI from "openai"

const openai = new OpenAI()

function sanitizeContent(content: string): string { return content.replace(/\0/g, ''); // Remove null bytes }

export async function embedFiles(filesContent: GitHubFileContent[]) { let embeddings: number[][] = []

try { const response = await openai.embeddings.create({ model: BUILDWARE_EMBEDDING_MODEL, dimensions: BUILDWARE_EMBEDDING_DIMENSIONS, // embed path + content input: filesContent.map(file => ${file.path}\n${sanitizeContent(file.content)}) })

if (response && response.data) {
  embeddings = response.data.map(item => item.embedding)
} else {
  console.error("OpenAI API call failed, response is undefined.")
}

} catch (error) { console.error("Error calling OpenAI API:", error) }

const preparedFiles: Omit< InsertEmbeddedFile, "userId" | "projectId" | "embeddedBranchId" | "githubRepoFullName"

[] = filesContent.map((file, index) => ({ path: file.path, content: sanitizeContent(file.content), tokenCount: encode(file.content).length, embedding: embeddings[index] }))

return preparedFiles }`

I also sanitized issue-messages-queries.ts. Here is the refactored file: `"use server"

import { and, desc, eq } from "drizzle-orm" import { revalidatePath } from "next/cache" import { db } from "../db" import { InsertIssueMessage, SelectIssueMessage, issueMessagesTable } from "../schema/issue-messages-schema"

function sanitizeContent(content: string): string { return content.replace(/\0/g, ''); // Remove null bytes }

export async function createIssueMessageRecord( data: InsertIssueMessage ): Promise { try { const sanitizedData = { ...data, content: sanitizeContent(data.content) }; const [result] = await db .insert(issueMessagesTable) .values({ ...sanitizedData }) .returning(); revalidatePath("/") return result } catch (error) { console.error("Error creating issue message record:", error) throw error } }

export async function getIssueMessageById( id: string ): Promise<SelectIssueMessage | undefined> { try { return db.query.issueMessages.findFirst({ where: eq(issueMessagesTable.id, id) }) } catch (error) { console.error(Error getting issue message by id ${id}:, error) throw error } }

export async function getIssueMessagesByIssueId( issueId: string ): Promise<SelectIssueMessage[]> { try { return db.query.issueMessages.findMany({ where: eq(issueMessagesTable.issueId, issueId), orderBy: desc(issueMessagesTable.createdAt) }) } catch (error) { console.error(Error getting issue messages for issue ${issueId}:, error) throw error } }

export async function updateIssueMessage( id: string, data: Partial ): Promise { try { await db .update(issueMessagesTable) .set(data) .where(and(eq(issueMessagesTable.id, id))) revalidatePath("/") } catch (error) { console.error(Error updating issue message ${id}:, error) throw error } }

export async function deleteIssueMessage(id: string): Promise { try { await db .delete(issueMessagesTable) .where(and(eq(issueMessagesTable.id, id))) revalidatePath("/") } catch (error) { console.error(Error deleting issue message ${id}:, error) throw error } }

export async function deleteIssueMessagesByIssueId( issueId: string ): Promise { try { await db .delete(issueMessagesTable) .where(eq(issueMessagesTable.issueId, issueId)) revalidatePath("/") } catch (error) { console.error(Error deleting issue messages for issue ${issueId}:, error) throw error } }`

On a similar note, I also sanitized the generate-prs.ts script, since there are conventions for naming branches, and your issue names could violate them.: const sanitizeBranchName = (name: string) => { return name .toLowerCase() .replace(/[^a-z0-9-]/g, '-') // Replace any non-alphanumeric characters with hyphens .replace(/-+/g, '-') // Replace multiple consecutive hyphens with a single hyphen .replace(/^-|-$/g, '') // Remove leading and trailing hyphens .slice(0, 50); // Limit the length to 50 characters };

After making these changes, the project worked for me. Good luck!