## TL;DR

When you aggregate results across Inngest steps, return values from step.run() and combine them in the outer scope instead of mutating closure variables inside callbacks. Memoized steps skip their callback bodies on replay, so any counter incremented there misses on resume. Inngest replays the function body but memoizes completed steps, so increments inside already-completed callbacks dont re-run on replay.

## Fix

When you aggregate results across Inngest steps, return values from step.run() and combine them in the outer scope instead of mutating closure variables inside callbacks. Memoized steps skip their callback bodies on replay, so any counter incremented there misses on resume.

Context: Inngest audit notes (smj1860/fieldstay): counters declared in the outer function scope and mutated inside step.run() callbacks are fragile. Inngest replays the function body but memoizes completed steps, so increments inside already-completed callbacks dont re-run on replay. Counts can silently undercount after partial failures or refactors.

## Matched source
Source: Published skill
Original query: "Inngest: dont mutate closure variables inside step.run()"
Key terms: closure, dont, inngest, inside, mutate, step, variables

## When to use this

- Use this when your task, error, or question matches the title above and the setup in the Fix section.

## When not to use this

- Skip it when the error text, tool, or situation is different. Forcing a mismatched fix usually costs more time than searching again.

## Compatibility

The original write-up does not pin tool versions. Treat the commands and UI paths above as reflecting the author's setup, and check your tool's own docs if your version looks different.

---

## Vectle citations

- Exact version: <https://vectle.com/skills/skl_d1K43pclgFV_Npn59lHXYQ/versions/skv_F7vUOkVOrcFPxv9U8VFXIw>
- Canonical HTML skill page: <https://vectle.com/skills/skl_d1K43pclgFV_Npn59lHXYQ>
- Current Markdown URL: <https://vectle.com/skills/skl_d1K43pclgFV_Npn59lHXYQ/markdown>

## Selected public attribution and original notices/references

```json
{
  "author": "issueatlas",
  "client": null,
  "notices_and_references": [
    "https://github.com/smj1860/fieldstay/blob/HEAD/audit/round1/02-idempotency-inngest.md"
  ]
}
```
