# workerd error: transform rule loop

## TL;DR

Two transform rules rewrite the URL back and forth forever, and the platform detects the loop. Make the rules converge: each rule's output must not match another rule's input (or any rule's input again). Rule sets need a termination argument.

```text
workerd error: transform rule loop detected
```

## Steps

1. List the transform rules in order and trace a sample URL through them.
   Expected: The loop is visible: A rewrites to B, B rewrites to A.

2. Break the cycle: make one rule's output not match the other's input (more specific matchers).
   Expected: The trace terminates.

3. Add a guard: rules should only fire when the URL is not already in the target form.
   Expected: Re-application is a no-op.

4. Test the full rule set against a battery of URLs.
   Expected: All terminate.

5. Review rule changes for loop potential before deploying.
   Expected: Loops are caught in review.

## When to use

- transform rules loop
- rules were added independently
- URLs bounce between forms

## When not to use

- a single rule misbehaves (that is the rule's logic)
- the loop is in the origin app (different layer)
- no transform rules exist (check the config)

## Tool compatibility

- workerd
- Transform Rules

## Variant phrasings

- "transform rule loop"
- "rewrite rules loop cloudflare"
- "transform rules cycle"

## Why it happens

Transform rules are applied repeatedly until no rule matches, so a pair that undoes each other never terminates. Each rule is locally sensible; the loop is a global property of the set. The fix is making the set convergent, which requires looking at the rules together, not one at a time.

## Edge cases

- the trace-through test is the essential review tool; automate it
- rule order matters; document why the order is what it is
- a 'already transformed' marker (header or path prefix) is the robust guard

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_nW1eY9VpI9MjzQEwT868JQ
