Backtestshugorun-20260922-141813#15174
Panic when deleting a directory in static when server is running
The merged fix was judged better than our patch.
In this judgment, Patch B = our agent, Patch A = the merged fix.
Both patches share the identical root-cause fix: adding a `case files.ComponentFolderStatic` to the switch in processPartialFileEvents so the deleted-static event no longer falls through to the panicking default. The differentiators favor A. (1) A additionally makes SourceFilesystem.Contains stat-free by routing through ReverseLookup, with the explicit rationale 'so it also works for deleted files.' This is directly on point: a deleted file/dir no longer exists on disk, so the old prefix+IsDir/stat logic would return false for exactly the removed paths this issue is about, meaning the static syncer can fail to recognize and clean up the removed file. B only suppresses the crash but leaves that deleted-file recognition path unimproved. A's change is purposeful, not a drive-by refactor, and its comment documents intent. (2) Tests: A adds two testscripts that spin up the actual `hugo server` and delete both a file mount and a directory mount into static, asserting no stderr — this mirrors the reported scenario ('deleting a directory in static when server is running') far more faithfully than B's single in-process rebuild unit test. A's dir-mount case directly reproduces the issue title. (3) Scope is the one axis where B is leaner (switch case + one test only), and A's Contains edit does touch a broadly-used method, carrying some regression risk. But that edit is small, well-justified, and addresses the substance of the bug (correct handling of removed static paths) rather than merely masking the symptom. On balance A is the more complete fix with better-matched test coverage; the modest extra scope is warranted, so A wins over a tie.
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
24m 16s17 turns
Wall-clock time in the container
Full test suite
No new failures
3,689 passed · 99 skipped · 3,801 total
Contamination audit
Unknown
See the audit notes for this run
Patch size
26vs 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
hugolib/hugo_sites_build.goindex 823f9811e..1bff660ca 100644@@ -1078,6 +1078,9 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo // It's hard to determine the exact change set of this, // so be very coarse grained for now. changes = append(changes, identity.GenghisKhan)+ case files.ComponentFolderStatic:+ // Static files are handled separately by the server's static file syncer,+ // so there is nothing to do here for the partial rebuild. case files.ComponentFolderArchetypes: // Ignore for now. default:hugolib/rebuild_test.goindex b6d716c37..00cf83313 100644@@ -309,6 +309,29 @@ Pages: {{ range .Site.RegularPages }}{{ .RelPermalink }}|{{ end }}$ b.AssertFileContent("public/index.html", "Pages: /bar/p1/|$") } +func TestRebuildRemoveStaticDirIssue15174(t *testing.T) {+ files := `+-- hugo.toml --+baseURL = "https://example.com"+disableLiveReload = true+-- layouts/home.html --+Home.+-- static/staticdir/staticfile.txt --+Static content.+`+ b := TestRunning(t, files)++ b.AssertFileContent("public/index.html", "Home.")++ // Deleting the directory removes its file and then the now-empty directory,+ // which emits a Remove event for the extension-less "static/staticdir" path.+ // This resolves to the static component in processPartialFileEvents, which+ // used to hit the default case and panic with: unknown component: "static".+ b.RemoveFiles("static/staticdir/staticfile.txt", "static/staticdir").Build()++ b.AssertFileContent("public/index.html", "Home.")+}+ func TestRebuildAddRegularFileRegularPageUsedInHomeMultilingual(t *testing.T) { files := ` -- hugo.toml --
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
What the agent reported
The fix is complete and verified. Here is my final report.
What was wrong
Hugo panicked with unknown component: "static" when a directory inside static/ was deleted while hugo server was running.
Root cause: in hugolib/hugo_sites_build.go, the handleChange closure inside processPartialFileEvents switches on pathInfo.Component() with cases for content, layouts, assets, data, i18n, and archetypes, then a default: that panics. There was no case for files.ComponentFolderStatic. When a static directory is deleted, fileEventsApplyInfo marks the event removed=true (Stat fails), the extension-less directory path is resolved to the static component, and it fell through to the default panic (hugo_sites_build.go:1084). Static files are published by an entirely separate pipeline (the server's staticSyncer/copyStatic), so the partial-rebuild path should never have tried to act on them.
What I changed
hugolib/hugo_sites_build.go— added acase files.ComponentFolderStatic:with an empty body (ignoring the event, exactly like the adjacentarchetypescase) and a comment explaining static files are handled by the server's static syncer. Thedefault: panicremains for genuinely unknown components. Cache-buster compilation anddeletedDirsaccumulation happen earlier in the loop (beforehandleChange), so they still run for static paths — no behavior was dropped.hugolib/rebuild_test.go— added regression testTestRebuildRemoveStaticDirIssue15174reproducing the exact scenario (delete a directory understatic/in a running server) and asserting the build completes without panicking.
Test evidence
- Before the fix:
TestRebuildRemoveStaticDirIssue15174panicked withpanic: unknown component: "static"athugo_sites_build.go:1084— the exact reported failure. - After the fix: the test passes (
--- PASS,./bt-test ./hugolib/ -run TestRebuildRemoveStaticDirIssue15174exit 0). - Regression gate:
./bt-test ./hugolib/ -run TestRebuild(all rebuild/partial-rebuild tests) exit 0 — nothing previously passing broke. - Reviewer confirmed the fix is correct, minimal, and additive; no unrelated changes, no weakened/removed tests, no scratch files.
Requirements checklist
- Fix the panic when deleting a directory in
staticwhile the server is running — ✅ Implemented (added the missingstaticcase) with regression-test evidence (panics before, passes after).
Note: the working tree shows pre-existing deletions of AGENTS.md and CLAUDE.md from the initial git status; these are workspace/harness artifacts predating this task and are not part of my change (my diff touches only the two files above). All changes are left uncommitted in the working tree.