Skip to content

Library watch cleanup forgets stale assets after a deletion error #34808

Not planned

Description

@fernandezbaptiste

Hullo folks,

I'm doing some research for Tessl Code Review and we ran it against your repo. It flagged a potential issue, and I figured it made sense to share it with you:

Command

build, with the @angular/build:library builder in watch mode.

Description

After a stale output cannot be deleted, the next iteration no longer knows that the file needs deletion. A temporary filesystem error can therefore leave an obsolete asset in the output directory for the rest of the watch session.

At 612cde0d, recordEmittedOutputs removes the asset from its inventory before deleteFilesFromDisk runs. The build action catches the filesystem error, and watch mode retains the same BuilderState.

Expected: retain failed cleanup work so a later successful iteration can delete the obsolete output.

Observed: even passing the same deleted source to the next cleanup returns an empty deletion set.

Minimal reproduction

I ran this focused probe with Node 25.2.0 on macOS. It executes the current BuilderState implementation and uses a real permission-induced EACCES. Only the unused result holder is stubbed. This is not a full ng build --watch integration test.

Save as cleanup-repro.mjs at the repository root and run node cleanup-repro.mjs as a non-root user:

import {readFileSync, mkdtempSync, writeFileSync, chmodSync, existsSync, rmSync} from 'node:fs';
import {join} from 'node:path';
import {stripTypeScriptTypes} from 'node:module';
import vm from 'node:vm';
import assert from 'node:assert/strict';
const source = readFileSync('packages/angular/build/src/builders/library/builder-state.ts','utf8');
// Only the unused result holder is stubbed. Output tracking runs unchanged.
const ctx = vm.createContext({ExecutionResult:class {}});
vm.runInContext(stripTypeScriptTypes(source.slice(source.indexOf('export class BuilderState')).replace('export class BuilderState','globalThis.BuilderState = class BuilderState')),ctx);
const state = new ctx.BuilderState();
const root = mkdtempSync(join(process.cwd(),'cleanup-repro-'));
const output = join(root,'old.txt');
writeFileSync(output,'stale asset');
state.recordEmittedOutputs({filesToEmit:[{source:'/fixture/src/old.txt',path:'old.txt'}],filesToDelete:[]});
const first = [...state.recordEmittedOutputs({filesToEmit:[],filesToDelete:['/fixture/src/old.txt']})];
assert.deepEqual(first,['old.txt']);
let failure;
try {
  chmodSync(root,0o555);
  try { rmSync(output,{force:true}); } catch(e) {failure=e.code;}
} finally { chmodSync(root,0o755); }
assert.equal(failure,'EACCES');
state.resetExecutionResult();
const retry = [...state.recordEmittedOutputs({filesToEmit:[],filesToDelete:['/fixture/src/old.txt']})];
assert.deepEqual(retry,[]);
assert.equal(existsSync(output),true);
console.log(JSON.stringify({firstDeletion:first,failure,nextDeletion:retry,staleFileStillExists:existsSync(output)}));
rmSync(root,{recursive:true,force:true});

Output:

{"firstDeletion":["old.txt"],"failure":"EACCES","nextDeletion":[],"staleFileStillExists":true}

The directory permission is restored before the second iteration, so the remaining file is no longer blocked from deletion. The cleanup inventory has already forgotten it.

Environment

Source checkout at the commit above, Node 25.2.0, macOS. No packaged Angular CLI version or previous known-good release was tested.

Full transparency: I work at Tessl, and we've spotted that using Tessl Code Review - using repository-level context and specific review lenses that improve over time through feedback. That’s how this finding surfaced.

We’re just getting started and want to offer the tool free to open-source projects. If this is useful, happy to give you access.

Baptiste

Activity

  1. added this to the needsTriage milestone on Nov 30, 2026
  2. alan-agius4 commented on Dec 1, 2026

    @alan-agius4
    Collaborator

    Thanks for reporting this.

    We are going to close this as not planned. When a filesystem deletion error occurs in watch mode, the build iteration already fails and surfaces the underlying error directly, so the failure is not silent.

    Making watch mode output tracking transactional across filesystem deletion and concurrent write errors adds significant state complexity to BuilderState (and still cannot fully avoid edge cases from partial concurrent writes). Consistent with the application builder, we do not attempt transactional disk I/O recovery in watch mode; if a permission or file lock error interrupts disk cleanup, restarting the watch build cleanly resets the output directory.

  3. fernandezbaptiste commented on Dec 1, 2026

    @fernandezbaptiste
    Author

    Thanks for flagging, @alan-agius4. Understood: the failed watch iteration already surfaces the filesystem error, and restarting resets the output. That’s useful feedback on the practical impact and the recovery trade-off. We’ll take it into account when checking and sharing future findings.

    Bap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions