{"record":{"id":"69afb1fd5baadedc","repo":"gastownhall/beads","slug":"check-issue-existence-in-s-w","errorCode":null,"errorMessage":"check issue existence in %s: %w","messagePattern":"check issue existence in (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/edges.go","lineNumber":158,"sourceCode":"\t\tfor start := 0; start < len(ids); start += queryBatchSize {\n\t\t\tend := start + queryBatchSize\n\t\t\tif end > len(ids) {\n\t\t\t\tend = len(ids)\n\t\t\t}\n\t\t\tbatch := ids[start:end]\n\t\t\tplaceholders := make([]string, len(batch))\n\t\t\targs := make([]any, len(batch))\n\t\t\tfor i, id := range batch {\n\t\t\t\tplaceholders[i] = \"?\"\n\t\t\t\targs[i] = id\n\t\t\t}\n\t\t\trows, err := tx.QueryContext(ctx, fmt.Sprintf(\n\t\t\t\t\"SELECT id FROM %s WHERE id IN (%s)\", table, strings.Join(placeholders, \",\")), args...)\n\t\t\tif err != nil {\n\t\t\t\tif isTableNotExistError(err) {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\treturn nil, fmt.Errorf(\"check issue existence in %s: %w\", table, err)\n\t\t\t}\n\t\t\tfor rows.Next() {\n\t\t\t\tvar id string\n\t\t\t\tif scanErr := rows.Scan(&id); scanErr != nil {\n\t\t\t\t\t_ = rows.Close()\n\t\t\t\t\treturn nil, fmt.Errorf(\"check issue existence in %s: scan: %w\", table, scanErr)\n\t\t\t\t}\n\t\t\t\tpresent[id] = struct{}{}\n\t\t\t}\n\t\t\t_ = rows.Close()\n\t\t\tif err := rows.Err(); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"check issue existence in %s: rows: %w\", table, err)\n\t\t\t}\n\t\t}\n\t}\n\treturn present, nil\n}\n","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/edges.go#L140-L176","documentation":"PresentIssueOrWispIDsInTx failed while executing the existence probe SELECT id FROM <table> WHERE id IN (...) against the issues or wisps table. The driver error is wrapped with the table name. A missing wisps table is tolerated (treated as no wisps), but any other query error aborts the read/count.","triggerScenarios":"ExecuteEdgeRead or ExecuteEdgeCount running while the connection drops, the context is cancelled, or the issues table is missing/corrupt/locked; batched IN probes over a database undergoing migration.","commonSituations":"Dolt server restart mid-query; context deadline exceeded on large batches; schema where issues was renamed; table corruption or lock contention during concurrent writes.","solutions":["Inspect the wrapped driver error for the root cause and address it (connectivity, permissions, schema).","Retry transient failures (deadlock, connection reset) with backoff.","Run schema migrations to ensure the issues table exists.","Raise the context timeout or fix upstream cancellation of the operation."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Probe schema first:\n// SELECT COUNT(*) FROM issues — run migrations if this fails.","typeGuard":null,"tryCatchPattern":"res, err := ExecuteEdgeRead(ctx, tx, req)\nif err != nil && strings.Contains(err.Error(), \"check issue existence in \") {\n\tif isTransient(err) {\n\t\tres, err = ExecuteEdgeRead(ctx, tx, req) // retry with fresh tx/backoff\n\t}\n}","preventionTips":["Ensure the issues schema is migrated before reads","Use adequate context timeouts for batched IN probes","Retry transient driver errors with backoff","Avoid unauthenticated/locked table states during reads"],"tags":["database","sql","existence-check","query-execution"],"backgroundTag":"sql-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}