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)

Current New
AUTH_BASE_URL OS_AUTH_BASE_URL
CORS_ENABLED OS_CORS_ENABLED
CORS_ORIGIN OS_CORS_ORIGIN
CORS_CREDENTIALS OS_CORS_CREDENTIALS
CORS_MAX_AGE OS_CORS_MAX_AGE
AI_MODEL OS_AI_MODEL
MCP_SERVER_ENABLED OS_MCP_SERVER_ENABLED
MCP_SERVER_NAME OS_MCP_SERVER_NAME
MCP_SERVER_TRANSPORT OS_MCP_SERVER_TRANSPORT
OBJECTSTACK_DEV_CRYPTO_KEY OS_DEV_CRYPTO_KEY
OBJECTSTACK_METADATA_WRITABLE OS_METADATA_WRITABLE
OBJECTSTACK_NODE_ID OS_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)

Legacy Canonical Action
AUTH_SECRET OS_AUTH_SECRET Keep fallback, log deprecation warning once
ROOT_DOMAIN OS_ROOT_DOMAIN Keep fallback, log deprecation warning once
OS_MULTI_TENANT OS_MULTI_ORG_ENABLED Keep 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