Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion apps/server/apps/gateway/src/ahand/ahand.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,15 @@
.returning();
inserted = row;
} catch (e) {
// Map postgres unique constraint violation to ConflictException
// Hub-keying invariant: ahand-hub keys devices by `id TEXT PRIMARY KEY`
// (no per-user partitioning — see team9ai/aHand devices migration). In a
// concurrent-register race the loser's hub.registerDevice() at step 1
// already returns HTTP 409, which AhandHubClient re-throws as
// ConflictException before reaching this try block, so 23505 is
// unreachable in that case. It can still fire on a retry where the
// gateway crashed after step 1 (hub OK) but before step 2 (DB OK); the
// hub.deleteDevice compensation below is safe because deviceId is
// globally unique — it can only target the caller's own hub binding.
if ((e as { code?: string }).code === '23505') {
// Compensate hub registration since the device is already in DB
await this.hub.deleteDevice(input.hubDeviceId).catch((err) => {
Expand Down Expand Up @@ -220,9 +228,9 @@

return {
device: inserted,
deviceJwt: minted.token,

Check warning on line 231 in apps/server/apps/gateway/src/ahand/ahand.service.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe member access .token on an `any` value

Check warning on line 231 in apps/server/apps/gateway/src/ahand/ahand.service.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe assignment of an `any` value
hubUrl: this.hubWebSocketUrl(hubUrl),
jwtExpiresAt: minted.expiresAt,

Check warning on line 233 in apps/server/apps/gateway/src/ahand/ahand.service.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe member access .expiresAt on an `any` value

Check warning on line 233 in apps/server/apps/gateway/src/ahand/ahand.service.ts

View workflow job for this annotation

GitHub Actions / lint

Unsafe assignment of an `any` value
};
}

Expand Down
Loading