Skip to content

env: enforce OS_ prefix for all ObjectStack-owned environment variables #1382

Description

@xuyushun441-sys

Background

All ObjectStack-owned environment variables should be prefixed OS_* for namespace hygiene. Audit (see chat) surfaced inconsistencies in three buckets:

  1. Internal vars without OS_ prefix — should be renamed (no upstream convention to honour).
  2. Existing OS_ canonical with legacy alias — alias should be deprecated.
  3. Third-party / SDK conventions — keep as-is (e.g. OPENAI_API_KEY, TURSO_DATABASE_URL, BETTER_AUTH_URL, OAuth *_CLIENT_ID/SECRET, RESEND_API_KEY). Out of scope for this issue.

PORT and DATABASE_URL are Heroku/12-factor industry conventions; they keep working as silent fallbacks for OS_RUNTIME_PORT / OS_DATABASE_URL without deprecation noise.

Scope (Categories ① + ②)

① Rename (internal, no upstream)

CurrentNew
AUTH_BASE_URLOS_AUTH_BASE_URL
CORS_ENABLEDOS_CORS_ENABLED
CORS_ORIGINOS_CORS_ORIGIN
CORS_CREDENTIALSOS_CORS_CREDENTIALS
CORS_MAX_AGEOS_CORS_MAX_AGE
AI_MODELOS_AI_MODEL
MCP_SERVER_ENABLEDOS_MCP_SERVER_ENABLED
MCP_SERVER_NAMEOS_MCP_SERVER_NAME
MCP_SERVER_TRANSPORTOS_MCP_SERVER_TRANSPORT
OBJECTSTACK_DEV_CRYPTO_KEYOS_DEV_CRYPTO_KEY
OBJECTSTACK_METADATA_WRITABLEOS_METADATA_WRITABLE
OBJECTSTACK_NODE_IDOS_NODE_ID

Affected files: packages/cli/src/commands/serve.ts, packages/plugins/plugin-hono-server/src/hono-plugin.ts, packages/adapters/hono/src/index.ts, packages/plugins/plugin-auth/src/auth-manager.ts, packages/services/service-ai/src/plugin.ts, packages/plugins/plugin-mcp-server/src/plugin.ts, examples/app-crm/test-backend.mjs, packages/objectql/src/protocol-meta-types-rich.test.ts, packages/plugins/plugin-webhooks/src/webhook-outbox-plugin.ts.

② Deprecate legacy alias (canonical OS_ already exists)

LegacyCanonicalAction
AUTH_SECRETOS_AUTH_SECRETKeep fallback, log deprecation warning once
ROOT_DOMAINOS_ROOT_DOMAINKeep fallback, log deprecation warning once
OS_MULTI_TENANTOS_MULTI_ORG_ENABLEDKeep fallback, log deprecation warning once

Behaviour

  • For ①: keep reading legacy name as silent fallback for at least one minor release so user .env files don't break, but emit a one-shot console.warn('[OS] Env var X is deprecated; use OS_X') on first read.
  • For ②: same — fallback + one-shot deprecation warning.
  • No legacy reads for brand-new vars (would never have been published).

Out of scope

  • Category ③ third-party conventions.
  • PORT / DATABASE_URL industry fallbacks remain silent.

Acceptance

  • All call sites read OS_-prefixed name first, fall back to legacy.
  • Deprecation warning helper is centralised (not duplicated).
  • Docs / .env.example / changesets updated.
  • AGENTS.md guard: "All new env vars MUST start with OS_".
  • pnpm test green.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions