Skip to content

refactor(kits): read the kit instance id from FIREBASE_KIT_INSTANCE_ID - #3122

Open
cabljac wants to merge 2 commits into
kitsfrom
refactor/kits-firebase-kit-instance-id
Open

refactor(kits): read the kit instance id from FIREBASE_KIT_INSTANCE_ID#3122
cabljac wants to merge 2 commits into
kitsfrom
refactor/kits-firebase-kit-instance-id

Conversation

@cabljac

@cabljac cabljac commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

firebase-tools >= 15.27.0 injects FIREBASE_KIT_INSTANCE_ID for every kit instance, but bigquery-firestore-export, firestore-incremental-capture and firestore-vector-search still declared INSTANCE_ID as a user-supplied param. The params machinery never sees injected values and FIREBASE_ is reserved in .env, so this follows the #3060 pattern: a plain process.env read, the param removed, and configFromEnv throwing an error that names the CLI floor when the variable is missing.

Where a kit derives a discovery-time value from the id (the bigquery Pub/Sub topic default, the vector-search query trigger path) the read happens when the deploy entry loads, so an unsupported CLI fails discovery instead of freezing kit-undefined-* names into the manifest. The vector-search ./lib entry still loads without the variable, as its README promises; a test pins that.

The repo-wide CLI floor now lives in kits/README.md; each kit README repeats it, drops INSTANCE_ID from its params table, and gains a changelog entry.

Tests: bigquery-firestore-export 79, firestore-incremental-capture 75, firestore-vector-search 120, plus tsc -b and prettier. Not verified: a live deploy or emulator run against 15.27.0.

Fixes #3063

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates multiple Firebase kits (bigquery-firestore-export, firestore-incremental-capture, and firestore-vector-search) to retrieve the instance ID from the FIREBASE_KIT_INSTANCE_ID environment variable injected by the Firebase CLI (version 15.27.0 or later), rather than requiring it as a configuration parameter (INSTANCE_ID). This change simplifies configuration and prevents manual synchronization errors. Feedback suggests optimizing the code by reusing the module-level instanceId constant instead of calling instanceIdFromEnv() redundantly at runtime in both bigquery-firestore-export and firestore-vector-search configurations.

bigqueryDatasetLocation: params.bigqueryDatasetLocation.value(),
projectId: projectID.value(),
instanceId: resolvedInstanceId,
instanceId: instanceIdFromEnv(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since instanceId is already resolved at module load time (line 45), calling instanceIdFromEnv() again here is redundant. You can directly use the instanceId constant. Note that if you apply this change, the test throws at runtime when FIREBASE_KIT_INSTANCE_ID is missing in config.test.ts will become obsolete and should be removed, as the import-time check already guarantees the variable is present when the module is loaded.

Suggested change
instanceId: instanceIdFromEnv(),
instanceId,

region: process.env.FUNCTION_REGION,
projectId: projectID.value(),
instanceId: params.instanceId.value(),
instanceId: instanceIdFromEnv(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since instanceId is already resolved at module load time (line 66), calling instanceIdFromEnv() again here is redundant. You can directly use the instanceId constant. Note that if you apply this change, the test throws at runtime when FIREBASE_KIT_INSTANCE_ID is missing in config.test.ts will become obsolete and should be removed, as the import-time check already guarantees the variable is present when the module is loaded.

Suggested change
instanceId: instanceIdFromEnv(),
instanceId,

firebase-tools >= 15.27.0 injects FIREBASE_KIT_INSTANCE_ID for every kit
instance at discovery, deploy, emulator and serve time. The params
machinery never sees injected values and the FIREBASE_ prefix is reserved
in .env files, so bigquery-firestore-export, firestore-incremental-capture
and firestore-vector-search now read the variable directly instead of
declaring a user-supplied INSTANCE_ID param, matching delete-user-data.

Instance-scoped defaults (the Pub/Sub topic, the query trigger document
path) are derived from the variable at import, so an unsupported CLI fails
the discovery pass with an error naming the version floor rather than
freezing kit-undefined-* names into the manifest. configFromEnv throws the
same error at runtime.

The repo-wide CLI floor lives in kits/README.md; each kit README repeats it
next to its kit stanza and drops INSTANCE_ID from its params table.
The ./lib entry re-exports configFromEnv from config.ts, and the README
promises it reads no environment at load so users can import it from their
own triggers. Resolving FIREBASE_KIT_INSTANCE_ID at module scope in
config.ts broke that. The query trigger path is now derived in index.ts,
the deploy-only entry, so discovery still fails loudly on an unsupported
CLI while lib.ts loads without the variable. Tests pin both.

Also asserts on declaredParams in the bigquery-firestore-export test,
narrows the kits README wording to kits that use the instance id, and
rewraps a long README line.
@cabljac
cabljac force-pushed the refactor/kits-firebase-kit-instance-id branch from 9468548 to 6ae6eeb Compare September 7, 2026 10:51
@cabljac cabljac added the kits label Sep 7, 2026
@cabljac cabljac added this to the kits-stable milestone Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(kits): migrate all kits from the INSTANCE_ID param to the injected FIREBASE_KIT_INSTANCE_ID

1 participant