chore: use nullish coalescing for AAI PostgreSQL env fallbacks (#543) - #544
Conversation
## Title fix: use nullish coalescing for AAI PostgreSQL env fallbacks ## Description This change updates the environment variable fallback logic in `packages/server/src/commands/base.ts` for AAI PostgreSQL configuration. It replaces logical OR assignment (`||=`) with nullish coalescing assignment (`??=`) across all AAI-related Postgres variables and updates the accompanying comment to reflect the new behavior. ### Motivation Motivation inferred from the diff comments: ensure fallbacks only apply when variables are `null` or `undefined`, not when they are any falsy value. This avoids unintentionally overriding intentionally provided but falsy environment values. If broader motivation exists, it is not evident beyond the comment change. ### Modified Areas **File:** `packages/server/src/commands/base.ts` - Comment updated to: “AAI PostgreSQL fallbacks - Individual variable fallbacks using nullish coalescing.” - For each scope (RecordManager, AgentMemory, VectorStore), the following variables now use `??=` instead of `||=`: - `AAI_DEFAULT_POSTGRES_RECORDMANAGER_HOST` - `AAI_DEFAULT_POSTGRES_RECORDMANAGER_PORT` - `AAI_DEFAULT_POSTGRES_RECORDMANAGER_DATABASE` - `AAI_DEFAULT_POSTGRES_RECORDMANAGER_USER` - `AAI_DEFAULT_POSTGRES_RECORDMANAGER_PASSWORD` - `AAI_DEFAULT_POSTGRES_AGENTMEMORY_HOST` - `AAI_DEFAULT_POSTGRES_AGENTMEMORY_PORT` - `AAI_DEFAULT_POSTGRES_AGENTMEMORY_DATABASE` - `AAI_DEFAULT_POSTGRES_AGENTMEMORY_USER` - `AAI_DEFAULT_POSTGRES_AGENTMEMORY_PASSWORD` - `AAI_DEFAULT_POSTGRES_VECTORSTORE_HOST` - `AAI_DEFAULT_POSTGRES_VECTORSTORE_PORT` - `AAI_DEFAULT_POSTGRES_VECTORSTORE_DATABASE` - `AAI_DEFAULT_POSTGRES_VECTORSTORE_USER` - `AAI_DEFAULT_POSTGRES_VECTORSTORE_PASSWORD` ### Behavior & Impact - **Previous behavior (`||=`):** would assign a fallback when the left-hand env var was any falsy value (e.g., empty string `""`, `"0"`). - **New behavior (`??=`):** assigns a fallback only when the left-hand env var is `null` or `undefined`. - **Impact:** Reduces accidental overrides of defined-but-falsy environment variables and aligns fallback logic with intent expressed in the comment’s precedence rules. ### Config/Env/Deps - **Env:** Uses existing `DATABASE_*` values as fallbacks with updated nullish semantics. - **Dependencies:** None added/removed. - **Migrations/Schema:** None apparent.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Codex Review: Here are some suggestions.
Reply with @codex fix comments to fix any unresolved comments.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
| // AAI PostgreSQL fallbacks - Individual variable fallbacks using nullish coalescing | ||
| // Precedence order: Individual AAI secrets > Individual AAI variables > Shared DATABASE_SECRET | ||
| process.env.AAI_DEFAULT_POSTGRES_RECORDMANAGER_HOST ||= process.env.DATABASE_HOST | ||
| process.env.AAI_DEFAULT_POSTGRES_RECORDMANAGER_PORT ||= process.env.DATABASE_PORT | ||
| process.env.AAI_DEFAULT_POSTGRES_RECORDMANAGER_DATABASE ||= process.env.DATABASE_NAME | ||
| process.env.AAI_DEFAULT_POSTGRES_RECORDMANAGER_USER ||= process.env.DATABASE_USER | ||
| process.env.AAI_DEFAULT_POSTGRES_RECORDMANAGER_PASSWORD ||= process.env.DATABASE_PASSWORD | ||
| process.env.AAI_DEFAULT_POSTGRES_RECORDMANAGER_HOST ??= process.env.DATABASE_HOST | ||
| process.env.AAI_DEFAULT_POSTGRES_RECORDMANAGER_PORT ??= process.env.DATABASE_PORT | ||
| process.env.AAI_DEFAULT_POSTGRES_RECORDMANAGER_DATABASE ??= process.env.DATABASE_NAME | ||
| process.env.AAI_DEFAULT_POSTGRES_RECORDMANAGER_USER ??= process.env.DATABASE_USER | ||
| process.env.AAI_DEFAULT_POSTGRES_RECORDMANAGER_PASSWORD ??= process.env.DATABASE_PASSWORD | ||
|
|
||
| process.env.AAI_DEFAULT_POSTGRES_AGENTMEMORY_HOST ||= process.env.DATABASE_HOST | ||
| process.env.AAI_DEFAULT_POSTGRES_AGENTMEMORY_PORT ||= process.env.DATABASE_PORT | ||
| process.env.AAI_DEFAULT_POSTGRES_AGENTMEMORY_DATABASE ||= process.env.DATABASE_NAME | ||
| process.env.AAI_DEFAULT_POSTGRES_AGENTMEMORY_USER ||= process.env.DATABASE_USER | ||
| process.env.AAI_DEFAULT_POSTGRES_AGENTMEMORY_PASSWORD ||= process.env.DATABASE_PASSWORD | ||
| process.env.AAI_DEFAULT_POSTGRES_AGENTMEMORY_HOST ??= process.env.DATABASE_HOST | ||
| process.env.AAI_DEFAULT_POSTGRES_AGENTMEMORY_PORT ??= process.env.DATABASE_PORT | ||
| process.env.AAI_DEFAULT_POSTGRES_AGENTMEMORY_DATABASE ??= process.env.DATABASE_NAME | ||
| process.env.AAI_DEFAULT_POSTGRES_AGENTMEMORY_USER ??= process.env.DATABASE_USER | ||
| process.env.AAI_DEFAULT_POSTGRES_AGENTMEMORY_PASSWORD ??= process.env.DATABASE_PASSWORD | ||
|
|
||
| process.env.AAI_DEFAULT_POSTGRES_VECTORSTORE_HOST ||= process.env.DATABASE_HOST | ||
| process.env.AAI_DEFAULT_POSTGRES_VECTORSTORE_PORT ||= process.env.DATABASE_PORT | ||
| process.env.AAI_DEFAULT_POSTGRES_VECTORSTORE_DATABASE ||= process.env.DATABASE_NAME | ||
| process.env.AAI_DEFAULT_POSTGRES_VECTORSTORE_USER ||= process.env.DATABASE_USER | ||
| process.env.AAI_DEFAULT_POSTGRES_VECTORSTORE_PASSWORD ||= process.env.DATABASE_PASSWORD | ||
| process.env.AAI_DEFAULT_POSTGRES_VECTORSTORE_HOST ??= process.env.DATABASE_HOST | ||
| process.env.AAI_DEFAULT_POSTGRES_VECTORSTORE_PORT ??= process.env.DATABASE_PORT | ||
| process.env.AAI_DEFAULT_POSTGRES_VECTORSTORE_DATABASE ??= process.env.DATABASE_NAME | ||
| process.env.AAI_DEFAULT_POSTGRES_VECTORSTORE_USER ??= process.env.DATABASE_USER | ||
| process.env.AAI_DEFAULT_POSTGRES_VECTORSTORE_PASSWORD ??= process.env.DATABASE_PASSWORD |
There was a problem hiding this comment.
[P1] Restore fallback when AAI env vars set to empty strings
Switching the AAI PostgreSQL fallback logic from ||= to ??= means the fallback now triggers only when the left-hand env var is null or undefined. In many deployments (and .env templates) these AAI vars are declared as AAI_DEFAULT_POSTGRES_*= with no value, which produces an empty string at runtime. With the new nullish assignment those empty strings are preserved, so host/user/password remain blank and the service attempts to connect with invalid credentials instead of inheriting the shared DATABASE_* settings. The previous ||= semantics correctly treated empty strings as unset. Unless you can guarantee the variables are either omitted or fully populated, this change will break existing configurations that rely on blank values to fall back.
Useful? React with 👍 / 👎.
Title
fix: use nullish coalescing for AAI PostgreSQL env fallbacks
Description
This change updates the environment variable fallback logic in
packages/server/src/commands/base.tsfor AAI PostgreSQL configuration. It replaces logical OR assignment (||=) with nullish coalescing assignment (??=) across all AAI-related Postgres variables and updates the accompanying comment to reflect the new behavior.Motivation
Motivation inferred from the diff comments: ensure fallbacks only apply when variables are
nullorundefined, not when they are any falsy value. This avoids unintentionally overriding intentionally provided but falsy environment values. If broader motivation exists, it is not evident beyond the comment change.Modified Areas
File:
packages/server/src/commands/base.ts??=instead of||=:AAI_DEFAULT_POSTGRES_RECORDMANAGER_HOSTAAI_DEFAULT_POSTGRES_RECORDMANAGER_PORTAAI_DEFAULT_POSTGRES_RECORDMANAGER_DATABASEAAI_DEFAULT_POSTGRES_RECORDMANAGER_USERAAI_DEFAULT_POSTGRES_RECORDMANAGER_PASSWORDAAI_DEFAULT_POSTGRES_AGENTMEMORY_HOSTAAI_DEFAULT_POSTGRES_AGENTMEMORY_PORTAAI_DEFAULT_POSTGRES_AGENTMEMORY_DATABASEAAI_DEFAULT_POSTGRES_AGENTMEMORY_USERAAI_DEFAULT_POSTGRES_AGENTMEMORY_PASSWORDAAI_DEFAULT_POSTGRES_VECTORSTORE_HOSTAAI_DEFAULT_POSTGRES_VECTORSTORE_PORTAAI_DEFAULT_POSTGRES_VECTORSTORE_DATABASEAAI_DEFAULT_POSTGRES_VECTORSTORE_USERAAI_DEFAULT_POSTGRES_VECTORSTORE_PASSWORDBehavior & Impact
||=): would assign a fallback when the left-hand env var was any falsy value (e.g., empty string"","0").??=): assigns a fallback only when the left-hand env var isnullorundefined.Config/Env/Deps
DATABASE_*values as fallbacks with updated nullish semantics.