Repository navigation
BE-1233: Add the hash-queue crate for RabbitMQ jobs and an entity embedding worker - #10700
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## fs/be-1250-send-signed-webhooks-to-subscriber-endpoints-over #10700 +/- ##
==============================================================================================
Coverage 70.37% 70.38%
==============================================================================================
Files 2138 2141 +3
Lines 226210 226436 +226
Branches 9801 9820 +19
==============================================================================================
+ Hits 159205 159381 +176
- Misses 64953 65004 +51
+ Partials 2052 2051 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
705ace4 to
88344dd
Compare
| /// Run the worker that starts entity embedding workflows for batches of queued entities. | ||
| EmbeddingWorker(Box<EmbeddingWorkerArgs>), |
There was a problem hiding this comment.
For simplicity this week we can keep it here, but we should think about moving away from the monolithic binary.
| .init(); | ||
|
|
||
| let count = env::args().nth(1).map_or( | ||
| NonZeroU32::new(1_100).expect("the default job count should not be zero"), |
There was a problem hiding this comment.
1100 as the default job count?
| //! Consumes `embedding.entity` and nothing else. A batch holds up to 500 jobs, or the jobs that | ||
| //! arrived within 5 seconds of its first one. Handling a batch takes 2 seconds, which stands in for | ||
| //! starting its embedding workflows. |
There was a problem hiding this comment.
Where do the numbers come from?
| /// The queue's name, which is also the routing key its jobs are published under. | ||
| const NAME: &'static str; | ||
| /// The wait before each retry. A job is attempted once more than there are delays. | ||
| const RETRY_DELAYS: &'static [Duration]; | ||
| /// When a consumer of this queue hands jobs to its handler. | ||
| const BATCH: BatchPolicy = BatchPolicy::SINGLE; |
There was a problem hiding this comment.
Is there a specific reason why we use consts here instead of functions? Or do the name/relays needs to be static?
| jsonschema = { version = "0.51.0", default-features = false } | ||
| jsonwebtoken = { version = "10.3.0", default-features = false } | ||
| kiddo = { version = "6.0.0" } | ||
| lapin = { version = "4.13.0", default-features = false } |
There was a problem hiding this comment.
Without the default features, what TLS etc. is used?
PR overviewThis PR adds the The worker accepts actor identity from job messages, allowing a publisher with broker credentials to select the graph identity used for entity reads and embedding updates. The Compose configuration also exposes a broker with default credentials to peers that can reach the developer host, enabling unauthorized job access and manipulation. Missing TLS support and a mutable broker image tag remain additional transport-protection and supply-chain concerns; no issues have been addressed yet. Open issues (4)
Fixed/addressed: 0 · PR risk: 7/10 Reviews
|
PR SummaryMedium Risk Overview Adds Not in this PR: the graph API still does not enqueue embedding jobs—it still triggers workflows directly on write. Reviewed by Cursor Bugbot for commit 88344dd. Bugbot is set up for automated code reviews on this repo. Configure here. |
TimDiekmann
left a comment
There was a problem hiding this comment.
The PR is currently failing a lot of CIs. I'd propose we unstack it until that is resolved so follow-up PRs don't get blocked on that.
There was a problem hiding this comment.
🟡 Changes recommended
Publisher confirms can ACK unroutable retries, causing permanent job loss when the original is acknowledged; mandatory publishing and returned-message failure handling are needed.
1 open issue
What changed in this PR
Adds RabbitMQ job infrastructure and a standalone worker that batches entity embedding requests into Temporal workflows. Graph writes still start workflows directly; queue publishing is not yet integrated.
Changes:
- Introduces durable queues with delayed retries, parking, batching, and consumer priorities.
- Adds an embedding worker that groups entities by actor.
- Provides local RabbitMQ setup, examples, and documentation.
| File | Description |
|---|---|
libs/@local/queue/turbo.json |
Defines crate maintenance tasks. |
libs/@local/queue/src/topology.rs |
Declares queues, routing, and batch policies. |
libs/@local/queue/src/queues/webhook_delivery.rs |
Defines placeholder webhook jobs. |
libs/@local/queue/src/queues/temporal_trigger.rs |
Defines placeholder workflow jobs. |
libs/@local/queue/src/queues/mod.rs |
Registers queue topology. |
libs/@local/queue/src/queues/entity_embedding.rs |
Defines embedding jobs and batching. |
libs/@local/queue/src/lib.rs |
Exposes the queue API. |
libs/@local/queue/src/error.rs |
Defines queue operation errors. |
libs/@local/queue/src/broker.rs |
Implements publishing, consumption, and retries. |
libs/@local/queue/README.md |
Documents queue behavior and usage. |
libs/@local/queue/examples/webhook-delivery/README.md |
Explains the webhook example. |
libs/@local/queue/examples/webhook-delivery/producer.rs |
Publishes sample webhook jobs. |
libs/@local/queue/examples/webhook-delivery/consumer.rs |
Demonstrates retries and parking. |
libs/@local/queue/examples/temporal-trigger/README.md |
Explains the Temporal example. |
libs/@local/queue/examples/temporal-trigger/producer.rs |
Publishes a workflow trigger. |
libs/@local/queue/examples/temporal-trigger/consumer.rs |
Starts a placeholder workflow. |
libs/@local/queue/examples/entity-embedding/README.md |
Explains batching and priority examples. |
libs/@local/queue/examples/entity-embedding/producer.rs |
Publishes and times sample embedding jobs. |
libs/@local/queue/examples/entity-embedding/consumer.rs |
Demonstrates prioritized batch consumption. |
libs/@local/queue/docs/dependency-diagram.mmd |
Adds the crate dependency diagram. |
libs/@local/queue/compose.yml |
Provides local RabbitMQ infrastructure. |
libs/@local/queue/Cargo.toml |
Declares crate dependencies and examples. |
Cargo.toml |
Registers the crate and Lapin dependency. |
Cargo.lock |
Records resolved dependency changes. |
apps/hash-graph/src/subcommand/mod.rs |
Registers the embedding-worker command. |
apps/hash-graph/src/subcommand/embedding_worker.rs |
Starts embedding workflows per actor batch. |
apps/hash-graph/Cargo.toml |
Adds the queue dependency. |
Review effort: Balanced
| BasicPublishOptions::default(), | ||
| body, | ||
| properties, | ||
| ) | ||
| .await? | ||
| .await | ||
| } | ||
| .await | ||
| .change_context(QueueError::Publish)?; | ||
|
|
||
| if confirmation.is_ack() { |
| volumes: | ||
| - rabbitmq-data:/var/lib/rabbitmq | ||
| ports: | ||
| - "5672:5672" |
There was a problem hiding this comment.
Medium: Broker is network-exposed with default credentials
Both port mappings publish on all host interfaces by default, while the official image disables the guest account's loopback restriction; a fresh broker retains guest:guest with full access to the default virtual host. A peer that can reach the developer host can therefore authenticate and publish, consume, or purge jobs. (docs.docker.com)
Bind both mappings to loopback (127.0.0.1:5672:5672 and 127.0.0.1:15672:15672), and require dedicated credentials before using this stack on a shared network.
| # Private third-party dependencies | ||
| derive_more = { workspace = true, features = ["display", "error"] } | ||
| futures-util = { workspace = true } | ||
| lapin = { workspace = true, features = ["default-runtime"] } |
There was a problem hiding this comment.
Medium: Broker client has no TLS backend
The workspace disables Lapin's default features, and restoring only default-runtime leaves this client without a TLS backend; the resolved AMQP connector rejects amqps:// rather than establishing an encrypted connection. (raw.githubusercontent.com) Enable a certificate-validating backend here and use amqps:// for remote brokers so credentials and job traffic can be protected.
| lapin = { workspace = true, features = ["default-runtime"] } | |
| lapin = { workspace = true, features = ["default-runtime", "rustls"] } |
|
|
||
| services: | ||
| rabbitmq: | ||
| image: rabbitmq:4.4-management |
There was a problem hiding this comment.
Low: Broker image is not digest-pinned
rabbitmq:4.4-management is a mutable tag, so a subsequent pull can execute different upstream code without a reviewed repository change. As supply-chain hardening, pin a reviewed image digest and keep it current through dependency-update PRs. (docs.docker.com)
| for (actor_id, entity_ids) in entities_by_actor { | ||
| let entity_ids = entity_ids.into_iter().collect::<Vec<_>>(); | ||
| temporal | ||
| .start_update_entity_embeddings_workflow(actor_id, &entity_ids, exclusions) |
There was a problem hiding this comment.
Medium: Worker trusts actor identity from the queue message
The worker takes actor_id straight from the JSON job body and passes it as the workflow's authentication.actorId. createAndStoreEntityEmbeddingsActivity then reads the entities and calls updateEntityEmbeddings on the graph with actorHeaders(params.authentication.actorId). Nothing ties that actor to whoever published the job. That makes every service with broker credentials a trusted source of graph identity, the same as the server's write path.
The topology makes this harder to lock down with RabbitMQ permissions. Every job uses one shared hash topic exchange, retries are published to the default exchange (which routes to any queue by name), and Broker::connect declares every queue. So every service that uses this crate, including the future webhook delivery worker that talks to external endpoints, needs write access that also reaches embedding.entity. Any of them can then queue jobs that run as any actor, an instance admin included.
The impact is limited to embedding reads and writes and the OpenAI calls. Still, I'd fix this before a production publisher exists. Options:
- Have the worker run as a fixed system or machine actor instead of a caller-supplied one (the TODO in
entity_embedding.rsalready mentions this). - Authenticate the message, for example with an HMAC over the payload using a key only the graph holds.
- At minimum, put this queue on its own exchange or vhost so per-service write permissions can restrict who publishes to it.
I couldn't confirm how the production broker's users and permissions will be set up.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 88344dd. Configure here.
| temporal | ||
| .start_update_entity_embeddings_workflow(actor_id, &entity_ids, exclusions) | ||
| .await?; | ||
| } |
There was a problem hiding this comment.
Retries duplicate embedding workflows
Medium Severity
If starting updateEntityEmbeddings fails for one actor, the whole batch is failed and retried, including actors whose workflows already started. start_update_entity_embeddings_workflow allocates a new workflow id each call, and job.id is ignored, so those entities start again. A crash after Temporal accepts the starts and before the ack does the same.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 88344dd. Configure here.
| delivery | ||
| .ack(BasicAckOptions::default()) | ||
| .await | ||
| .change_context(QueueError::Consume)?; |
There was a problem hiding this comment.
Unsent acknowledgements counted as success
Medium Severity
Delivery::ack returns Ok(false) when the acknowledgement is not sent, because the channel is closed or the acker is already spent. settle treats that as success. A failed job may already have been copied to its retry or parking queue, while the original delivery stays unacked and is delivered again.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 88344dd. Configure here.
Benchmark results
|
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| resolve_policies_for_actor | user: empty, selectivity: high, policies: 2002 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: medium, policies: 1002 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: high, policies: 3314 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: medium, policies: 1527 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: high, policies: 2079 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: medium, policies: 1034 | Flame Graph |
policy_resolution_medium
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| resolve_policies_for_actor | user: empty, selectivity: high, policies: 102 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: medium, policies: 52 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: high, policies: 269 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: medium, policies: 108 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: high, policies: 134 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: medium, policies: 64 | Flame Graph |
policy_resolution_none
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| resolve_policies_for_actor | user: empty, selectivity: high, policies: 2 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: medium, policies: 2 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: high, policies: 9 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: medium, policies: 4 | Flame Graph |
policy_resolution_small
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| resolve_policies_for_actor | user: empty, selectivity: high, policies: 52 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: empty, selectivity: medium, policies: 26 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: high, policies: 94 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: seeded, selectivity: medium, policies: 27 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: high, policies: 67 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: low, policies: 1 | Flame Graph | |
| resolve_policies_for_actor | user: system, selectivity: medium, policies: 30 | Flame Graph |
read_scaling_complete
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_id;one_depth | 1 entities | Flame Graph | |
| entity_by_id;one_depth | 10 entities | Flame Graph | |
| entity_by_id;one_depth | 25 entities | Flame Graph | |
| entity_by_id;one_depth | 5 entities | Flame Graph | |
| entity_by_id;one_depth | 50 entities | Flame Graph | |
| entity_by_id;two_depth | 1 entities | Flame Graph | |
| entity_by_id;two_depth | 10 entities | Flame Graph | |
| entity_by_id;two_depth | 25 entities | Flame Graph | |
| entity_by_id;two_depth | 5 entities | Flame Graph | |
| entity_by_id;two_depth | 50 entities | Flame Graph | |
| entity_by_id;zero_depth | 1 entities | Flame Graph | |
| entity_by_id;zero_depth | 10 entities | Flame Graph | |
| entity_by_id;zero_depth | 25 entities | Flame Graph | |
| entity_by_id;zero_depth | 5 entities | Flame Graph | |
| entity_by_id;zero_depth | 50 entities | Flame Graph |
read_scaling_linkless
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_id | 1 entities | Flame Graph | |
| entity_by_id | 10 entities | Flame Graph | |
| entity_by_id | 100 entities | Flame Graph | |
| entity_by_id | 1000 entities | Flame Graph | |
| entity_by_id | 10000 entities | Flame Graph |
representative_read_entity
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/block/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/book/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/building/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/organization/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/page/v/2
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/person/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/playlist/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/song/v/1
|
Flame Graph | |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/uk-address/v/1
|
Flame Graph |
representative_read_entity_type
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| get_entity_type_by_id | Account ID: bf5a9ef5-dc3b-43cf-a291-6210c0321eba
|
Flame Graph |
representative_read_multiple_entities
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_property | traversal_paths=0 | 0 | |
| entity_by_property | traversal_paths=255 | 1,resolve_depths=inherit:1;values:255;properties:255;links:127;link_dests:126;type:true | |
| entity_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:0;links:0;link_dests:0;type:false | |
| entity_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:0;links:1;link_dests:0;type:true | |
| entity_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:2;links:1;link_dests:0;type:true | |
| entity_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:2;properties:2;links:1;link_dests:0;type:true | |
| link_by_source_by_property | traversal_paths=0 | 0 | |
| link_by_source_by_property | traversal_paths=255 | 1,resolve_depths=inherit:1;values:255;properties:255;links:127;link_dests:126;type:true | |
| link_by_source_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:0;links:0;link_dests:0;type:false | |
| link_by_source_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:0;links:1;link_dests:0;type:true | |
| link_by_source_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:0;properties:2;links:1;link_dests:0;type:true | |
| link_by_source_by_property | traversal_paths=2 | 1,resolve_depths=inherit:0;values:2;properties:2;links:1;link_dests:0;type:true |
scenarios
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| full_test | query-limited | Flame Graph | |
| full_test | query-unlimited | Flame Graph | |
| linked_queries | query-limited | Flame Graph | |
| linked_queries | query-unlimited | Flame Graph |



Purpose
Graph changes have to reach consumers outside the graph: webhook delivery, workflow triggers and entity embeddings. Today the graph starts an embedding workflow directly on every write. This PR adds
hash-queue, a crate for RabbitMQ job queues with delayed retries, and a first consumer of it: an embedding worker that starts one embedding workflow per batch of entities instead of one per write.Changes
hash-queuedefines a queue as a job type with aQueueimplementation.Broker::publishsends a job,Broker::consumeruns a handler on it. The README describes the topology.failed.<queue>, so other queues can bind to it.BatchPolicy: the most jobs in a batch and the longest a batch waits. A batch has one outcome, but each job keeps its own retry count.Broker::with_consumer_prioritylets one worker's batches fill before the next worker receives jobs.webhook.deliveryandtemporal.trigger, which are placeholders for now, andembedding.entity.hash-graph embedding-workerconsumesembedding.entityin batches of up to 500 and startsupdateEntityEmbeddingsonce per actor in a batch. It needs RabbitMQ and Temporal, not Postgres, so it can run and scale on its own.examples, with a README on how to run it against the RabbitMQ incompose.yml.Known issues
embedding.entityjobs yet. It still starts embedding workflows itself, and only the example producer publishes jobs.