feat(worker): add X-Entity-Id header to job dispatch pipeline#49
Merged
Conversation
- Add entity_id to JobRow interface (worker reads from app_jobs.jobs) - Add entityId to RequestOptions and emit X-Entity-Id header on dispatch - Add entityId to FunctionContext.job (fn-types) - Read X-Entity-Id header in fn-runtime context and server - Add entityId to JobContext in fn-app, echo on responses, forward in callbacks This completes the entity_id promotion from DB column to HTTP header, making entity context available to cloud functions for billing/metering.
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Promotes
entity_idfrom a buried payload field to a first-class HTTP header (X-Entity-Id) across the entire job dispatch pipeline:job/worker/src/index.ts) —entity_idadded toJobRowinterface, read fromapp_jobs.jobscolumnjob/worker/src/req.ts) — emitsX-Entity-Idheader alongsideX-Database-IdandX-Actor-Idpackages/fn-types/src/runtime.ts) —entityIdadded toFunctionContext.jobpackages/fn-runtime/src/context.ts,server.ts) — readsX-Entity-Idheader into contextpackages/fn-app/src/index.ts) — reads intoJobContext, echoes on responses, forwards in callbacksThis is Phase 1 of the cloud functions metering architecture. With entity_id available in function context and callbacks, the metering layer can bill compute to the correct entity (org/team within a customer app).
Depends on the companion constructive-db PR which adds the
entity_idcolumn toapp_jobs.jobs.Review & Testing Checklist for Human
X-Entity-Idheader is correctly emitted whenentity_idis present on the job row (and omitted when NULL — conditional spread preserves backward compat)context.job.entityIdis accessible in function handlersX-Entity-Idso the completion handler has entity context for meteringNotes
Backward compatible — when
entity_idis NULL/undefined, no header is emitted (same conditional spread pattern asX-Database-IdandX-Actor-Id). Existing functions that don't usecontext.job.entityIdare unaffected.Link to Devin session: https://app.devin.ai/sessions/8820b639fbd94ac8bfae86cfb01cf827
Requested by: @pyramation