Skip to content

fix(indexer): remove duplicate schema block and fix rate-limit bugs from #207#208

Merged
David1984TK merged 1 commit into
mainfrom
claude/bimex-review-wlvPQ
Jul 1, 2026
Merged

fix(indexer): remove duplicate schema block and fix rate-limit bugs from #207#208
David1984TK merged 1 commit into
mainfrom
claude/bimex-review-wlvPQ

Conversation

@David1984TK

Copy link
Copy Markdown
Owner

Summary

Correcciones sobre los bugs encontrados en la revisión del PR #207 (ya mergeado).

  • schema.sql — bloque duplicado eliminado: PR #147 global rate limiting by ip on public indexer endpoints fix #207 insertó el bloque completo de rate-limit (tablas + 5 funciones) antes de la sección alter publication supabase_realtime, pero el mismo bloque ya existía más abajo bajo -- ─── IP Rate Limiting ───. Con CREATE IF NOT EXISTS / CREATE OR REPLACE el segundo bloque sobreescribía silenciosamente al primero en cada migración — cualquier corrección en el bloque nuevo era no-op en producción. Se elimina el bloque duplicado (157 líneas) y se aplican los fixes directamente al bloque canónico.

  • schema.sql consume_rate_limit_bucketretryAfter corregido: greatest(ceil(...), 1) devolvía ≥ 1 incluso para peticiones permitidas, produciendo { allowed: true, retryAfter: 37 } — contrato roto. Cambiado a CASE WHEN count > p_limit THEN ... ELSE 0 END para ser consistente con acquire_sse_connection.

  • schema.sql acquire_sse_connection — colisión de advisory lock: pg_advisory_xact_lock(hashtext(p_key)) usa int4 (32 bits); dos IPs distintas pueden colisionar y serializar conexiones SSE sin relación. Cambiado a pg_advisory_xact_lock(hashtext('rl_sse'), hashtext(p_key)) (overload de dos int4 = espacio de 64 bits efectivos).

  • package.json test:scripts: corregido de node --test scripts/test-scripts.js test/*.test.js a node scripts/test-scripts.js. El comando original pasaba test/rateLimiter.test.js (que importa de vitest) al runner de node --test, que reportaba 0 tests y un falso verde. scripts/test-scripts.js tampoco usa la API node:test por lo que --test era incorrecto.

Test plan

  • node -e "require('./bimex-indexer/package.json')" — JSON válido
  • npm run test en bimex-indexer/ — suite vitest pasa
  • npm run test:scripts en bimex-indexer/ — ejecuta el script estructural sin error
  • Verificar en Supabase que schema.sql no tiene definiciones duplicadas tras aplicar la migración

Generated by Claude Code

…rom PR #207

- schema.sql: delete the duplicate rate-limit block (lines 50-200) that
  PR #207 inserted above the canonical '─── IP Rate Limiting ───' section.
  Both blocks used CREATE IF NOT EXISTS / CREATE OR REPLACE, so the second
  block always silently overwrote the first; any fix in the new block was
  a no-op in production.

- schema.sql consume_rate_limit_bucket: fix retryAfter returning >= 1 even
  for allowed requests. Changed greatest(..., 1) to a CASE that returns 0
  when count <= p_limit, matching the contract of acquire_sse_connection.

- schema.sql acquire_sse_connection: replace pg_advisory_xact_lock(hashtext(p_key))
  with pg_advisory_xact_lock(hashtext('rl_sse'), hashtext(p_key)) to avoid
  int4 hash collisions across unrelated SSE keys serializing each other.

- schema.sql: remove WHAT-level comment line from the canonical block header.

- package.json: fix test:scripts from "node --test scripts/test-scripts.js test/*.test.js"
  to "node scripts/test-scripts.js". The original mixed vitest-based test files
  (rateLimiter.test.js) into a node --test invocation that would see 0 tests
  and report a false pass; scripts/test-scripts.js also does not use the
  node:test API so --test was wrong for it too.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JfnhH2CghRyxav22rfM8bQ
@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
bimex-frontend Ready Ready Preview, Comment Jul 1, 2026 9:22pm

@David1984TK David1984TK marked this pull request as ready for review July 1, 2026 21:27
@David1984TK David1984TK merged commit eb44363 into main Jul 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants