Skip to content

fix(queue): processJob silently drops unrecognized job types with no default case or logging #5836

Description

@JSONbored

Context

processJob in src/queue/job-dispatch.ts is the top-level Cloudflare Queues job dispatcher: a switch (message.type) (line 69) that fans out to dozens of handlers, ending at line 347 with no default: case.

If a message.type doesn't match any case — a stale message left over from a job type that was renamed/removed, a producer/consumer version skew during a rolling deploy, or a corrupted payload — processJob returns silently with zero logging. The caller in src/index.ts (queue() handler, around lines 86-87) then does:

await processJob(env, message.body);
message.ack();

so the message is permanently dropped with no observability at all — no log line, no metric, no audit event.

This is inconsistent with the codebase's own established pattern for "a job type is no longer relevant": src/index.ts already has an explicit, logged retired_review_job_ignored path for hosted-review-execution jobs that are deliberately retired (around line 60):

console.warn(JSON.stringify({ level: "warn", event: "retired_review_job_ignored", messageId: message.id, jobType: message.body.type }));
message.ack();

and the DLQ consumer (src/queue/dlq.ts, processDlqBatch) logs every dropped job via a structured dlq_message_dead_lettered event before acking. An unmatched message.type reaching processJob is the same class of "this job is being silently discarded" event, but today it is the only ack-and-drop path in the queue pipeline with no log line at all.

Requirements

  • Add a default: case to processJob's switch (message.type) in src/queue/job-dispatch.ts.
  • The default case must log a structured event (mirroring the existing retired_review_job_ignored / dlq_message_dead_lettered JSON log shape: level, event, and the job type) so an operator can see in logs/log-search that an unrecognized job type was silently dropped.
  • Use console.warn (matching the retired_review_job_ignored precedent for a non-fatal-but-noteworthy drop), not console.error (reserved for queue_message_failed-class failures elsewhere in src/index.ts).
  • The default case must not throw — processJob must keep returning normally so the existing ack-after-processJob flow in src/index.ts/src/server.ts is unaffected; this is purely an observability addition, not a behavior change to message handling.
  • No change to any of the existing matched case branches.

Deliverables

  • A default: case added to processJob's switch statement in src/queue/job-dispatch.ts that logs an unknown_job_type_ignored-style structured event (job type + any available message metadata) and returns normally.
  • A unit test asserting that calling processJob with an unrecognized message.type logs the new event and does not throw.

Test Coverage Requirements

Aim for 99%+ Codecov patch coverage on the touched lines in src/queue/job-dispatch.ts (src/** is in coverage.include). The new default: branch needs a dedicated test — grepping test/unit/ for processJob plus "unknown"/"default" currently returns no hits, so this is genuinely uncovered today.

Expected Outcome

An unrecognized JobMessage["type"] reaching processJob (from a rolling-deploy version skew, a stale queued message, or a corrupted payload) is now logged with a structured, greppable event before being acked, instead of vanishing with zero trace — matching the observability already given to every other "job intentionally not processed" path in this pipeline (retired_review_job_ignored, dlq_message_dead_lettered).

Links & Resources

  • src/queue/job-dispatch.ts (processJob, switch (message.type) starting line 69, ending line 347, no default:)
  • src/index.ts (retired_review_job_ignored precedent around line 60; the queue() handler's await processJob(env, message.body); message.ack(); call around lines 86-87)
  • src/queue/dlq.ts (processDlqBatch's dlq_message_dead_lettered structured-log precedent)

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:bugGittensor-scored bug fix — scores a 0.05x multiplier.help wantedExtra attention is needed

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions