Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(account-link): draft the account_link_codes collision fix, apply pending owner (order 433)
nirholas4189557f0a4b
diff --git a/api/_lib/migrations/20261024193900_fix_account_link_codes_collision.sql b/api/_lib/migrations/20261024193900_fix_account_link_codes_collision.sqlnew file mode 100644index 000000000..ac2ef17fb--- /dev/null+++ b/api/_lib/migrations/20261024193900_fix_account_link_codes_collision.sql@@ -0,0 +1,35 @@+-- Fix: account_link_codes name collision. The 2026-10-11 account-linking+-- migration's `create table if not exists account_link_codes` silently+-- no-op'd against a same-named table already created by the 2026-09-22+-- agents-v1 migration, so the device-linking feature has been throwing+-- NeonDbError 42703 ("column status does not exist") on every call in+-- production since it shipped. The old table is renamed (not dropped) so its+-- rows survive, then the correctly-shaped table is created in its place.+-- Apply: node scripts/apply-migrations.mjs --apply --file 20261024193900_fix_account_link_codes_collision.sql+-- Idempotent.++alter table if exists account_link_codes rename to account_link_codes_agents_v1_legacy;+alter index if exists account_link_codes_user_idx rename to account_link_codes_agents_v1_legacy_user_idx;++create table if not exists account_link_codes (+ id uuid primary key default gen_random_uuid(),+ code_hash text not null unique,+ user_id uuid not null references users(id) on delete cascade,+ device_kind text not null check (device_kind in ('phone', 'desktop', 'cli', 'telegram')),+ label text,+ requested_scope text,+ status text not null default 'issued'+ check (status in ('issued', 'claimed', 'confirmed', 'rejected', 'consumed', 'expired')),+ claim jsonb,+ claim_secret_hash text unique,+ result_kind text check (result_kind in ('session', 'api_key', 'gateway_link')),+ result_id uuid,+ result_secret text,+ device_id uuid,+ created_at timestamptz not null default now(),+ expires_at timestamptz not null,+ claimed_at timestamptz,+ decided_at timestamptz,+ consumed_at timestamptz+);+create index if not exists account_link_codes_user_idx on account_link_codes (user_id, created_at desc);diff --git a/api/_lib/schema.sql b/api/_lib/schema.sqlindex 3b7655448..b1325e8e7 100644--- a/api/_lib/schema.sql+++ b/api/_lib/schema.sql@@ -2689,9 +2689,14 @@ CREATE TABLE IF NOT EXISTS agent_automations (CREATE INDEX IF NOT EXISTS agent_automations_agent_idx ON agent_automations (agent_id, created_at DESC);CREATE INDEX IF NOT EXISTS agent_automations_live_idx ON agent_automations (trigger_type) WHERE enabled = true;--- ── link codes ───────────────────────────────────────────────────────────────--- An eight-character code pairs a device or chat gateway to an account for ten--- minutes. Only the sha256 of the code is stored; redemption is single use.+-- ── link codes (agents-v1 legacy shape) ────────────────────────────────────+-- This is the ORIGINAL account_link_codes from the 2026-09-22 agents-v1+-- feature (agent_id/scopes/redeemed_at/link_id). A fresh bootstrap creates it+-- under this name so migration 20261024193900_fix_account_link_codes_collision.sql+-- has something to rename, exactly mirroring what happened in production: the+-- 2026-10-11 account-linking feature's own `account_link_codes` (status/+-- device_kind/claim_secret_hash/...) is the table that migration actually+-- creates and that api/_lib/account-link/link-codes.js reads and writes today.CREATE TABLE IF NOT EXISTS account_link_codes (id uuid PRIMARY KEY DEFAULT gen_random_uuid(),code_hash text NOT NULL UNIQUE,diff --git a/tests/account-link-codes-schema.test.js b/tests/account-link-codes-schema.test.jsnew file mode 100644index 000000000..f8108fa63--- /dev/null+++ b/tests/account-link-codes-schema.test.js@@ -0,0 +1,58 @@+// Real-DB regression test for the account_link_codes name collision.+//+// 20261011003000_account_linking.sql's `create table if not exists+// account_link_codes (...)` silently no-op'd against a same-named table+// already created by 20260922130000_agents_v1_api.sql (a different,+// agent-identity-linking feature). Production ran the old (agents-v1) shape+// under the new feature's name, so every call into+// api/_lib/account-link/link-codes.js (mint/claim/poll/pending/decide/+// devices/revoke) threw NeonDbError 42703 ("column status does not exist").+//+// tests/account-link.test.js mocks the DB entirely and cannot see this; run+// this file against the real database the repo already points at:+// node --env-file=.env.local ./node_modules/.bin/vitest run tests/account-link-codes-schema.test.js++import { afterAll, beforeAll, describe, expect, it } from 'vitest';++const hasDb = Boolean(process.env.DATABASE_URL);+const liveDb = describe.skipIf(!hasDb);++liveDb('account_link_codes schema', () => {+ /** @type {import('@neondatabase/serverless').NeonQueryFunction} */+ let sql;+ let user;++ beforeAll(async () => {+ ({ sql } = await import('../api/_lib/db.js'));+ const stamp = Date.now();+ [user] = await sql`insert into users (email) values (${`link-codes-schema-${stamp}@qa.three.ws`}) returning id`;+ }, 60_000);++ afterAll(async () => {+ if (sql && user) {+ await sql`delete from account_link_codes where user_id = ${user.id}`;+ await sql`delete from users where id = ${user.id}`;+ }+ });++ it('has the device-linking columns, not the agents-v1 columns the name collision used to leave in place', async () => {+ const rows = await sql`+ select column_name from information_schema.columns+ where table_name = 'account_link_codes'+ order by ordinal_position+ `;+ const columns = rows.map((r) => r.column_name);+ expect(columns).toEqual(expect.arrayContaining(['status', 'device_kind', 'claim_secret_hash', 'claimed_at', 'decided_at', 'consumed_at']));+ expect(columns).not.toContain('agent_id');+ });++ it('preserves the renamed agents-v1 table instead of dropping its rows', async () => {+ const [row] = await sql`select to_regclass('account_link_codes_agents_v1_legacy') as t`;+ expect(row.t).not.toBeNull();+ });++ it('listPendingLinkCodes resolves instead of throwing 42703', async () => {+ const { listPendingLinkCodes } = await import('../api/_lib/account-link/link-codes.js');+ await expect(listPendingLinkCodes(user.id)).resolves.toEqual([]);+ });+});