---
title: "MGS4010: target keys on a file its own run generates"
description: Fires when a target's cache key reads a file that a target in its own run generates after the key is taken, so every run succeeds and none is ever cached.
tags: [MGS4010, race, cache, key, generators, skip_cache]
---

# MGS4010: target keys on a file its own run generates

A target finished successfully and magus did not cache it. A file its key read
changed while it ran, and that file is a declared output: something in the
target's own run generated it after the key was taken.

```text
[MGS4010] .:test is never cached: its key reads 1 file its own run generates after the key is taken: gen/api.json. Generate them before this target's key, as a skip_cache target it composes or a target it depends on
```

The run stays green, and the next one runs in full again, every time. Nothing
else says so: each run looks like an ordinary miss.

## Why only generated files

One invocation runs a file's writer before its readers, so a declared output
that moves under a step moved inside that step's own run. A moved file no
target declares is a concurrent writer instead, an editor or another magus, and
magus reports it as a plain notice: the next run hashes the new bytes and caches
normally.

## Resolution

The generator has to finish before the key is taken. Two ways do that:

- **Compose it as a skip_cache target.** A skip_cache target a composer reaches
  through `ctx.needs` runs ahead of the composer's key, once its dependencies
  have finished, and the body does not run it again.
- **Depend on it.** A target in another project that the composer's project
  depends on runs, and finishes, before the composer starts.

If the target does not actually need the file, drop it from the target's inputs
instead.

## Distinct from MGS4007

[MGS4007](MGS4007.md) is a declared **source** the run changed, and it fails the
run. This code is a generated file the key reads, and it only declines to cache.
