Skip to content

feat(functions): deploy task queue triggers for Cloud Run functions - #11558

Open
Ortes wants to merge 2 commits into
firebase:mainfrom
Fullphysio:fp/dart-task-queue-on-main
Open

Ortes wants to merge 2 commits into
firebase:mainfrom
Fullphysio:fp/dart-task-queue-on-main

Conversation

@Ortes

@Ortes Ortes commented Nov 18, 2026

Copy link
Copy Markdown

Description

Deploying an onTaskDispatched function on the run platform (Cloud Run functions, e.g. Dart) fails with Task Queue triggers for Cloud Run functions are not supported yet.

This PR adds task queue support for run:

  • setTrigger and deleteTrigger upsert and disable the Cloud Tasks queue, as for gcfv2.
  • createRunFunction and updateRunFunction set the task queue invoker with the gcfv2 rules: no default, null on update means private.
  • serviceFromEndpoint stores taskQueueTrigger in the firebase-functions-metadata annotation, and endpointFromService reads it back. Without this, the next deploy reads the service as HTTPS and the planner refuses the change.

It covers only task queues. #10838 covers task queues, schedules and blocking triggers together, but has been marked "do not merge" since July.

Scenarios Tested

  • New unit tests: set and delete triggers on run, invoker on create and update, private when there is no invoker, annotation round-trip.
  • mocha 'src/deploy/**/*.spec.ts' 'src/gcp/**/*.spec.ts': 1775 passing.
  • On a real project, with the same change on top of v15.34.1 and a Dart onTaskDispatched function: create, unchanged re-deploy (an update, not an HTTPS→task queue change), OIDC dispatch from Cloud Tasks (204), retry after a 500, delete, then recreate.

Sample Commands

firebase deploy --only functions now deploys task queue functions on Cloud Run.

@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 adds support for deploying task queue triggers (onTaskDispatched) for Cloud Run functions, updating the fabricator and Run v2 service metadata serialization along with corresponding unit tests. The review feedback highlights two critical issues where an empty invoker array could be passed to run.setInvokerCreate or run.setInvokerUpdate, resulting in a FirebaseError crash. To resolve these, it is recommended to ensure the invoker array is non-empty before creation and to map a null invoker to ["private"] instead of [] during updates.

Comment on lines +1010 to 1019
} else if (backend.isTaskQueueTriggered(endpoint)) {
// Like HTTPS triggers, taskQueueTriggers have an invoker, but unlike HTTPS they don't default
// public.
const invoker = endpoint.taskQueueTrigger.invoker;
if (invoker && !invoker.includes("private")) {
await this.executor
.run(() => run.setInvokerCreate(endpoint.project, serviceName, invoker))
.catch(rethrowAs(endpoint, "set invoker"));
}
}

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.

high

In createRunFunction, if endpoint.taskQueueTrigger.invoker is an empty array ([]), invoker is truthy and !invoker.includes("private") is true, so it will call run.setInvokerCreate(..., []). However, run.setInvokerCreate (defined in src/gcp/run.ts) explicitly throws a FirebaseError if invoker.length === 0. To prevent this crash, we should also check invoker.length > 0 before calling run.setInvokerCreate.

Suggested change
} else if (backend.isTaskQueueTriggered(endpoint)) {
// Like HTTPS triggers, taskQueueTriggers have an invoker, but unlike HTTPS they don't default
// public.
const invoker = endpoint.taskQueueTrigger.invoker;
if (invoker && !invoker.includes("private")) {
await this.executor
.run(() => run.setInvokerCreate(endpoint.project, serviceName, invoker))
.catch(rethrowAs(endpoint, "set invoker"));
}
}
} else if (backend.isTaskQueueTriggered(endpoint)) {
// Like HTTPS triggers, taskQueueTriggers have an invoker, but unlike HTTPS they don't default
// public.
const invoker = endpoint.taskQueueTrigger.invoker;
if (invoker && invoker.length > 0 && !invoker.includes("private")) {
await this.executor
.run(() => run.setInvokerCreate(endpoint.project, serviceName, invoker))
.catch(rethrowAs(endpoint, "set invoker"));
}
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 2d0a65b: the create path now skips an empty invoker, with a test.

Comment on lines +1055 to 1057
} else if (backend.isTaskQueueTriggered(endpoint)) {
invoker = endpoint.taskQueueTrigger.invoker === null ? [] : endpoint.taskQueueTrigger.invoker;
}

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.

high

In updateRunFunction, mapping endpoint.taskQueueTrigger.invoker === null to [] will cause run.setInvokerUpdate to be called with an empty array, which throws FirebaseError("Invoker cannot be an empty array"). In firebase-tools, the standard way to represent a private invoker is ["private"] (as seen in the tests for HTTPS triggers). Since the default for task queue triggers is private, null (which resets the invoker to default) should be mapped to ["private"] instead of []. Note: A similar issue exists in updateV2Function at line 903, which should also be updated to use ["private"] instead of [] to prevent the same crash.

Suggested change
} else if (backend.isTaskQueueTriggered(endpoint)) {
invoker = endpoint.taskQueueTrigger.invoker === null ? [] : endpoint.taskQueueTrigger.invoker;
}
} else if (backend.isTaskQueueTriggered(endpoint)) {
invoker = endpoint.taskQueueTrigger.invoker === null ? ["private"] : endpoint.taskQueueTrigger.invoker;
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 2d0a65b for Cloud Run: null now resets to ["private"] on update, with a test. The gcfv2 line (updateV2Function) predates this PR, so I left it out of scope here.

setTrigger and deleteTrigger threw for platform run, so an
onTaskDispatched function on Cloud Run could not be deployed.

- Create, update and disable the Cloud Tasks queue like for gcfv2.
- Set the task queue invoker on Cloud Run create and update, with the
  same rules as gcfv2: no default, null on update means private.
- Persist taskQueueTrigger in the firebase-functions-metadata annotation
  so the next deploy reads the service back as a task queue function
  instead of HTTPS.
run.setInvokerCreate and run.setInvokerUpdate throw on an empty array.
Skip the create call for an empty invoker, and reset a null invoker to
private on update.
@Ortes
Ortes force-pushed the fp/dart-task-queue-on-main branch from a94fa33 to 2d0a65b Compare November 19, 2026 08:47
Ortes added a commit to Fullphysio/firebase-tools that referenced this pull request Nov 19, 2026
run.setInvokerCreate and run.setInvokerUpdate throw on an empty array.
Skip the create call for an empty invoker, and reset a null invoker to
private on update. Upstream: firebase#11558.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant