Skip to content

chore: use nullish coalescing for AAI PostgreSQL env fallbacks (#543) - #544

Merged
ct3685 merged 1 commit into
productionfrom
staging
Sep 15, 2025
Merged

chore: use nullish coalescing for AAI PostgreSQL env fallbacks (#543)#544
ct3685 merged 1 commit into
productionfrom
staging

Conversation

@ct3685

@ct3685 ct3685 commented Sep 15, 2025

Copy link
Copy Markdown

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.

## 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.
@vercel

vercel Bot commented Sep 15, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
answerai-docs Building Building Preview Sep 15, 2025 8:03pm
the-answerai Building Building Preview Sep 15, 2025 8:03pm

@ct3685
ct3685 merged commit dd15cc7 into production Sep 15, 2025
5 of 8 checks passed
@maxtechera
maxtechera temporarily deployed to staging - theanswer-iek0 September 15, 2025 20:03 — with Render Inactive

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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".

Comment on lines +181 to +199
// 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants