Skip to main content

APP_VAR Dynamic Substitution V2 (User + Developer Guide)

Document Scope​

This is a technical reference consolidated on 2026-02-11, not a promise that every token, flag or deep link is enabled for every tenant today. Check the current deployment, variable type and configuration before relying on a template. Avoid placing personal data or access tokens in shared documents.

1) User Guide​

What APP_VAR does​

APP_VAR_* tokens are placeholders. A supported resolver can replace them with values from the current user, workspace, channel or browser. If a resolver is disabled, lacks context or fails, the placeholder can remain visible.

Where replacement happens​

Backend substitution, when enabled, occurs before some variable content is saved. Frontend substitution occurs in a rendered view and does not rewrite the stored source. Raw editor text can therefore differ from a preview.

Current tokens you can use​

The 2026-02 registry/reference includes backend tokens APP_VAR_CURRENT_CHANNEL, APP_VAR_CURRENT_WORKSPACE, APP_VAR_USER_ID, APP_VAR_USER_EMAIL, APP_VAR_USER_EMAIL_ACCOUNT, APP_VAR_USER_NAME and APP_VAR_NAME. Frontend core tokens include APP_VAR_BASE_URL, APP_VAR_BROWSER_LOCALE, APP_VAR_CURRENT_TIMEZONE and APP_VAR_CURRENT_TIME. APP_VAR_BAD_PIPELINE was a negative-path example, not a user value.

A token's presence in this list does not establish that its registry entry is active or that a particular save path has the required user and channel context.

Practical examples​

An illustrative template from the original reference:

APP_VAR_BASE_URL/app/channel/APP_VAR_CURRENT_CHANNEL?newSession=true&agent=trinity&import=APP_VAR_CURRENT_CHANNEL&workspace=APP_VAR_CURRENT_WORKSPACE

Use only after confirming that the current route accepts these parameters and that the rendered tokens resolve for the current user. Do not paste a real workspace ID or email into a public document.

Troubleshooting (User)​

  • Compare the raw variable with its rendered preview; frontend replacement belongs to the rendered view.
  • If a token remains, check whether its feature flag and registry entry are active and whether the required channel, workspace and user context exists.
  • If a browser token remains, reload the view and check the browser context. The frontend code has local fallbacks for core browser tokens, but a missing origin, locale or timezone can still leave a placeholder.
  • Do not clear application storage solely because a token is unresolved; ask an administrator to inspect the active configuration if the issue persists.

2) Developer Guide​

High-level architecture​

The historical pipeline expands includes and context, optionally substitutes backend APP_VAR values before persistence, and applies frontend APP_VAR values at render time. Confirm the exact entry point before assuming that a variable passed through each stage.

Registry model​

The original design uses public.mvpl_variables_dynamic with var_name, var_category, resolver_pipeline, active, description and example_value. Read current schema and policy before changing entries. This public reference does not authorize registry edits.

Pipeline step types​

The reference describes context, db, variable and transform steps. The active resolver and permitted data access depend on the deployed implementation and policy.

Security model​

Unresolved backend tokens remain unchanged when the flag is off, context is absent, or resolution fails. Do not treat an unresolved placeholder as an authorization signal. Inspect RLS and context binding for any new registry entry.

Feature flags​

The backend reads app_var_substitution_backend_enabled from mvpl_parameters and defaults to disabled if the value is absent, invalid or unreadable. This reference also records app_var_substitution_frontend_enabled; confirm its current use in the UI rather than assuming it gates all frontend substitution.

Frontend reliability behavior (critical)​

The frontend hook fetches the registry and refreshes it if core browser tokens are missing. It computes fallback values from the browser for APP_VAR_BASE_URL, APP_VAR_BROWSER_LOCALE, APP_VAR_CURRENT_TIMEZONE and APP_VAR_CURRENT_TIME. When a value cannot be derived, the placeholder is retained. The result is a render-time value, not a persisted source update.

Key implementation files​

Relevant frontend source includes src/hooks/useAppVarSubstitution.ts, src/lib/app-var-substitution/, and src/lib/api/appVarRegistry.ts. Backend resolution is in supabase/functions/_shared/app-var-substitution/. Recheck paths against the revision being deployed.

Migrations relevant to this feature​

The original reference listed 20260128094000_seed_app_var_substitution_parameters.sql, 20260205164907_add_app_var_base_url_frontend.sql and 20260211154500_reassign_app_var_name_user_name.sql. A migration file or source revision alone does not prove the target database has applied it; consult that environment's migration ledger.

The template above contains newSession, agent, import and workspace parameters. Treat it as an example from 2026-02. Validate the current parser, user's accessible workspace and agent identifier before distributing a link.

Validation commands​

The former reference listed unit, integration and browser suites for this feature. Run the relevant repository checks on the exact target revision as part of engineering validation; this documentation update makes no test-pass claim.

Known expected behavior​

A backend placeholder may remain when its flag is disabled, context is missing or resolution fails. Frontend placeholders resolve only in the rendered UI when a value is available. APP_VAR_BAD_PIPELINE remains an intentionally unresolved negative example.

3) Quick Reference​

One variable to test everything​

Use a small non-sensitive sample such as APP_VAR_BASE_URL in a rendered preview, then compare it with the raw source. A resolved sample proves only that token in that context; it does not certify every token or tenant.