Backtestshugorun-20261002-200313#15174
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 stop the panic, but Patch A also fixes why static events end up in the partial rebuild. Patch A has two parts. First, it adds an explicit `ComponentFolderStatic` case to the component switch in `processPartialFileEvents`. This matches the existing `ComponentFolderArchetypes` "ignore" case and removes the panic directly. Second, it rewrites `SourceFilesystem.Contains` to use `ReverseLookup`, which does not stat files. The old version iterated mounts, required `dir.IsDir()`, and did prefix matching. That breaks for deleted directories, since a removed mount no longer reports `IsDir`, and for single-file mounts. In those cases the static syncer did not recognise the event as static, so the event fell through to the partial build and hit the panic. With the new `Contains`, the static syncer can classify and sync deletions correctly, so the removed files also disappear from the published output. That is the behaviour a user actually needs. Patch A's two testscripts cover deleting a directory mounted into static and a file mounted into static while the server runs, and they assert no stderr output (no panic). These are realistic end-to-end reproductions of the reported scenario. Patch B filters static components out of the resolved paths before parsing. This avoids the panic but only treats the symptom. If `Contains` still misclassifies a deleted static directory, the event is silently dropped from the build and never reaches the static syncer, so stale files may stay in `public`. It also restructures the loop (preallocated slice to append) more than needed. Its Go integration test exercises static add/edit/remove under `TestRunning` and is a reasonable regression test for the panic. However, it does not check that deleted static files are removed from the output, and it does not cover mounts. On correctness at the root cause, Patch A is stronger. Its scope remains focused, with a small and clear change consistent with the surrounding code.
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
42m 43s
Wall-clock time in the container
Full test suite
No new failures
3,693 passed · 99 skipped · 3,801 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
49vs 78 merged
Changed lines, ours vs merged
The issue
View on GitHubunknown component: "static" in processPartialFileEvents (hugolib/hugo_sites_build.go:1084, your v0.165.0-DEV-8a5cb2344)The two patches
Our patch+45 −4
hugolib/hugo_sites_build.goindex 823f9811e..1928b1fe3 100644@@ -919,8 +919,12 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo for _, ev := range eventInfos { cpss := h.BaseFs.ResolvePaths(ev.Name)- pss := make([]*paths.Path, len(cpss))- for i, cps := range cpss {+ pss := make([]*paths.Path, 0, len(cpss))+ for _, cps := range cpss {+ if cps.Component == files.ComponentFolderStatic {+ // Static files are synced to the publish dir outside of the Hugo build.+ continue+ } p := cps.Path if ev.removed && !paths.HasExt(p) { // Assume this is a renamed/removed directory.@@ -932,9 +936,10 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo deletedDirs = append(deletedDirs, cps.Path) } - pss[i] = h.Configs.ContentPathParser.Parse(cps.Component, p)+ pi := h.Configs.ContentPathParser.Parse(cps.Component, p)+ pss = append(pss, pi) if ev.added && !ev.isChangedDir && cps.Component == files.ComponentFolderContent {- addedContentPaths = append(addedContentPaths, pss[i])+ addedContentPaths = append(addedContentPaths, pi) } // Compile cache buster.hugolib/rebuild_test.goindex b6d716c37..9841c341f 100644@@ -2211,3 +2211,39 @@ objects: ["o1"] b.AssertFileContent("public/objects/index.html", "Objects|taxonomy|<p>Objects content edited.</p>") b.AssertFileContent("public/objects/o1/index.html", "O1|term|") }++// Static files are synced to /public outside of the Hugo build, but events for+// them may still reach the partial rebuild.+func TestRebuildStaticFilesAndDirs(t *testing.T) {+ t.Parallel()+ files := `+-- hugo.toml --+baseURL = "https://example.com"+disableKinds = ["term", "taxonomy", "sitemap", "robotstxt", "404", "rss"]+disableLiveReload = true+-- content/p1.md --+---+title: "P1"+---+-- static/mydir/foo.txt --+Foo.+-- static/bar.txt --+Bar.+-- layouts/all.html --+{{ .Title }}|+`+ b := TestRunning(t, files)+ b.AssertFileContent("public/p1/index.html", "P1|")++ b.EditFileReplaceAll("static/bar.txt", "Bar.", "Bar edited.").Build()+ b.AddFiles("static/mydir/new.txt", "New.").Build()+ b.AddFiles("static/newdir/new.txt", "New.").Build()++ // Delete a directory in static.+ b.RemoveFiles("static/mydir/foo.txt", "static/mydir/new.txt", "static/mydir").Build()+ b.RemoveFiles("static/newdir/new.txt", "static/newdir").Build()+ b.RemoveFiles("static/bar.txt").Build()++ b.EditFileReplaceAll("content/p1.md", `"P1"`, `"P1 edited"`).Build()+ b.AssertFileContent("public/p1/index.html", "P1 edited|")+}
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