Skip to content

fix(server): use account identity for duplicate-session idle policy (… - #120

Merged
leocagli merged 4 commits into
Bitcoindefi:mainfrom
franklincg:fastmoney-openao16-final
Aug 28, 2026
Merged

fix(server): use account identity for duplicate-session idle policy (…#120
leocagli merged 4 commits into
Bitcoindefi:mainfrom
franklincg:fastmoney-openao16-final

Conversation

@franklincg

@franklincg franklincg commented Aug 24, 2026

Copy link
Copy Markdown

Fixes #16


Summary by Gitar

  • Connection Policy:
    • Replaced IP-based duplicate session idle penalty with account identity grouping in connectionPolicy.ts
    • Added comprehensive unit tests in testConnectionPolicy.ts covering CGNAT and missing account scenarios

This will update automatically on new commits.

@leocagli

Copy link
Copy Markdown
Collaborator

Te aviso que esta quedo en conflicto con main y necesita un rebase tuyo.

Hoy entraron cuatro merges que tocan esa zona: #109 (los seed que faltaban, npcs.json y objs.json), #80 (apagado ordenado, que reescribio parte de server/src/server.ts), #114 (orden de schema.sql y el ranking) y #121 (los pings como actividad, tambien en server/src/server.ts).

La issue #16 sigue asignada a vos y la PR queda abierta. Cuando rebasees contra main apruebo la corrida del CI y la miramos.

Dos cosas que cambiaron y te conviene saber:

El CI ahora sirve. main estaba en rojo desde el dia que se agrego el workflow, por esos dos archivos de seed que faltaban. Desde hoy esta entero en verde, asi que si el CI de tu rama pasa, quiere decir algo.

Las corridas de los PRs de fork quedan esperando aprobacion. Nadie las estaba aprobando, por eso tu PR nunca mostro resultado. Ya lo estoy destrabando a mano; avisa cuando rebasees y la apruebo.

Comment thread server/package.json
"clean": "rm -rf dist",
"build": "pnpm run clean && tsc && node scripts/copy-assets.cjs",
"dev": "NODE_ENV=development tsx watch src/server.ts",
"test": "tsx --test tests/**/*.test.ts",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Bug: New npm scripts reference missing files

Both new scripts point at paths that don't exist in the repo: test:client-activity runs src/scripts/testClientActivityPolicy.ts (not present in server/src/scripts/) and test runs tsx --test tests/**/*.test.ts (no server/tests/ directory exists). pnpm test and pnpm test:client-activity will fail immediately, and any CI wired to test will break. Add the missing test file/directory in this PR, or remove the script entries until the tests land.

Was this helpful? React with 👍 / 👎

Comment thread server/package.json
"clean": "rm -rf dist",
"build": "pnpm run clean && tsc && node scripts/copy-assets.cjs",
"dev": "NODE_ENV=development tsx watch src/server.ts",
"test": "tsx --test tests/**/*.test.ts",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Quality: Test glob may not expand without shell globstar

tsx --test tests/**/*.test.ts relies on ** recursive globbing, which requires shell globstar (bash) or is passed literally to tsx depending on the runner. If the pattern isn't expanded, the test command silently matches nothing or errors. Prefer letting the test runner do the matching (e.g. tsx/node's own glob support) or a portable pattern to avoid environment-dependent behavior.

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown
Code Review 🚫 Blocked 0 resolved / 4 findings

Fixes duplicate-session idle policy to use account identity instead of IP-based grouping with added unit tests, but the PR is blocked by four issues: missing test files referenced in npm scripts (testClientActivityPolicy.ts and tests/ directory), a shell-dependent glob pattern in the test script, a missing gracefulShutdown.ts module imported by server.ts that causes startup failure, and a type mismatch on RuntimeClient.close() that doesn't accept the arguments being passed. These must be resolved before merge.

🚨 Bug: Imported ./gracefulShutdown module is missing from this branch

📄 server/src/server.ts:7 📄 server/src/server.ts:211-225

server.ts adds import { createGracefulShutdown } from "./gracefulShutdown" and calls it at module load, but no gracefulShutdown.ts/.js exists in this branch (git ls-tree HEAD server/src shows nothing; the commit 8b28af6 that added it lives only on origin/main and is not an ancestor of this PR). As written the branch fails to compile/resolve the module and the server crashes on startup. Either add gracefulShutdown.ts to this branch or properly merge the main commit that introduces it before merging.

⚠️ Bug: New npm scripts reference missing files

📄 server/package.json:28 📄 server/package.json:35

Both new scripts point at paths that don't exist in the repo: test:client-activity runs src/scripts/testClientActivityPolicy.ts (not present in server/src/scripts/) and test runs tsx --test tests/**/*.test.ts (no server/tests/ directory exists). pnpm test and pnpm test:client-activity will fail immediately, and any CI wired to test will break. Add the missing test file/directory in this PR, or remove the script entries until the tests land.

💡 Quality: Test glob may not expand without shell globstar

📄 server/package.json:28

tsx --test tests/**/*.test.ts relies on ** recursive globbing, which requires shell globstar (bash) or is passed literally to tsx depending on the runner. If the pattern isn't expanded, the test command silently matches nothing or errors. Prefer letting the test runner do the matching (e.g. tsx/node's own glob support) or a portable pattern to avoid environment-dependent behavior.

