Skip to content

docs(cache): say that output: [{ auto: true }] records only files the run wrote #3482

Closed

Description

@l0st0

Automatic output tracking records the files a task writes during the run that fills the cache entry. Code generators often skip files that are already current (the TanStack Router generator, paraglide-js compile, wrangler types). On a tree where the generated files already exist, the run that creates the cache entry writes nothing, so the entry holds no outputs. Delete the generated files, run the task again, and you get a cache hit that restores nothing.

Repro (vite-plus 1.7.0):

  1. A task codegen that runs paraglide-js compile --outdir src/paraglide, with cache: { input: [{ auto: true }, '!src/paraglide/**'], output: [{ auto: true }] }.
  2. vp run codegen twice: the second is a hit.
  3. rm -rf src/paraglide && vp run codegen: a cache hit, and src/paraglide is still missing.

Listing the outputs explicitly (output: [{ auto: true }, 'src/paraglide/**']) fixes it. guide/automatic-data-tracking.md and config/run.md describe auto output as write tracking but don't warn about generators that skip unchanged files. Suggested: a row in the cases table, or a note under output, recommending explicit globs for generator tasks.

Activity

  1. voidzero-bot commented on Nov 18, 2026

    @voidzero-bot
    Contributor
    • Reproduced: Yes
    • Exploration: Yes — View branch
    • Unit Test: No — documentation-only change
    • Priority: P2: has workaround. The caching engine is working as designed, but the missing documentation warning can surprise users of code generators that skip unchanged files. The workaround (adding explicit output globs to cache.output) is straightforward.

    The root cause is not in the cache engine itself — automatic output tracking intentionally records only files the task process writes. The problem is that the docs don't warn that generators such as paraglide-js compile, TanStack Router, or wrangler types may write nothing when their outputs already exist, leaving a cache entry with no outputs. Deleting the generated files later then yields a cache hit that restores nothing.

    I found a potential fix for this issue. I added warning boxes to docs/guide/automatic-data-tracking.md and docs/config/run.md that explain the limitation, plus a table row showing the workaround pattern output: [{ auto: true }, 'src/paraglide/**']. The fix branch is linked above; it should be reviewed before merging.

    Full Triage Report

    Triage Report: #3482

    Issue Summary

    Automatic output tracking for vp run tasks records only files the task process actually writes during the run that creates the cache entry. Code generators that skip writing files which are already current therefore produce a cache entry with no outputs. If the generated files are later deleted, subsequent runs still hit the cache but restore nothing, leaving the output directory missing.

    The issue requests a documentation note in guide/automatic-data-tracking.md and/or config/run.md warning about this behavior and recommending explicit output globs for generator tasks.

    Environment

    • Repository: /home/runner/work/vite-plus/vite-plus
    • Branch: triagebot/fix-3482
    • vp version: v1.7.0 (local vite-plus 1.7.0)
    • Node.js: v24.22.3
    • pnpm: v12.11.2
    • OS: Ubuntu (GitHub Actions runner)
    • vite-plus linked from checkout at packages/cli

    Reproduction Path

    Created minimal reproduction at /tmp/vite-plus-triage/gh-3482/repro.

    Files

    vite.config.ts (buggy configuration):

    import { defineConfig } from 'vite-plus';
    
    export default defineConfig({
      run: {
        tasks: {
          codegen: {
            command: 'node generate.mjs',
            cache: {
              input: [{ auto: true }, '!src/generated/**'],
              output: [{ auto: true }],
            },
          },
        },
      },
    });

    generate.mjs (simulates a generator that skips up-to-date files):

    import fs from 'node:fs';
    import path from 'node:path';
    
    const dir = 'src/generated';
    const file = path.join(dir, 'out.txt');
    
    if (!fs.existsSync(file)) {
      fs.mkdirSync(dir, { recursive: true });
      fs.writeFileSync(file, 'generated content
    ');
      console.log('wrote', file);
    } else {
      console.log('skipped', file, '(already exists)');
    }

    Initial state: src/generated/out.txt exists with content "initial generated content".

    Steps and Results

    1. Clear cache: rm -rf node_modules/.vite/task-cache
    2. First run — cache miss, generator skips writing:
      $ vp run -v codegen
      $ node generate.mjs
      skipped src/generated/out.txt (already exists)
      ... 0 cache hits • 1 cache miss
      
    3. Second run — cache hit (but the cached entry captured no outputs):
      $ vp run -v codegen
      $ node generate.mjs ◉ cache hit, replaying
      skipped src/generated/out.txt (already exists)
      ... 1 cache hit • 0 cache misses
      
    4. Delete generated output and run again:
      $ rm -rf src/generated && vp run -v codegen
      $ node generate.mjs ◉ cache hit, replaying
      skipped src/generated/out.txt (already exists)
      ... 1 cache hit • 0 cache misses
      
      After the run, src/generated/ is still missing.

    This exactly matches the reported behavior: a cache hit that restores nothing.

    Control Case

    Modified vite.config.ts to add an explicit output glob:

    output: [{ auto: true }, 'src/generated/**'],

    After clearing cache and re-creating the initial file, the first two runs behaved the same (cache miss, then cache hit). However, after deleting src/generated/, the next run restored the missing file from the cache.

    This confirms:

    • { auto: true } output tracking only archives files the task wrote.
    • Explicit output globs archive files matching the pattern even when the task did not write them.
    • The suggested workaround (output: [{ auto: true }, '<glob>/**']) fixes the behavior.

    Result

    Reproduced: Yes.

    The current behavior matches the report. A documentation update is appropriate to warn users that output: [{ auto: true }] records only writes, and to recommend explicit output globs for tasks that may skip already-current generated files.

    Diagnosis

    Affected Files and Lines

    • docs/guide/automatic-data-tracking.md:40
      • States: "File system tracking also tracks outputs. If you omit cache.output, Vite Task archives files the command writes after a successful run and restores them on a cache hit."
    • docs/guide/automatic-data-tracking.md:279
      • The "When To Add Manual Config" table lists cases for overriding inputs/outputs but does not mention generator tasks that skip up-to-date files.
    • docs/config/run.md:333-350
      • The cache.output section describes automatic write tracking and using explicit globs to exclude files (e.g., !build.log), but does not warn that tools which skip unchanged files create cache entries with no outputs.

    Root Cause

    The observed behavior is expected from the cache engine. Vite Task's automatic output tracking intentionally records only files the task process writes during the run. When a code generator sees that its outputs are already current and skips writing them, the cache entry for that run captures zero output files. Later, even if the generated files are deleted, the cache key still matches (inputs are unchanged), so Vite Task replays the cached run — including its empty output set — instead of re-running the generator.

    The defect is in the documentation: it explains automatic output tracking as "files the command writes" without highlighting that unchanged-skipping generators may write nothing, producing a misleading cache hit.

    Suggested Fix Approach

    1. In docs/guide/automatic-data-tracking.md, add a warning or limitation note in the "File System Tracking" outputs subsection explaining that automatic output tracking only archives files actually written during the cache-filling run.
    2. In the "When To Add Manual Config" table, add a row such as:
      • Case: Generator skips files that are already up to date
      • Example: output: [{ auto: true }, 'src/paraglide/**']
    3. In docs/config/run.md, under cache.output, add a note that { auto: true } should be combined with explicit output globs for generator tasks that may skip writing unchanged files.

    Edge Cases

    • Generators that always rewrite their outputs are unaffected.
    • Generators that partially skip files may create cache entries that restore only a subset of outputs, leading to inconsistent state.
    • Adding an explicit output glob archives the files as they existed at cache time, even if the generator would have produced different content on a fresh run. This is usually the desired behavior for deterministic generators.

    Verification

    Claim

    Observed behavior: A cached vp run codegen task, configured with output: [{ auto: true }], produced a cache hit that restored no files after the generated output directory was deleted. The generator script skipped writing because the files already existed when the cache entry was created.

    Expected behavior (reporter): The documentation should warn that automatic output tracking records only files written during the cache-filling run, and should recommend explicit output globs for generator tasks that skip unchanged files.

    Research

    • Product documentation in docs/guide/automatic-data-tracking.md:40 states: "File system tracking also tracks outputs. If you omit cache.output, Vite Task archives files the command writes after a successful run and restores them on a cache hit." This wording matches the observed behavior (only written files are archived).
    • docs/config/run.md:333-337 describes cache.output as "automatic write tracking" and says Vite Task "uses automatic write tracking to choose those files." Again, the behavior is consistent with the docs.
    • Neither doc page warns that tools skipping unchanged files leave cache entries with empty outputs.
    • The "When To Add Manual Config" table in docs/guide/automatic-data-tracking.md:279 has no row for generator tasks that skip already-current files.
    • git blame shows these descriptions were added in 8696d857 ("docs: Vite Task cache reuse and tool-reported caching") and updated in 70185afa (a vite-task bump); neither commit added guidance for unchanged-skipping generators.
    • gh search issues --repo voidzero-dev/vite-plus "automatic output tracking" returns only this issue; no prior discussion was found.
    • The actual cache engine lives in vite-task, a git dependency in Cargo.toml; the behavior is not implemented in this repository.

    Verdict

    bug — The caching engine is behaving as documented (it tracks writes), but the documentation is incomplete for a common and non-obvious generator use case. Users reasonably expect cached tasks to restore their outputs after deletion; the current docs do not warn that automatic output tracking can fail to do so for generators that skip unchanged files. The requested documentation update is a valid bug fix.

    Fix

    Changed Files

    • docs/guide/automatic-data-tracking.md
      • Added a warning box after the automatic output tracking paragraph explaining that only files actually written during the cache-filling run are archived, with an example generator task that combines { auto: true } with an explicit output glob.
      • Added a row in the "When To Add Manual Config" table for generator tasks that skip unchanged files.
    • docs/config/run.md
      • Added a warning box under the cache.output section with the same guidance.

    Rationale

    The caching engine is behaving as designed; the defect is incomplete documentation. The fix makes the limitation visible in both the conceptual guide and the config reference, and shows users the exact pattern (output: [{ auto: true }, 'src/paraglide/**']) that resolves the issue.

    Regression Test

    No regression test was added. The change is documentation-only and does not affect executable behavior; existing caching tests are unaffected. Validation was performed with the original reproduction and a control case.

    Validation

    1. git diff --check -- docs/config/run.md docs/guide/automatic-data-tracking.md — passed, no whitespace errors.
    2. Re-ran the reproduction with the documented workaround (output: [{ auto: true }, 'src/generated/**']):
      • First run: cache miss, generator skips writing (file already exists).
      • Second run: cache hit.
      • After rm -rf src/generated, third run: cache hit and the missing src/generated/out.txt was restored.
    3. Verified all referenced documentation links and commands remain valid; no new external links were introduced.

    Alternatives Considered

    • Only adding a table row: less discoverable than a warning box with a complete example.
    • Only adding a warning in config/run.md: the guide page is where users learn the tracking model, so both locations are warranted.
    • Changing the caching engine to archive existing files matching output: [{ auto: true }] automatically: rejected because { auto: true } is explicitly write tracking; requiring explicit globs preserves the intended semantic boundary and avoids archiving unintended stale files.

    This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.

    I've opened a pull request with this fix: #3483

  2. added
    - P2: has workaround
    on Nov 18, 2026
  3. self-assigned this
    on Nov 18, 2026
  4. added a commit that references this issue on Nov 19, 2026
    5fcc5f7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

- P2: has workaroundtriage: fix verified

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions