Skip to content

workers: preserve job payload type through definition, registry, and enqueue #1455

Description

@rickylabs

Summary

NetScript 0.0.5 types a worker handler payload while building a job, but erases that payload type before registration and enqueue. An application cannot derive a safe job id -> payload map from the published job definition/registry, and a payload for one job can compile when enqueued for another.

Published 0.0.5 behavior

  1. defineJob(...).payload<TPayload>() narrows the handler payload while JobBuilder is being constructed.
  2. build() returns JobDefinition<TId> whose public shape retains id, entrypoint, name, and topic, but no payload type/schema.
  3. The workers service JobTriggerInput exposes payload?: Record<string, unknown>.
  4. Trigger-core enqueueJob<TJobId, TPayload>(job, options) infers the options payload independently because JobDefinition<TJobId> has no payload parameter.
  5. Generated job registries use JobHandler<any>, so generation cannot recover the erased payload type.

That means the following application invariant is not expressible using the published types: selecting literal job ID embed-document must require EmbedDocumentPayload, while selecting transcribe-image must require TranscribeImagePayload.

Expected

  • Preserve payload type/schema in a shape such as JobDefinition<TId, TPayload>.
  • Generate/export a literal job-ID-to-payload registry/type map.
  • Bind triggerJob and trigger-core enqueueJob payload to the selected job definition/ID.
  • Preserve the handler type in generated registration instead of JobHandler<any> at the application boundary.
  • Reuse the same definition for runtime validation, so producer and consumer cannot drift.

Consumer impact

EIS-Chat must temporarily own a small shared job contract to restore compile-time and runtime safety around an otherwise native workersContract + createServiceClient transport. That compatibility seam will be removed when the published registry carries the payload mapping.

Related: #1451 tracks generated job registry operational metadata and handler erasure, but does not cover the job-ID-to-payload contract at trigger/enqueue call sites.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions