Plan: AW-3 — Add Redis (BullMQ) to agent-core#
Summary#
Add Redis connectivity via ioredis and BullMQ queue infrastructure to agent-core, registering phase-invoke and phase-result queues and surfacing Redis health in the /health endpoint. This is the shared foundation blocking AW-4, AW-5, AW-7, and AW-9.
Files#
| File | Action | Description |
|---|---|---|
package.json | modify | Add @nestjs/bullmq, bullmq, ioredis dependencies |
src/config/config.schema.ts | modify | Add REDIS_HOST (string, default localhost) and REDIS_PORT (number, default 6379) to Joi schema |
src/app.module.ts | modify | Register BullModule.forRootAsync() with config-driven connection, register phase-invoke and phase-result queues |
src/health/health.service.ts | modify | Inject Redis client (ioredis), add ping() check, return redis field in health response |
src/health/health.controller.ts | modify | Update return type to include redis field |
src/health/health.module.ts | modify | Provide the Redis IORedis client via a custom factory provider |
src/health/health.controller.spec.ts | modify | Update test to mock Redis health and assert new response shape |
src/health/health.service.spec.ts | create | Unit test for HealthService covering connected and disconnected Redis states |
.env | modify | Append REDIS_HOST=localhost and REDIS_PORT=6379 |
Steps#
- Install
@nestjs/bullmq,bullmq, andioredisvianpm install. - Add
REDIS_HOSTandREDIS_PORTtoconfigValidationSchemainsrc/config/config.schema.ts(afterEXCLUDED_REPOS, line ~22). - Append
REDIS_HOST=localhostandREDIS_PORT=6379to.env. - Import
BullModulefrom@nestjs/bullmqinsrc/app.module.ts. AddBullModule.forRootAsync()withConfigServiceinjection (readingREDIS_HOSTandREDIS_PORT) afterAppConfigModule. Registerphase-invokeandphase-resultqueues viaBullModule.registerQueue(). - Create a custom Redis provider in
src/health/health.module.tsusingioredis(new Redis({ host, port })fromConfigService), inject it intoHealthService. - Update
HealthService.getHealth()to callredis.ping(), return{ status, uptime, redis }whereredisis"connected"or"disconnected". - Update
HealthControllerreturn type to match the new response shape. - Update existing
health.controller.spec.tsand createhealth.service.spec.ts— mock Redis client, test connected/disconnected paths. - Run
npm run build,npm run test,npm run lintto verify.
Verification#
npm run buildcompiles cleanly with zero errors.npm run testpasses with no regressions; new health specs pass.npm run lintreports zero warnings.
Risks#
- BullMQ startup failure blocks boot: Redis unavailable at startup should cause a hard failure (fail fast). Verify
BullModule.forRootAsync()propagates connection errors to NestJS bootstrap — if it silently swallows, add anonModuleInitRedis ping guard. - ioredis dual usage: Both BullMQ (internal) and
HealthService(explicit) use ioredis. Use a separate Redis instance for health checks to avoid coupling health probes to BullMQ's internal connection lifecycle.