Backtestshugorun-20261013-011256#15174

Issue #15174 Merged fix PR # Run 13 Oct 2026 · run-20261013-011256 gohugoio/hugo

Panic when deleting a directory in static when server is running

Worse

The merged fix was judged better than our patch.

In this judgment, Patch B = our agent, Patch A = the merged fix.

Both patches fix the root cause the same way. They replace the stat-dependent, directory-only `Contains` check with a `ReverseLookup`-based check. That check still classifies events for deleted mount roots and covers single-file mounts, so static events go back to the static syncer instead of the partial rebuild.

The differences are in error handling and tests:

- **Error handling.** Patch B calls `panic(err)` when `ReverseLookup` returns an error. That adds a new panic path to file-event classification in the running server, which is the kind of crash the issue reports. Patch A ignores the error and returns false, which is safer for a classification helper.
- **Fallback case.** Patch A also adds a `ComponentFolderStatic` case to the `processPartialFileEvents` switch. This is a defensive fallback rather than the fix itself. It could quietly drop a misrouted static event, but since the static syncer owns those events anyway, the risk is low and it prevents the reported panic outright.
- **Tests.** Patch A adds two server testscripts that reproduce the reported scenario end-to-end: deleting a mounted static directory and deleting a single-file static mount while the server runs, then asserting nothing is written to stderr. Patch B adds a focused unit test of `IsStatic` and `IsContent` after removing mount roots, plus a single-file mount check. That test is precise and would fail before the fix, but it does not exercise the server event path where the panic happened.

Overall, Patch A is more robust, with no new panic and a defensive switch case, and its tests reproduce the issue directly.

The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.

Solve

51m 34s

Wall-clock time in the container

Full test suite

No new failures

2,667 passed · 95 skipped · 2,791 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

79vs 78 merged

Changed lines, ours vs merged

unknown  component: "static" in processPartialFileEvents (hugolib/hugo_sites_build.go:1084, your v0.165.0-DEV-8a5cb2344)

The two patches

