Skip to content

feat(database-redis): add Redis adapter and persistent Redis state - #1292

Merged
leifermendez merged 1 commit into
builderbotfrom
feat/database-redis-state
Nov 18, 2026
Merged

leifermendez merged 1 commit into
builderbotfrom
feat/database-redis-state

Conversation

@leifermendez

@leifermendez leifermendez commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Que tipo de Pull Request es?

  • Mejoras
  • Bug
  • Docs / tests

Descripción

Redis adapter and persistent state, split out of #1281 so the Redis feature can be reviewed without the unrelated core-pipeline rewrite.

This is unit A of two. Unit B — handleMsg fallback rewrite, addAnswer ref change, BUILDERBOT_SILENT and the generator CRLF normalization — is deliberately not included here.

Cambios

Área Cambio
packages/database-redis/** New package: history adapter backed by ioredis (keys bot:history:<prefix>:<from>, TTL renewed per message, SCAN-based clearAll)
packages/bot/src/context/redisStateClass.ts New RedisState backend: multi().hset() + conditional expire, atomic, no GET/SET race
packages/bot/src/types.ts GeneralArgs.RedisOptions; BotState reads return Promise so an external backend fits the contract
packages/bot/src/core/coreClass.ts Wiring only: imports RedisState, stateHandler: SingleState | RedisState, constructor picks the backend from RedisOptions, await at the two state reads, as BotStateStandAlone cast, awaits in endFlow
packages/cli/src/configuration/index.ts redis added to the database list
scripts/generate/** Redis database zone; templates use await state.get(...)
starters/apps/** Regenerated (151 files touched, 30 new Redis starters)
lerna.json, root package.json New package registered; packages/database-redis added to root workspaces
pnpm-lock.yaml ioredis@5.11.1, no registry snapshot of @builderbot/bot

Por qué el workspaces raíz importa

packages/database-redis was already in lerna.json but missing from root package.json workspaces, which is the only input of scripts/check-workspace-deps.js. Without that entry the guard was blind to the package. It is added here.

Verificación ejecutada

Check Resultado
Full suite (pnpm test, 30 projects) passed — one more project than before (the new package)
packages/bot 222 passed, 1 pre-existing skip (211 before; +11 redisState)
packages/database-redis 6/6
pnpm run generate:check passed against the committed starters
@builderbot/bot build OK
@builderbot/database-redis build OK
Lockfile ioredis@5.11.1 resolved; zero @builderbot/bot registry snapshots

Contrato async: qué cambia para terceros

BotState.get/getMyState/getAllState/clear now declare Promise. With the in-memory backend the values still arrive immediately, so await works and existing runtime behaviour is unchanged; the difference is that TypeScript now requires await at call sites. The generated templates were updated accordingly. This is a public typing change, which is why it is called out instead of hidden inside a dependency bump.

Fuera de alcance

handleMsg fallback rewrite, addAnswer ref change, BUILDERBOT_SILENT, generator CRLF normalization and their tests (0.2.5-handlemsg-fallbacks, hunks of coreClass.test/events.test/0.0.1-flow-events). Those go to unit B.

Checklist

  • Tests, builds and generate:check executed on this tree
  • Full monorepo suite green (30 projects)
  • CI at this PR head — run 44280893205: Tests and Templates in sync (including Check generated templates) both passed

Split from #1281, keeping only the Redis feature:

- packages/database-redis: history adapter backed by ioredis.
- bot: RedisState backend selected through GeneralArgs.RedisOptions; BotState
  reads are Promise-returning so an external backend fits the contract.
- manager: no changes here; the async contract is additive for in-memory state.
- cli/zones/starters: redis database option plus regenerated templates using
  `await state.get(...)`.
- root workspaces: packages/database-redis added, which check:workspace-deps
  needs to see the package at all.

Out of scope (kept for a separate unit): handleMsg fallback rewrite, addAnswer
ref change, BUILDERBOT_SILENT and the generator CRLF normalization.
@leifermendez leifermendez added the enhancement New feature or request label Nov 18, 2026
@leifermendez
leifermendez merged commit 09638c1 into builderbot Nov 18, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant