Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0f467a3
fix: v2 to v1 downgrade failing with CPU error
IzaakGough Aug 4, 2026
84b5409
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Aug 6, 2026
09a8a26
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Aug 6, 2026
dc89614
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Aug 13, 2026
e167c47
fix: narrow the platform-change guard to cpu and fail fast on downgrade
IzaakGough Aug 13, 2026
8f824ec
fix: also reject redeploying a Cloud Run service as gcfv1
IzaakGough Aug 13, 2026
907a080
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Aug 14, 2026
f7bc29a
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Aug 17, 2026
5188d2a
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Aug 20, 2026
04e9d54
test: pin the downgrade check ahead of the timeout check
IzaakGough Aug 20, 2026
9e4c525
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Aug 24, 2026
e412f3e
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Aug 24, 2026
1653a7c
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Aug 24, 2026
f1df3f3
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Aug 25, 2026
3796ea3
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Aug 27, 2026
e491efa
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Aug 28, 2026
538bc9a
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Sep 1, 2026
6faf71a
fix: tell the user how to recreate a function as GCFv1
IzaakGough Sep 1, 2026
b5579a9
test: cover the Cloud Run to GCFv1 downgrade and the delete instruction
IzaakGough Sep 1, 2026
2318b14
chore: add changelog entry for the GCFv1 downgrade error
IzaakGough Sep 1, 2026
f3b6624
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Sep 3, 2026
5a6860d
fix: report every downgraded function, not just the first
IzaakGough Sep 3, 2026
f1690f2
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Sep 4, 2026
c602cef
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Sep 10, 2026
b2122eb
fix: reject the v2 to v1 downgrade before inheriting existing settings
IzaakGough Sep 10, 2026
87da259
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Sep 11, 2026
26960ad
Merge branch 'main' into @invertase/fix-issue-5461
IzaakGough Sep 11, 2026
c636a44
Merge remote-tracking branch 'origin/main' into @invertase/fix-issue-…
IzaakGough Sep 30, 2026
4516d77
Merge remote-tracking branch 'origin/main' into @invertase/fix-issue-…
IzaakGough Sep 30, 2026
202e8cb
Merge remote-tracking branch 'origin/main' into @invertase/fix-issue-…
IzaakGough Oct 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- [Fixed] Report the GCFv2-to-GCFv1 downgrade error during validation instead of a misleading CPU error (#5461).
45 changes: 45 additions & 0 deletions src/deploy/functions/functionsDeployHelper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,51 @@ describe("functionsDeployHelper", () => {
});
});

describe("generationDowngradeMessage", () => {
const v1: backend.Endpoint = { ...ENDPOINT, platform: "gcfv1" };

it("rejects an existing gcfv2 function being redeployed as gcfv1", () => {
const have: backend.Endpoint = { ...ENDPOINT, platform: "gcfv2" };

expect(helper.generationDowngradeMessage(v1, have)).to.match(
/cannot be downgraded from GCFv2 to GCFv1/,
);
});

it("rejects an existing Cloud Run service being redeployed as gcfv1", () => {
const have: backend.Endpoint = { ...ENDPOINT, platform: "run" };

expect(helper.generationDowngradeMessage(v1, have)).to.match(
/cannot be downgraded from Cloud Run to GCFv1/,
);
});

it("tells the user how to recreate the function as gcfv1", () => {
const have: backend.Endpoint = { ...ENDPOINT, platform: "gcfv2" };

expect(helper.generationDowngradeMessage(v1, have)).to.contain(
"firebase functions:delete foo --region us-central1",
);
});

it("allows every other change of platform", () => {
for (const [want, have] of [
["gcfv1", "gcfv1"],
["gcfv2", "gcfv1"],
["gcfv2", "run"],
["run", "gcfv2"],
] as const) {
expect(
helper.generationDowngradeMessage(
{ ...ENDPOINT, platform: want },
{ ...ENDPOINT, platform: have },
),
`${have} to ${want}`,
).to.be.undefined;
}
});
});

describe("isCodebasePartiallyFiltered", () => {
it("should return false when filters is undefined or empty", () => {
expect(helper.isCodebasePartiallyFiltered("codebaseA")).to.be.false;
Expand Down
21 changes: 21 additions & 0 deletions src/deploy/functions/functionsDeployHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,27 @@ export function getFunctionLabel(fn: backend.TargetIds & { codebase?: string }):
return id;
}

/**
* Explains why a gcfv1 endpoint may not take over a name that already exists as something
* else, or undefined if the update is legal. A gcfv1 function is a different resource to a
* gcfv2 function or a Cloud Run service, so the CLI cannot update one into the other.
* Shared so that prepare-time validation and the release planner cannot drift apart.
*/
export function generationDowngradeMessage(
want: backend.Endpoint,
have: backend.Endpoint,
): string | undefined {
if (want.platform !== "gcfv1" || have.platform === "gcfv1") {
return undefined;
}
const from = have.platform === "gcfv2" ? "GCFv2" : "Cloud Run";
return (
`[${getFunctionLabel(want)}] Functions cannot be downgraded from ${from} to GCFv1. ` +
`To recreate it as GCFv1, delete the existing function first: ` +
`firebase functions:delete ${want.id} --region ${want.region}`
);
}

/**
* Returns list of codebases specified in firebase.json filtered by --only filters if present.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/deploy/functions/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
managedSA = `${saToCreate}@${projectId}.iam.gserviceaccount.com`;
}

const newEtag = iam.computeRolesEtag(requiredRoles!);

Check warning on line 171 in src/deploy/functions/prepare.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Forbidden non-null assertion

for (const endpoint of backend.allEndpoints(want)) {
endpoint.serviceAccount = managedSA;
Expand Down Expand Up @@ -207,10 +207,10 @@
if (existingManagedSA) {
try {
haveRoles = await resourcemanager.getServiceAccountRoles(projectId, managedSA);
} catch (err: any) {

Check warning on line 210 in src/deploy/functions/prepare.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type
throw new FirebaseError(
`The declarative security roles for codebase ${codebase} have changed, but you do not have access to see what has changed. Please ask an IAM administrator to perform the next deploy.`,
{ original: err },

Check warning on line 213 in src/deploy/functions/prepare.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe assignment of an `any` value
);
}
}
Expand Down Expand Up @@ -414,8 +414,10 @@
context.codebaseDeployEvents[codebase].runtime = wantBuild.runtime;
}

// ===Phase 2.5. Before proceeding further, let's make sure that we don't have conflicting function names.
// ===Phase 2.5. Before proceeding further, let's make sure that we don't have conflicting function
// names, and that nothing is taking over a name that already exists as a newer generation.
validate.endpointsAreUnique(wantBackends);
validate.noGenerationDowngrades(wantBackends, existingBackend);

// ===Phase 3. Prepare source for upload.
context.sources = {};
Expand Down Expand Up @@ -594,7 +596,7 @@
// Match triggers.
try {
resolvedRegion = await resolveRegionForTrigger(endpoint);
} catch (err: any) {

Check warning on line 599 in src/deploy/functions/prepare.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type
logger.debug(
`Failed to resolve region for endpoint ${id}. Defaulting to ${FALLBACK_DEPLOYMENT_REGION}.`,
getErrStack(err),
Expand Down Expand Up @@ -707,7 +709,7 @@
.filter(
(ep) =>
backend.isBlockingTriggered(ep) &&
AUTH_BLOCKING_EVENTS.includes(ep.blockingTrigger.eventType as any),

Check warning on line 712 in src/deploy/functions/prepare.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type

Check warning on line 712 in src/deploy/functions/prepare.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe argument of type `any` assigned to a parameter of type `"providers/cloud.auth/eventTypes/user.beforeCreate" | "providers/cloud.auth/eventTypes/user.beforeSignIn" | "providers/cloud.auth/eventTypes/user.beforeSendEmail" | "providers/cloud.auth/eventTypes/user.beforeSendSms"`
) as (backend.Endpoint & backend.BlockingTriggered)[];

if (authBlockingEndpoints.length === 0) {
Expand Down Expand Up @@ -943,7 +945,7 @@
* a function and doesn't have one. To avoid repetitive nagging, only warn on the first
* deploy of the function.
*/
export async function warnIfNewGenkitFunctionIsMissingSecrets(

Check warning on line 948 in src/deploy/functions/prepare.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Missing return type on function
have: backend.Backend,
want: backend.Backend,
options: DeployOptions,
Expand Down
4 changes: 3 additions & 1 deletion src/deploy/functions/release/planner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,9 @@ describe("planner", () => {
const want: backend.Endpoint = { ...func("id", "region"), platform: "gcfv1" };
const have: backend.Endpoint = { ...func("id", "region"), platform: "gcfv2" };

expect(() => planner.checkForIllegalUpdate(want, have)).to.throw();
expect(() => planner.checkForIllegalUpdate(want, have)).to.throw(
/cannot be downgraded from GCFv2 to GCFv1/,
);
});
});

Expand Down
8 changes: 4 additions & 4 deletions src/deploy/functions/release/planner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
EndpointFilter,
endpointMatchesAnyFilter,
generationDowngradeMessage,
getFunctionLabel,
isCodebasePartiallyFiltered,
} from "../functionsDeployHelper";
Expand Down Expand Up @@ -318,7 +319,7 @@
if (have.eventTrigger.eventType !== v2events.PUBSUB_PUBLISH_EVENT) {
return false;
}
return have.eventTrigger.eventFilters!.topic !== want.eventTrigger.eventFilters!.topic;

Check warning on line 322 in src/deploy/functions/release/planner.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Forbidden non-null assertion

Check warning on line 322 in src/deploy/functions/release/planner.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Forbidden non-null assertion
}

/** Whether a user upgraded a scheduled function (which goes from Pub/Sub to HTTPS). */
Expand Down Expand Up @@ -389,10 +390,9 @@
)}] Changing from ${haveType} function to ${wantType} function is not allowed. Please delete your function and create a new one instead.`,
);
}
if (want.platform === "gcfv1" && have.platform === "gcfv2") {
throw new FirebaseError(
`[${getFunctionLabel(want)}] Functions cannot be downgraded from GCFv2 to GCFv1`,
);
const downgrade = generationDowngradeMessage(want, have);
Comment thread
IzaakGough marked this conversation as resolved.
Resolved
if (downgrade) {
throw new FirebaseError(downgrade);
}

// We need to call from module exports so tests can stub this behavior, but that
Expand Down
58 changes: 58 additions & 0 deletions src/deploy/functions/validate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

describe("functionNamesAreValid", () => {
it("should allow properly formatted function names", () => {
const functions: any[] = [

Check warning on line 49 in src/deploy/functions/validate.spec.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type
{
id: "my-function-1",
},
Expand Down Expand Up @@ -613,6 +613,64 @@
});
});

describe("noGenerationDowngrades", () => {
const ENDPOINT_BASE: backend.Endpoint = {
platform: "gcfv1",
id: "id",
region: "us-east1",
project: "project",
entryPoint: "func",
runtime: "nodejs16",
httpsTrigger: {},
};

it("rejects downgrading an existing gcfv2 function to gcfv1", () => {
const want = { default: backend.of(ENDPOINT_BASE) };
const have = backend.of({ ...ENDPOINT_BASE, platform: "gcfv2", cpu: 1 });

expect(() => validate.noGenerationDowngrades(want, have)).to.throw(
/cannot be downgraded from GCFv2 to GCFv1/,
);
});

it("rejects redeploying an existing Cloud Run service as gcfv1", () => {
const want = { default: backend.of(ENDPOINT_BASE) };
const have = backend.of({ ...ENDPOINT_BASE, platform: "run", cpu: 1 });

expect(() => validate.noGenerationDowngrades(want, have)).to.throw(
/cannot be downgraded from Cloud Run to GCFv1/,
);
});

it("reports every downgraded function, not just the first", () => {
const want = {
one: backend.of({ ...ENDPOINT_BASE, id: "a" }),
two: backend.of({ ...ENDPOINT_BASE, id: "b" }),
};
const have = backend.of(
{ ...ENDPOINT_BASE, id: "a", platform: "gcfv2" },
{ ...ENDPOINT_BASE, id: "b", platform: "run" },
);

let err: unknown;
try {
validate.noGenerationDowngrades(want, have);
} catch (e: unknown) {
err = e;
}

expect(err).to.be.instanceOf(FirebaseError);
expect((err as FirebaseError).message).to.match(/a\(us-east1\)[\s\S]*GCFv2/);
expect((err as FirebaseError).message).to.match(/b\(us-east1\)[\s\S]*Cloud Run/);
});

it("allows a gcfv1 function that does not exist yet", () => {
const want = { default: backend.of(ENDPOINT_BASE) };

expect(() => validate.noGenerationDowngrades(want, backend.empty())).to.not.throw();
});
});

describe("endpointsAreUnqiue", () => {
const ENDPOINT_BASE: backend.Endpoint = {
platform: "gcfv2",
Expand Down
31 changes: 30 additions & 1 deletion src/deploy/functions/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import * as clc from "colorette";
import { FirebaseError } from "../../error";
import { getSecretVersion, SecretVersion } from "../../gcp/secretManager";
import { logger } from "../../logger";
import { EndpointFilter, endpointMatchesFilter, getFunctionLabel } from "./functionsDeployHelper";
import {
EndpointFilter,
endpointMatchesFilter,
generationDowngradeMessage,
getFunctionLabel,
} from "./functionsDeployHelper";
import { serviceForEndpoint } from "./services";
import * as fsutils from "../../fsutils";
import * as backend from "./backend";
Expand Down Expand Up @@ -132,6 +137,30 @@ export function endpointsAreValid(
cpuConfigIsValid(endpoints);
}

/**
* Rejects an existing gcfv2 function or Cloud Run service being redeployed as gcfv1. Runs
* before the source is prepared, and before inferDetailsFromExisting copies settings that
* are only legal on the existing generation onto the gcfv1 endpoint.
*/
export function noGenerationDowngrades(
wantBackends: Record<string, backend.Backend>,
existingBackend: backend.Backend,
): void {
const msgs: string[] = [];
for (const wantBackend of Object.values(wantBackends)) {
for (const want of backend.allEndpoints(wantBackend).sort(backend.compareFunctions)) {
const have = existingBackend.endpoints[want.region]?.[want.id];
const msg = have && generationDowngradeMessage(want, have);
if (msg) {
msgs.push(msg);
}
}
}
if (msgs.length) {
throw new FirebaseError(msgs.join("\n"));
}
}

/**
* Validate that endpoints have valid CPU configuration.
* Enforces https://cloud.google.com/run/docs/configuring/cpu.
Expand Down
Loading