💡 Quality: client.close called with args but typed as () => void

📄 server/src/server.ts:244

closeClients() calls client.close(1001, SHUTDOWN_CLIENT_MESSAGE), but RuntimeClient.close is declared as close: () => void in types/runtime.ts, so this is a type error under strict compilation even though the underlying WebSocket accepts (code, reason). Widen the RuntimeClient.close signature to (code?: number, reason?: string) => void.

🤖 Prompt for agents
Code Review: Fixes duplicate-session idle policy to use account identity instead of IP-based grouping with added unit tests, but the PR is blocked by four issues: missing test files referenced in npm scripts (`testClientActivityPolicy.ts` and `tests/` directory), a shell-dependent glob pattern in the test script, a missing `gracefulShutdown.ts` module imported by `server.ts` that causes startup failure, and a type mismatch on `RuntimeClient.close()` that doesn't accept the arguments being passed. These must be resolved before merge.

1. ⚠️ Bug: New npm scripts reference missing files
   Files: server/package.json:28, server/package.json:35

   Both new scripts point at paths that don't exist in the repo: `test:client-activity` runs `src/scripts/testClientActivityPolicy.ts` (not present in server/src/scripts/) and `test` runs `tsx --test tests/**/*.test.ts` (no server/tests/ directory exists). `pnpm test` and `pnpm test:client-activity` will fail immediately, and any CI wired to `test` will break. Add the missing test file/directory in this PR, or remove the script entries until the tests land.

2. 💡 Quality: Test glob may not expand without shell globstar
   Files: server/package.json:28

   `tsx --test tests/**/*.test.ts` relies on `**` recursive globbing, which requires shell `globstar` (bash) or is passed literally to tsx depending on the runner. If the pattern isn't expanded, the test command silently matches nothing or errors. Prefer letting the test runner do the matching (e.g. tsx/node's own glob support) or a portable pattern to avoid environment-dependent behavior.

3. 🚨 Bug: Imported ./gracefulShutdown module is missing from this branch
   Files: server/src/server.ts:7, server/src/server.ts:211-225

   server.ts adds `import { createGracefulShutdown } from "./gracefulShutdown"` and calls it at module load, but no gracefulShutdown.ts/.js exists in this branch (git ls-tree HEAD server/src shows nothing; the commit 8b28af6 that added it lives only on origin/main and is not an ancestor of this PR). As written the branch fails to compile/resolve the module and the server crashes on startup. Either add gracefulShutdown.ts to this branch or properly merge the main commit that introduces it before merging.

4. 💡 Quality: client.close called with args but typed as () => void
   Files: server/src/server.ts:244

   closeClients() calls `client.close(1001, SHUTDOWN_CLIENT_MESSAGE)`, but RuntimeClient.close is declared as `close: () => void` in types/runtime.ts, so this is a type error under strict compilation even though the underlying WebSocket accepts (code, reason). Widen the RuntimeClient.close signature to `(code?: number, reason?: string) => void`.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Important

Your trial ends in 4 days — upgrade now to keep code review, CI analysis, auto-apply, custom automations, and more.

Was this helpful? React with 👍 / 👎 | Gitar

@franklincg

Copy link
Copy Markdown
Author

Hi @leocagli — I rebased/updated #120 against the current main and resolved the conflict with the recent server changes, including #121.

The CGNAT/account-identity fix for #16 is preserved, and the PR is mergeable again.

Could you approve/run the CI when you have a chance? Thanks.

@franklincg

franklincg commented Aug 28, 2026 via email

Copy link
Copy Markdown
Author

@leocagli

Copy link
Copy Markdown
Collaborator

Mergeado. Verificado en local con los comandos del CI, no sólo mirando el verde:

pnpm install --frozen-lockfile   rc=0
pnpm run lint                    rc=0
pnpm exec tsc --noEmit           rc=0
pnpm test                        3 pass, 0 fail
pnpm run build                   rc=0
pnpm exec tsx src/scripts/testConnectionPolicy.ts   connection policy tests passed

Lo que me convenció del enfoque es esta línea de connectionPolicy.ts:

// Never fall back to public IP when the authenticated account identity is absent.
if (!accountId) {
    continue;
}

Ahí está el bug entero. Dos personas atrás del mismo CGNAT son dos cuentas distintas, así que dejan de penalizarse entre sí; una persona con dos sesiones de la misma cuenta se sigue penalizando, que es lo que la política quería decir desde el principio. Y sacarlo a su propio módulo lo vuelve testeable sin levantar el servidor.

Gracias por el rebase y por dejar escrito en el comentario qué commit y qué checks, que ahorra tener que ir a buscarlo.

@leocagli
leocagli merged commit 12b967c into Bitcoindefi:main Aug 28, 2026
6 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.

Jugadores moviles se desconectan entre si por el timeout de IP duplicada (CGNAT)

2 participants