-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Bug Description
The getWorkspacesInfo account method generates invalid SQL when called with an empty workspace ID array. PostgreSQL rejects WHERE "uuid" IN () as a syntax error. This causes the GitHub integration (and potentially Gmail/Backup) to fail silently every ~6 minutes, and blocks connecting new GitHub repos.
Environment
- Version: v0.7.375
- Database: PostgreSQL 17 (self-hosted)
- Affected service:
hardcoreeng/account, called byhardcoreeng/github
Error
PostgresError: syntax error at or near ")"
position: "74"
code: "42601"
method: "getWorkspacesInfo"
source: "github"
This repeats every ~6 minutes indefinitely. Connecting new GitHub repos fails with platform:status:BadRequest in the transactor.
Root Cause
server/account/src/collections/postgres/postgres.ts ~line 177 — buildWhereClause does not handle empty $in arrays:
case '$in': {
const inVals = Object.values(qKey as object)[0]
const inVars: string[] = []
for (const val of inVals) { // empty array → no iterations
currIdx++
inVars.push(formatVar(currIdx, castType))
values.push(val)
}
whereChunks.push(`"${snakeKey}" IN (${inVars.join(', ')})`) // → IN ()
break
}When inVals is [], this produces IN () which is invalid SQL in PostgreSQL (and CockroachDB).
server/account/src/operations.ts ~line 1617 — getWorkspacesInfo checks ids == null but not ids.length === 0, so empty arrays pass through to the query.
services/github/pod-github/src/platform.ts ~line 1040 — the GitHub service calls getWorkspacesInfo(workspaces) without guarding for empty arrays. When there are no integrations, workspaces is [].
Impact
| Caller | Guards empty array? |
|---|---|
pod-github/src/platform.ts ~1040 |
No |
pod-gmail/src/gmailController.ts ~196 |
No |
server/backup/src/service.ts ~283 |
No |
pod-calendar/src/calendarController.ts ~75 |
Yes — if (ids.length === 0) return |
The calendar service is the only caller that properly guards against this.
Suggested Fix
Either (or both):
Option A — Fix at the query level in getWorkspacesInfoWithStatusByIds (server/account/src/utils.ts ~line 1350):
if (uuids.length === 0) return []Option B — Fix at the SQL builder level in buildWhereClause (postgres.ts):
case '$in': {
const inVals = Object.values(qKey as object)[0]
if (inVals.length === 0) {
whereChunks.push('FALSE')
break
}
// ... existing code
}Option B is more defensive and prevents the same bug from other callers.
Reproduction
- Self-host Huly v0.7.375 on PostgreSQL (not CockroachDB)
- Configure the GitHub integration (
GITHUB_APPID, etc.) - Install the GitHub App on an organization
- Observe
accountservice logs —getWorkspacesInfoerrors every ~6 minutes - Try to connect a repo to a project — fails with BadRequest