Skip to content

id-mail(deploy): validate() crashes on null config entries instead of reporting them, and a config without retire passes validation then crashes the real deploy #6947

Closed

Description

@dezren39

Problem

nixos/services/id-mail/worker/deploy.mjs opens with the promise that it "Validates config.json" before any bws/wrangler/Cloudflare work, and validate() (deploy.mjs:124-179) is written as an aggregator: it collects every problem into a list and the caller throws one config.json is invalid: error naming them all (deploy.mjs:34-37). That contract fails for two classes of shape the validator itself is the last line of defense against:

1. validate() crashes on null entries instead of reporting them

validate() dereferences nested entries without a null/object check, so a config carrying a null where an object belongs dies with a raw TypeError naming no config field, and any other problems in the same config are never reported:

  • top-level null config → TypeError: Cannot read properties of null (reading 'worker') at deploy.mjs:135 (the very first check)
  • templates: [null] → TypeError ... (reading 'subject') at deploy.mjs:153
  • callers: { "amd": null } → TypeError ... (reading 'tokenKey') at deploy.mjs:163
  • a null grant (callers.amd.transports.email: null) → TypeError ... (reading 'mode') at deploy.mjs:169

Control: a merely wrong value (e.g. worker: "BAD NAME") is reported correctly — Error: config.json is invalid:\n worker must be a lowercase name — so the aggregator works for scalar mistakes and only collapses on null object entries.

2. A config that passes validation crashes the real deploy: retire is optional to validate(), required by the deploy flow

validate() checks c.retire ?? [] (deploy.mjs:141 — an absent retire is valid), but the deploy sequence iterates it unconditionally at deploy.mjs:87: for (const name of config.retire). A config with no retire key:

  • passes validate() and --dry-run exits 0 printing dry run: mail config is valid, nothing deployed — the operator is told the config is valid;
  • the real deploy then crashes with TypeError: config.retire is not iterable at deploy.mjs:87, after the bws secret read and the wrangler deploy --dry-run step have already run (observed in the stub call log), midway through the deploy sequence.

Evidence

Verified this run on the laptop against main @ 63f83bef5a, probe ~/git/fleet/probe-idmail-deploy (the real deploy.mjs verbatim, stub bws/wrangler binaries and a stubbed fetch, the same harness as deploy.test.mjs):

  • control (the committed config.json, --dry-run): exit 0, config is valid, nothing deployed
  • bad-name control: clean aggregated validation error, zero external calls
  • the four null shapes above: raw TypeError from inside validate(), zero external calls, no aggregated report
  • retire omitted: --dry-run exit 0; real run exit 1 with TypeError: config.retire is not iterable at deploy.mjs:87 after bws secret list + wrangler deploy --dry-run had already executed

Why it matters

This deploy script is the guarded door for a production mail Worker: #3281 already established that it must fail closed and say why before touching anything external, because its sequence retires (force-deletes) Workers and resets secrets. A validator that crashes on the malformed shapes it exists to catch — and that blesses a config the deploy flow then crashes on halfway through the sequence — sends the operator debugging the validator instead of their config, at exactly the moment the config is broken.

Acceptance criteria

  • validate() never throws for any JSON value of config.json (null/scalar/array top level; null or non-object template, caller, or grant entries): every problem is returned in the aggregated list, each naming the config path it belongs to (e.g. templates[0] must be an object / callers.<name> must be an object), and the run ends with the existing config.json is invalid: error and zero external calls.
  • retire optionality agrees between validation and the deploy flow: either validation requires it, or the flow tolerates its absence (config.retire ?? []) — a config that passes --dry-run must complete the full (stubbed) deploy sequence without a TypeError.
  • Regression coverage in deploy.test.mjs (same stub harness): the null-entry shapes produce the aggregated validation error with no bws/wrangler calls logged, and a no-retire config completes the deploy sequence against the stubs.
  • The committed config.json still validates and --dry-run still exits 0; the existing id-mail(worker deploy): unrecognized arguments are silently ignored — a typo'd --dry-rnu enters the real deploy sequence and force-deletes the retired 'id-mail' Worker #3281 argument tests still pass.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    source/creatorFiled by the new-issue-creator job
    on Nov 7, 2026
  2. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor
  3. added
    priority/normalOrdinary priority (the default)
    work/self-assignedAn agent grabbed this item directly, outside the queue
    app/id-mailpkgs/nixos id-mail service and worker
    on Nov 7, 2026
  4. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · state: filed

    • Agent: new-issue-creator job (lane B, new-issue-creator-code-b)
    • Session / ID: cron run 2026-11-07 13:50 CST
    • Found via: filed this run
    • Task: Filed after laptop verification @63f83bef5a (probe ~/git/fleet/probe-idmail-deploy, real deploy.mjs + stub bws/wrangler/fetch): validate() TypeErrors on null top-level/template/caller/grant entries (deploy.mjs:135/:153/:163/:169) instead of aggregating them, and a retire-less config passes --dry-run then crashes the real deploy at deploy.mjs:87. Self-assigning under the guarded trivial self-solve path (§4): the fix is small and clearly scoped (null-safe validation + retire optionality agreement + deploy.test.mjs regression cases), low-risk, and verified by the existing stub harness.
    • Expectation: effort xs — done = fix merged with regression tests green on the laptop, issue closed by the PR.
    • Links: probe ~/git/fleet/probe-idmail-deploy (laptop)
  5. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    Additional verified shapes in the same validator (same probe, same run, before fixing): transports: "email" and transports: 5 → TypeError: (c.transports ?? []).every is not a function; templates: 5 and templates: {} → TypeError: ... is not iterable from the template loop. Control: limits: null is reported correctly through the aggregated config.json is invalid: error, so the fix scope is exactly the unguarded spots: top-level value, transports .every/.includes, the templates loop, template/caller/grant entries, and the retire flow mismatch. All are covered by the self-solve in progress.

  6. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · state: done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/id-mailpkgs/nixos id-mail service and workerkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions