fix(miniflare): local email reply rejects the permitted 100th References entry

Aperta Adatta ai principianti
#17,112 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
nodejs, typescript

Direzione di ricerca

Inizia da packages/miniflare/src/workers/email/validate.ts (il controllo di replyability intorno alle righe 36-49), dove il numero di references viene confrontato con il limite; il confine è sfasato di uno, quindi un conteggio di esattamente 100 viene rifiutato. Leggi la funzione di supporto alla validazione che lo circonda e i test unitari esistenti accanto a essa in packages/miniflare/src/workers/email/ prima di modificare. Il lavoro è completato quando 99 e 100 references rispondono con successo, 101 continua a fallire con il messaggio del limite di References e viene aggiunto un test di confine a 100 nella suite. Lo script di riproduzione nell'issue è una buona conferma end-to-end una volta che il test unitario passa.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

wrangler dev --local rejects a structured message.reply() when the incoming message contains exactly 100 valid References entries. The documented Email Routing limit allows 100 and rejects incoming messages with more than 100 entries.

Steps to reproduce

  1. With Node.js and npm available and port 28676 free, save the script as reproduce.sh and run sh reproduce.sh.
  2. The script installs the listed Wrangler version into a temporary directory, starts a Worker with the documented local routing flow, and posts three RFC 5322 fixtures with 99, 100, and 101 unique References entries. Each fixture has an In-Reply-To matching the last reference and a unique current Message-ID. The Worker tries one structured reply per inbound event.
  3. Compare the HTTP status and recorded reply count. The script exits zero when it observes the current off-by-one result and both adjacent controls behave as observed.
Reproduction script: reproduce.sh
#!/bin/sh
set -eu

test_dir=$(mktemp -d)
worker_pid=
cleanup() {
  if [ -n "$worker_pid" ]; then
    kill "$worker_pid" 2>/dev/null || true
    wait "$worker_pid" 2>/dev/null || true
  fi
  rm -rf "$test_dir"
}
trap cleanup EXIT
cd "$test_dir"
npm install --no-audit --no-fund --no-save [email protected]

cat > wrangler.json <<'CONFIG'
{
  "name": "email-references-limit",
  "main": "worker.js",
  "compatibility_date": "2026-11-21",
  "send_metrics": false
}
CONFIG
cat > worker.js <<'WORKER'
export default {
  async email(message) {
    await message.reply({
      from: message.to,
      subject: "Re: References boundary",
      text: "Reply fixture",
    });
  },
};
WORKER

server=http://127.0.0.1:28676
./node_modules/.bin/wrangler dev --local --ip 127.0.0.1 --port 28676 > wrangler.log 2>&1 &
worker_pid=$!
for attempt in $(seq 1 30); do
  if grep -Fq "Ready on $server" wrangler.log; then
    break
  fi
  sleep 1
done
if ! grep -Fq "Ready on $server" wrangler.log; then
  cat wrangler.log
  exit 1
fi

node --input-type=module <<'JS'
import assert from "node:assert/strict";

const date = new Date().toUTCString().replace(/GMT$/, "+0000");
for (const count of [99, 100, 101]) {
  const ids = Array.from({ length: count }, (_, index) => "<previous-" + index + "@example.net>");
  const incoming = [
    "From: [email protected]",
    "To: [email protected]",
    "Date: " + date,
    "Subject: References boundary",
    "Message-ID: <boundary-" + count + "@example.net>",
    "In-Reply-To: " + ids.at(-1),
    "References: " + ids.join("\r\n "),
    "MIME-Version: 1.0",
    "Content-Type: text/plain; charset=utf-8",
    "",
    "Please reply to this fixture.",
    "",
  ].join("\r\n");

  const url = "http://127.0.0.1:28676/cdn-cgi/local/email?from=sender%40example.net&to=reply-worker%40example.com&format=json";
  const response = await fetch(url, { method: "POST", body: incoming });
  const { outcome, replies } = await response.json();
  console.log(JSON.stringify({ count, status: response.status, outcome, replies: replies.length }));
  assert.equal(response.status, count === 99 ? 200 : 500);
  assert.equal(replies.length, count === 99 ? 1 : 0);
}
JS
grep -Fc 'References" header has more than 100 entries' wrangler.log

Expected behavior

The structured reply should succeed once for each valid local fixture with 99 or 100 incoming References entries. The 101-entry fixture should hit the documented limit and produce no reply.

Actual behavior

The 99-entry control returned HTTP 200 and one reply. Both the 100- and 101-entry fixtures returned HTTP 500 and zero replies. Wrangler logged that the References header had more than 100 entries once for each rejected fixture, including the one with exactly 100.

{"count":99,"status":200,"outcome":"ok","replies":1}
{"count":100,"status":500,"outcome":"exception","replies":0}
{"count":101,"status":500,"outcome":"exception","replies":0}

Runtime or environment

Evidence

  • Expected source: The Email Routing limits table and the Email Routing Workers API both specify that replies are rejected above 100 incoming References entries. The Email Service changelog documents testing reply behavior locally with Wrangler.
  • Failure source: The local /cdn-cgi/local/email endpoint produced the three paired observations above. The released source linked under Runtime or environment counts the references and rejects >= 100. The reported behavior was observed in the local emulator.
  • Evidence provenance: observed
  • Local verification: reproduced
  • Reproduction completeness: complete

Restoration check

With the same Worker and adjacent fixtures, the 99- and 100-entry submissions should each return HTTP 200 and record one reply. The 101-entry submission should still return HTTP 500 with zero replies and identify the References limit in the local log.

Triage assessment

  • Impact level: P2
  • Assessment status: supported
  • Impact basis: The local simulator incorrectly blocks reply testing at the single documented boundary, so a Worker tested with a full-length thread appears to reject a supported input.
  • Workaround status: none
  • Workaround basis: Shortening the fixture changes the input responsible for the requested test and no local alternative for exercising the same boundary was observed.
Lingua principale
TypeScript
Stelle
4.7k
Fork
1.7k
Merge medio
1g 22h
PR unite (30g)
287

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cloudflare/workers-sdk

Tutte le issue di cloudflare/workers-sdk

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.