Our patch+71 −8
hugolib/filesystems/basefs.goindex 13cc942fc..23c503c65 100644@@ -426,16 +426,15 @@ func (d *SourceFilesystem) RealFilename(rel string) string { }  // Contains returns whether the given filename is a member of the current filesystem.+// Note that this does not check if the file (or the mount it belongs to) exists,+// as it's used to classify file system events, including removals of+// mount root directories, and it covers both directory and single file mounts. func (d *SourceFilesystem) Contains(filename string) bool {-	for _, dir := range d.mounts() {-		if !dir.IsDir() {-			continue-		}-		if strings.HasPrefix(filename, dir.Meta().Filename) {-			return true-		}+	cps, err := d.ReverseLookup(filename, false)+	if err != nil {+		panic(err) 	}-	return false+	return len(cps) > 0 }  // RealDirs gets a list of absolute paths to directories starting from the givenhugolib/filesystems/basefs_test.goindex 883cf4d28..8923ef819 100644@@ -413,6 +413,70 @@ Main. 	b.Assert(rel, qt.Equals, filepath.FromSlash("foo/baz.txt")) } +// The server uses IsStatic to route file system events to the static syncer;+// any static event that isn't recognized as such ends up in the partial+// rebuild, which panicked with "unknown component: static".+func TestIsStaticRemovedMountRootAndSingleFileMount(t *testing.T) {+	files := `+-- hugo.toml --+[[module.mounts]]+source = "static"+target = "static"+[[module.mounts]]+source = "other/single.txt"+target = "static/single.txt"+[[module.mounts]]+source = "content"+target = "content"+-- static/foo/a.txt --+A.+-- static/b.txt --+B.+-- other/single.txt --+Single.+-- other/notmounted.txt --+Not mounted.+-- content/p1.md --+---+title: "P1"+---+`+	b := hugolib.Test(t, files)++	sfs := b.H.BaseFs.SourceFilesystems+	staticDir := filepath.FromSlash("/static")+	contentDir := filepath.FromSlash("/content")++	// Single file mount.+	b.Assert(sfs.IsStatic(filepath.FromSlash("/other/single.txt")), qt.IsTrue)+	b.Assert(sfs.IsStatic(filepath.FromSlash("/other/notmounted.txt")), qt.IsFalse)+	b.Assert(sfs.IsContent(filepath.FromSlash("/other/single.txt")), qt.IsFalse)++	// Remove the static and content mount roots.+	b.Assert(b.H.Fs.Source.RemoveAll(staticDir), qt.IsNil)+	b.Assert(b.H.Fs.Source.RemoveAll(contentDir), qt.IsNil)++	for _, filename := range []string{+		staticDir,+		filepath.Join(staticDir, "foo"),+		filepath.Join(staticDir, "foo", "a.txt"),+		filepath.Join(staticDir, "b.txt"),+	} {+		b.Assert(sfs.IsStatic(filename), qt.IsTrue, qt.Commentf(filename))+		b.Assert(sfs.IsContent(filename), qt.IsFalse, qt.Commentf(filename))+	}++	for _, filename := range []string{+		contentDir,+		filepath.Join(contentDir, "p1.md"),+	} {+		b.Assert(sfs.IsContent(filename), qt.IsTrue, qt.Commentf(filename))+		b.Assert(sfs.IsStatic(filename), qt.IsFalse, qt.Commentf(filename))+	}++	b.Assert(sfs.IsStatic(filepath.FromSlash("/other/single.txt")), qt.IsTrue)+}+ func TestAbsProjectContentDir(t *testing.T) { 	tempDir := t.TempDir()  
Merged fix · PR #+69 −9
hugolib/filesystems/basefs.goindex 13cc942fc..74f59b03c 100644@@ -426,16 +426,10 @@ func (d *SourceFilesystem) RealFilename(rel string) string { }  // Contains returns whether the given filename is a member of the current filesystem.+// It's stat-free, so it also works for deleted files. func (d *SourceFilesystem) Contains(filename string) bool {-	for _, dir := range d.mounts() {-		if !dir.IsDir() {-			continue-		}-		if strings.HasPrefix(filename, dir.Meta().Filename) {-			return true-		}-	}-	return false+	cps, _ := d.ReverseLookup(filename, false)+	return len(cps) > 0 }  // RealDirs gets a list of absolute paths to directories starting from the givenhugolib/hugo_sites_build.goindex 823f9811e..0feaada59 100644@@ -1080,6 +1080,8 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo 			changes = append(changes, identity.GenghisKhan) 		case files.ComponentFolderArchetypes: 			// Ignore for now.+		case files.ComponentFolderStatic:+			// Handled by the static file syncer. 		default: 			panic(fmt.Sprintf("unknown component: %q", pathInfo.Component())) 		}testscripts/server/server__delete_static_file_mount.txtnew file mode 100644index 000000000..df77b2a04@@ -0,0 +1,32 @@+# Test the hugo server command when removing a file mounted into static.+# See issue 15174.++hugo server &++waitServer++rm myfiles/robots.txt++sleep 2++stopServer+! stderr .++-- hugo.toml --+title = "Hugo Server Test"+baseURL = "https://example.org/"+disableKinds = ["taxonomy", "term", "sitemap"]+[[module.mounts]]+source = "content"+target = "content"+[[module.mounts]]+source = "layouts"+target = "layouts"+[[module.mounts]]+source = "myfiles/robots.txt"+target = "static/robots.txt"+-- layouts/all.html --+All.+-- content/p1.md --+-- myfiles/robots.txt --+robotstestscripts/server/server__delete_static_mount_dir.txtnew file mode 100644index 000000000..8c338812e@@ -0,0 +1,32 @@+# Test the hugo server command when removing a directory mounted into static.+# See issue 15174.++hugo server &++waitServer++rm mystatic/foo++sleep 2++stopServer+! stderr .++-- hugo.toml --+title = "Hugo Server Test"+baseURL = "https://example.org/"+disableKinds = ["taxonomy", "term", "sitemap"]+[[module.mounts]]+source = "content"+target = "content"+[[module.mounts]]+source = "layouts"+target = "layouts"+[[module.mounts]]+source = "mystatic/foo"+target = "static/foo"+-- layouts/all.html --+All.+-- content/p1.md --+-- mystatic/foo/static.txt --+static