Skip to content

feat(worker): add X-Entity-Id header to job dispatch pipeline#49

Merged
pyramation merged 1 commit into
mainfrom
feat/jobs-entity-id
May 21, 2026
Merged

feat(worker): add X-Entity-Id header to job dispatch pipeline#49
pyramation merged 1 commit into
mainfrom
feat/jobs-entity-id

Conversation

@pyramation
Copy link
Copy Markdown
Contributor

Summary

Promotes entity_id from a buried payload field to a first-class HTTP header (X-Entity-Id) across the entire job dispatch pipeline:

  1. Worker (job/worker/src/index.ts) — entity_id added to JobRow interface, read from app_jobs.jobs column
  2. Dispatch (job/worker/src/req.ts) — emits X-Entity-Id header alongside X-Database-Id and X-Actor-Id
  3. fn-types (packages/fn-types/src/runtime.ts) — entityId added to FunctionContext.job
  4. fn-runtime (packages/fn-runtime/src/context.ts, server.ts) — reads X-Entity-Id header into context
  5. fn-app (packages/fn-app/src/index.ts) — reads into JobContext, echoes on responses, forwards in callbacks

This 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_id column to app_jobs.jobs.

Review & Testing Checklist for Human

  • Verify X-Entity-Id header is correctly emitted when entity_id is present on the job row (and omitted when NULL — conditional spread preserves backward compat)
  • Verify context.job.entityId is accessible in function handlers
  • Verify the callback to job/server includes X-Entity-Id so the completion handler has entity context for metering

Notes

Backward compatible — when entity_id is NULL/undefined, no header is emitted (same conditional spread pattern as X-Database-Id and X-Actor-Id). Existing functions that don't use context.job.entityId are unaffected.

Link to Devin session: https://app.devin.ai/sessions/8820b639fbd94ac8bfae86cfb01cf827
Requested by: @pyramation

- 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-integration
Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation pyramation merged commit 5b6cc20 into main May 21, 2026
12 checks passed
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