Conversation
- bypass auth check for /health in UM - undo eslint fix in gateway
- Add pong-ai-service to docker-compose and dev-compose - Fix healthcheck to use GET instead of HEAD - Add environment variables to .env - Update requirements.txt with missing dependencies
…odify AI invitation logic
fix: kept these chages for later
ai-opponent integration
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 18 out of 19 changed files in this pull request and generated 13 comments.
Comments suppressed due to low confidence (1)
srcs/gateway/src/controllers/health.controller.ts:64
- In
healthAllHandler,results[name]is used inside theservices.map(...)callback, butnameis no longer defined after switching fromObject.entries(SERVICES)toObject.values(SERVICES). This will either fail TypeScript compilation or throw aReferenceErrorat runtime, and also means yourresultsobject is never populated under the intended service keys. You likely want to restore iteration over[name, service]entries or derive a key (e.g. the map key orserviceKey) and use that consistently for both success and error branches.
const res = await fetch(`https://${service.host}:${service.port}/health`, fetchOptions);
results[name] = res.status === 200 ? 'healthy' : 'unhealthy';
} catch (error) {
results[name] = `unhealthy (error: ${(error as Error).message})`;
}
| self.model_path = model_path | ||
| self.model: Optional[PPO] = None | ||
| self.sessions: Dict[str, GameSession] = {} | ||
| self.load_model() | ||
|
|
There was a problem hiding this comment.
AIService can leave self.model as None when load_model doesn’t find or fails to load a checkpoint, but downstream GameSession instances created from this service call get_ai_action() which blindly does self.model.predict(...). This will raise an AttributeError at runtime as soon as the RL WebSocket/session endpoints try to use the model. Consider either preventing session creation when no model is loaded, or explicitly handling the missing-model case (e.g. by failing fast with a clear error or initializing a fresh model) instead of passing None into GameSession.
srcs/pong-ai/pong_server.py
Outdated
| "ball_x": float(self.env.ball_x), | ||
| "ball_y": float(self.env.ball_y), | ||
| "ball_vx": float(self.env.ball_vx), | ||
| "ball_vy": float(self.env.ball_vy), | ||
| "ai_paddle_y": float(self.env.ai_paddle_y), |
There was a problem hiding this comment.
GameSession.step() assumes the environment exposes attributes like player_paddle_y, ball_x, ball_y, ball_vx, and ball_vy, but the PongEnv implementation in this service only returns observations via _convert_state and never defines these attributes. As written, any call to step() will raise AttributeError on the PongEnv instance, so the /session/create and /ws/game/{session_id} endpoints cannot function correctly. You should either adapt GameSession to work with PongEnv’s API (e.g. operate purely on the observation vector) or extend PongEnv to maintain and expose the fields GameSession expects.
srcs/pong-ai/pong_server.py
Outdated
|
|
||
| return { | ||
| "status": "success", | ||
| "session_id": session_id, | ||
| "message": "AI player joined the game", | ||
| "paddle": "right" | ||
| } | ||
|
|
||
| except Exception as e: | ||
| raise HTTPException(status_code=500, detail=str(e)) |
There was a problem hiding this comment.
This join_game handler has two except Exception as e blocks in a row, and the return after raise HTTPException is unreachable, which makes the control flow confusing and redundant. The second except will never be hit, and the dead return path suggests an earlier implementation that wasn’t fully cleaned up. It would be clearer and less error-prone to keep a single except block here and remove the unreachable return code.
| return { | |
| "status": "success", | |
| "session_id": session_id, | |
| "message": "AI player joined the game", | |
| "paddle": "right" | |
| } | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) |
srcs/pong-ai/pong_server.py
Outdated
srcs/pong-ai/pong_server.py
Outdated
| except Exception as e: | ||
| raise HTTPException(status_code=500, detail=str(e)) |
There was a problem hiding this comment.
This except block handling Exception is unreachable; as this except block also handles Exception.
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) |
| @@ -1 +1 @@ | |||
| import { Vector2 } from './game.vector.js'; | |||
There was a problem hiding this comment.
remove import
ESLint extension in VSCode can be set up with "Fix all auto-fixable problems"
| '/api/users/health', | ||
| '/api/game/health', | ||
| '/api/block/health', | ||
| '/api/game/create-session', |
There was a problem hiding this comment.
Je pense pas que cette route devrait etre dans les PUBLIC_ROUTES. Creer une game session necessite de l'utilisateur qu il soit enregistré.
There was a problem hiding this comment.
Ces displayProvider.ts sont amené a disparaitre au profit de l'implementation REACT
codastream
left a comment
There was a problem hiding this comment.
Hâte de le voir s'entrainer et fonctionner avec game.
Il faudrait probablement régler avant de fusionner certains points
- adapter le service en wss
- la cohérence des données renvoyées par env et la manière dont elles sont lues dans server
- éviter d'ajouter des erreurs ESLint : unused imports, no any, ...
Ainsi que
- l'architecture API : pourquoi get et post pour join-game ? utiliser un préfixe plus court ?
- le découpage des classes (faire une pour la connexion)
- éviter d'avoir trop de code en dur pour les url, ports, actions, ...
- vérifier les deps (requests, pygame) + fixer les versions
- validation des données entrantes (pydantic ?)
Et quelques optimisations pour maintenant ou plus tard
- timeout et resiliency patterns (reconnexion, ..)
- normalisation des valeurs
| @@ -1,2 +1,2 @@ | |||
| import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify'; | |||
| import { logger } from '../utils/logger.js'; | |||
There was a problem hiding this comment.
tu veux que je supprimes import { logger } from '../utils/logger.js'; n'est-ce pas ?
There was a problem hiding this comment.
| export async function healthAllHandler(req: FastifyRequest) { |
| }); | ||
|
|
||
| // POST version - accepts sessionId in body | ||
| app.post('/join-game', async (request, reply) => { |
There was a problem hiding this comment.
quel est l'intérêt d'avoir 2 routes pour join game ? POST est peut-être plus approprié
srcs/pong-ai/pong_server.py
Outdated
| "message": "AI is already in this game" | ||
| } | ||
|
|
||
| # Create AI player |
There was a problem hiding this comment.
il faudrait trouver un mécanisme pour supprimer les AIPlayer
bloc finally dans webSocket game selon Gemini
srcs/pong-ai/pong_server.py
Outdated
| self.model = None | ||
|
|
||
| def create_session(self, session_id: str) -> GameSession: | ||
| if session_id in self.sessions: |
There was a problem hiding this comment.
| if session_id in self.sessions: | |
| if self.model is None: | |
| raise RuntimeError("No model") | |
| if session_id in self.sessions: |
There was a problem hiding this comment.
je ne sais pas comment fonctionnent les checkpoints. il doit y avoir moyen de reduire leur nombre
Makefile
Outdated
| $(D_COMPOSE) up -d --build $(GAME_SERVICE_NAME) | ||
| block: | ||
| $(D_COMPOSE) up -d --build $(BK_SERVICE_NAME) | ||
| pong: |
Makefile docs/pong-ai.md srcs/dev-docker-compose.yml srcs/docker-compose.yml srcs/pong-ai/Dockerfile srcs/pong-ai/ai_player.py srcs/pong-ai/requirements.txt
Co-authored-by: Francois <multicompte+github@outlook.fr>
Co-authored-by: Francois <multicompte+github@outlook.fr>
Co-authored-by: Francois <multicompte+github@outlook.fr>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ection handling in AIPlayer
codastream
left a comment
There was a problem hiding this comment.
si on utilise pong_500000, peut-on supprimer les autres checkpoints ?
il y a quelques erreurs de linter qui sont faciles a supprimer (unused vars)
| import { handleClientMessage } from '../service/game.communication.js'; | ||
| import { GameSettings } from '../core/game.types.js'; | ||
| import { WebSocket } from 'ws'; | ||
| import { WS_CLOSE } from '../core/game.state.js'; |
srcs/game/src/routes/game.routes.ts
Outdated
| newGameSession, | ||
| healthCheck, | ||
| gameSettings, | ||
| resetGame, |
srcs/game/src/routes/game.routes.ts
Outdated
| healthCheck, | ||
| gameSettings, | ||
| resetGame, | ||
| stepGame, |
srcs/game/src/routes/game.routes.ts
Outdated
| gameSettings, | ||
| resetGame, | ||
| stepGame, | ||
| getGameState, |
There was a problem hiding this comment.
| getGameState, |
| @@ -0,0 +1,41 @@ | |||
| import { FastifyInstance } from 'fastify'; | |||
| import { proxyRequest, webSocketProxyRequest } from '../utils/proxy.js'; | |||
There was a problem hiding this comment.
| import { proxyRequest, webSocketProxyRequest } from '../utils/proxy.js'; | |
| import { proxyRequest } from '../utils/proxy.js'; |
There was a problem hiding this comment.
est-ce qu'un build multistage builder + runner ferait gagner de la place ?
There was a problem hiding this comment.
ça fera ~200-300MB économisés,
This pull request introduces a new RL-trained Pong AI service and integrates it throughout the stack, enabling users to play against an AI opponent. It adds new backend endpoints for AI interaction, updates the gateway to proxy AI-related requests, and enhances the frontend to support AI game sessions. Additionally, it includes supporting infrastructure updates, such as Docker and service orchestration, and some dependency upgrades.
Pong AI Service Integration
pong-ai-serviceto bothdocker-compose.ymlanddev-docker-compose.yml, including build context, environment variables, healthcheck, and model volume mounting. [1] [2]Dockerfileand aREADME.mdfor the Pong AI service, describing setup, training, API, and usage. [1] [2]Backend API Enhancements for RL/AI
/rl/reset,/rl/step, and/rl/statefor game session management and step-wise control. [1] [2] [3]GameStateinterface and game engine to expose ball velocity, needed for RL environments. [1] [2]Gateway and Proxy Updates
/pong-ai/join-gamerequests to the Pong AI service, supporting both GET and POST. [1] [2]Frontend (Game UI) Enhancements
Infrastructure and Miscellaneous
package.jsonandpackage-lock.jsonfor improved compatibility and security. [1] [2] [3] [4] [5]These changes collectively enable a user to play against a reinforcement learning-based AI opponent in Pong, with all necessary backend, proxy, and frontend support.